Make the EOL type more explicite

This commit is contained in:
Don Ho 2015-10-27 15:35:19 +01:00
parent 2fd963d932
commit 280ddcd493
9 changed files with 60 additions and 60 deletions

View File

@ -2117,15 +2117,15 @@ void Notepad_plus::setLangStatus(LangType langType)
} }
void Notepad_plus::setDisplayFormat(FormatType format) void Notepad_plus::setDisplayFormat(EolType format)
{ {
const TCHAR* str = TEXT("??"); const TCHAR* str = TEXT("??");
switch (format) switch (format)
{ {
case FormatType::windows: str = TEXT("Dos\\Windows"); break; case EolType::windows: str = TEXT("Dos\\Windows"); break;
case FormatType::macos: str = TEXT("Macintosh"); break; case EolType::macos: str = TEXT("Macintosh"); break;
case FormatType::unix: str = TEXT("UNIX"); break; case EolType::unix: str = TEXT("UNIX"); break;
case FormatType::unknown: str = TEXT("Unknown"); assert(false); break; case EolType::unknown: str = TEXT("Unknown"); assert(false); break;
} }
_statusBar.setText(str, STATUSBAR_EOF_FORMAT); _statusBar.setText(str, STATUSBAR_EOF_FORMAT);
} }
@ -3503,11 +3503,11 @@ void Notepad_plus::dynamicCheckMenuAndTB() const
} }
void Notepad_plus::enableConvertMenuItems(FormatType format) const void Notepad_plus::enableConvertMenuItems(EolType format) const
{ {
enableCommand(IDM_FORMAT_TODOS, (format != FormatType::windows), MENU); enableCommand(IDM_FORMAT_TODOS, (format != EolType::windows), MENU);
enableCommand(IDM_FORMAT_TOUNIX, (format != FormatType::unix), MENU); enableCommand(IDM_FORMAT_TOUNIX, (format != EolType::unix), MENU);
enableCommand(IDM_FORMAT_TOMAC, (format != FormatType::macos), MENU); enableCommand(IDM_FORMAT_TOMAC, (format != EolType::macos), MENU);
} }

View File

@ -496,14 +496,14 @@ private:
void getMainClientRect(RECT & rc) const; void getMainClientRect(RECT & rc) const;
void staticCheckMenuAndTB() const; void staticCheckMenuAndTB() const;
void dynamicCheckMenuAndTB() const; void dynamicCheckMenuAndTB() const;
void enableConvertMenuItems(FormatType f) const; void enableConvertMenuItems(EolType f) const;
void checkUnicodeMenuItems() const; void checkUnicodeMenuItems() const;
generic_string getLangDesc(LangType langType, bool getName = false); generic_string getLangDesc(LangType langType, bool getName = false);
void setLangStatus(LangType langType); void setLangStatus(LangType langType);
void setDisplayFormat(FormatType f); void setDisplayFormat(EolType f);
int getCmdIDFromEncoding(int encoding) const; int getCmdIDFromEncoding(int encoding) const;
void setUniModeText(); void setUniModeText();
void checkLangsMenu(int id) const ; void checkLangsMenu(int id) const ;

View File

@ -326,8 +326,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (!wParam) if (!wParam)
return FALSE; return FALSE;
FormatType newFormat = convertIntToFormatType(static_cast<int>(lParam), FormatType::unknown); EolType newFormat = convertIntToFormatType(static_cast<int>(lParam), EolType::unknown);
if (FormatType::unknown == newFormat) if (EolType::unknown == newFormat)
{ {
assert(false and "invalid buffer format message"); assert(false and "invalid buffer format message");
return FALSE; return FALSE;

View File

@ -1704,9 +1704,9 @@ void Notepad_plus::command(int id)
case IDM_FORMAT_TOUNIX: case IDM_FORMAT_TOUNIX:
case IDM_FORMAT_TOMAC: case IDM_FORMAT_TOMAC:
{ {
FormatType newFormat = (id == IDM_FORMAT_TODOS) EolType newFormat = (id == IDM_FORMAT_TODOS)
? FormatType::windows ? EolType::windows
: (id == IDM_FORMAT_TOUNIX) ? FormatType::unix : FormatType::macos; : (id == IDM_FORMAT_TOUNIX) ? EolType::unix : EolType::macos;
Buffer* buf = _pEditView->getCurrentBuffer(); Buffer* buf = _pEditView->getCurrentBuffer();
buf->setFormat(newFormat); buf->setFormat(newFormat);

View File

@ -4134,17 +4134,17 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
int i; int i;
if (element->Attribute(TEXT("format"), &i)) if (element->Attribute(TEXT("format"), &i))
{ {
FormatType newFormat = FormatType::osdefault; EolType newFormat = EolType::osdefault;
switch (i) switch (i)
{ {
case static_cast<LPARAM>(FormatType::windows) : case static_cast<LPARAM>(EolType::windows) :
newFormat = FormatType::windows; newFormat = EolType::windows;
break; break;
case static_cast<LPARAM>(FormatType::macos) : case static_cast<LPARAM>(EolType::macos) :
newFormat = FormatType::macos; newFormat = EolType::macos;
break; break;
case static_cast<LPARAM>(FormatType::unix) : case static_cast<LPARAM>(EolType::unix) :
newFormat = FormatType::unix; newFormat = EolType::unix;
break; break;
default: default:
assert(false and "invalid buffer format - fallback to default"); assert(false and "invalid buffer format - fallback to default");
@ -6462,16 +6462,16 @@ void Date::now()
} }
FormatType convertIntToFormatType(int value, FormatType defvalue) EolType convertIntToFormatType(int value, EolType defvalue)
{ {
switch (value) switch (value)
{ {
case static_cast<LPARAM>(FormatType::windows): case static_cast<LPARAM>(EolType::windows) :
return FormatType::windows; return EolType::windows;
case static_cast<LPARAM>(FormatType::macos): case static_cast<LPARAM>(EolType::macos) :
return FormatType::macos; return EolType::macos;
case static_cast<LPARAM>(FormatType::unix): case static_cast<LPARAM>(EolType::unix) :
return FormatType::unix; return EolType::unix;
default: default:
return defvalue; return defvalue;
} }

View File

@ -93,7 +93,7 @@ const int TAB_MULTILINE = 128; // 1000 0000
const int TAB_HIDE = 256; //1 0000 0000 const int TAB_HIDE = 256; //1 0000 0000
enum class FormatType: std::uint8_t enum class EolType: std::uint8_t
{ {
windows, windows,
macos, macos,
@ -109,7 +109,7 @@ enum class FormatType: std::uint8_t
** \param value An arbitrary int ** \param value An arbitrary int
** \param defvalue The default value to use if an invalid value is provided ** \param defvalue The default value to use if an invalid value is provided
*/ */
FormatType convertIntToFormatType(int value, FormatType defvalue = FormatType::osdefault); EolType convertIntToFormatType(int value, EolType defvalue = EolType::osdefault);
@ -571,7 +571,7 @@ private :
struct NewDocDefaultSettings final struct NewDocDefaultSettings final
{ {
FormatType _format = FormatType::osdefault; EolType _format = EolType::osdefault;
UniMode _unicodeMode = uniCookie; UniMode _unicodeMode = uniCookie;
bool _openAnsiAsUtf8 = true; bool _openAnsiAsUtf8 = true;
LangType _lang = L_TEXT; LangType _lang = L_TEXT;

View File

@ -54,7 +54,7 @@ long Buffer::_recentTagCtr = 0;
namespace // anonymous namespace // anonymous
{ {
static FormatType getEOLFormatForm(const char* const data, size_t length, FormatType defvalue = FormatType::osdefault) static EolType getEOLFormatForm(const char* const data, size_t length, EolType defvalue = EolType::osdefault)
{ {
assert(length == 0 or data != nullptr && "invalid buffer for getEOLFormatForm()"); assert(length == 0 or data != nullptr && "invalid buffer for getEOLFormatForm()");
@ -63,13 +63,13 @@ namespace // anonymous
if (data[i] == CR) if (data[i] == CR)
{ {
if (i + 1 < length && data[i + 1] == LF) if (i + 1 < length && data[i + 1] == LF)
return FormatType::windows; return EolType::windows;
return FormatType::macos; return EolType::macos;
} }
if (data[i] == LF) if (data[i] == LF)
return FormatType::unix; return EolType::unix;
} }
return defvalue; // fallback unknown return defvalue; // fallback unknown
@ -592,7 +592,7 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
Utf8_16_Read UnicodeConvertor; //declare here so we can get information after loading is done Utf8_16_Read UnicodeConvertor; //declare here so we can get information after loading is done
char data[blockSize + 8]; // +8 for incomplete multibyte char char data[blockSize + 8]; // +8 for incomplete multibyte char
FormatType bkformat = FormatType::unknown; EolType bkformat = EolType::unknown;
LangType detectedLang = L_TEXT; LangType detectedLang = L_TEXT;
bool res = loadFileData(doc, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, detectedLang, encoding, &bkformat); bool res = loadFileData(doc, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, detectedLang, encoding, &bkformat);
if (res) if (res)
@ -663,7 +663,7 @@ bool FileManager::reloadBuffer(BufferID id)
buf->_canNotify = false; //disable notify during file load, we dont want dirty to be triggered buf->_canNotify = false; //disable notify during file load, we dont want dirty to be triggered
int encoding = buf->getEncoding(); int encoding = buf->getEncoding();
char data[blockSize + 8]; // +8 for incomplete multibyte char char data[blockSize + 8]; // +8 for incomplete multibyte char
FormatType bkformat; EolType bkformat;
LangType lang = buf->getLangType(); LangType lang = buf->getLangType();
@ -682,7 +682,7 @@ bool FileManager::reloadBuffer(BufferID id)
if (nullptr != UnicodeConvertor.getNewBuf()) if (nullptr != UnicodeConvertor.getNewBuf())
{ {
FormatType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(),ndds._format); EolType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(), ndds._format);
buf->setFormat(format); buf->setFormat(format);
} }
else{ else{
@ -1340,7 +1340,7 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
return L_TEXT; return L_TEXT;
} }
inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * UnicodeConvertor, LangType & language, int & encoding, FormatType* pFormat) inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * unicodeConvertor, LangType & language, int & encoding, EolType* pFormat)
{ {
FILE *fp = generic_fopen(filename, TEXT("rb")); FILE *fp = generic_fopen(filename, TEXT("rb"));
if (!fp) if (!fp)
@ -1395,7 +1395,7 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
_pscratchTilla->execute(SCI_SETCODEPAGE, SC_CP_UTF8); _pscratchTilla->execute(SCI_SETCODEPAGE, SC_CP_UTF8);
bool success = true; bool success = true;
FormatType format = FormatType::unknown; EolType format = EolType::unknown;
__try __try
{ {
// First allocate enough memory for the whole file (this will reduce memory copy during loading) // First allocate enough memory for the whole file (this will reduce memory copy during loading)
@ -1452,15 +1452,15 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
_pscratchTilla->execute(SCI_APPENDTEXT, newDataLen, (LPARAM)newData); _pscratchTilla->execute(SCI_APPENDTEXT, newDataLen, (LPARAM)newData);
} }
if (format == FormatType::unknown) if (format == EolType::unknown)
format = getEOLFormatForm(data, lenFile, FormatType::unknown); format = getEOLFormatForm(data, lenFile, EolType::unknown);
} }
else else
{ {
lenConvert = UnicodeConvertor->convert(data, lenFile); lenConvert = unicodeConvertor->convert(data, lenFile);
_pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf())); _pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(unicodeConvertor->getNewBuf()));
if (format == FormatType::unknown) if (format == EolType::unknown)
format = getEOLFormatForm(UnicodeConvertor->getNewBuf(), UnicodeConvertor->getNewSize(), FormatType::unknown); format = getEOLFormatForm(unicodeConvertor->getNewBuf(), unicodeConvertor->getNewSize(), EolType::unknown);
} }
if (_pscratchTilla->execute(SCI_GETSTATUS) != SC_STATUS_OK) if (_pscratchTilla->execute(SCI_GETSTATUS) != SC_STATUS_OK)
@ -1486,7 +1486,7 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
// broadcast the format // broadcast the format
if (pFormat != nullptr) if (pFormat != nullptr)
{ {
if (format == FormatType::unknown) if (format == EolType::unknown)
{ {
NppParameters *pNppParamInst = NppParameters::getInstance(); NppParameters *pNppParamInst = NppParameters::getInstance();
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); // for ndds._format const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); // for ndds._format

View File

@ -111,7 +111,7 @@ public:
private: private:
~FileManager(); ~FileManager();
int detectCodepage(char* buf, size_t len); int detectCodepage(char* buf, size_t len);
bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LangType & language, int& encoding, FormatType* pFormat = nullptr); bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LangType & language, int& encoding, EolType* pFormat = nullptr);
LangType detectLanguageFromTextBegining(const unsigned char *data, unsigned int dataLen); LangType detectLanguageFromTextBegining(const unsigned char *data, unsigned int dataLen);
@ -196,11 +196,11 @@ public:
doNotify(BufferChangeReadonly); doNotify(BufferChangeReadonly);
} }
FormatType getFormat() const { EolType getFormat() const {
return _format; return _format;
} }
void setFormat(FormatType format) { void setFormat(EolType format) {
_format = format; _format = format;
doNotify(BufferChangeFormat); doNotify(BufferChangeFormat);
} }
@ -365,7 +365,7 @@ private:
LangType _lang; LangType _lang;
generic_string _userLangExt; // it's useful if only (_lang == L_USER) generic_string _userLangExt; // it's useful if only (_lang == L_USER)
bool _isDirty = false; bool _isDirty = false;
FormatType _format = FormatType::osdefault; EolType _format = EolType::osdefault;
UniMode _unicodeMode; UniMode _unicodeMode;
int _encoding = -1; int _encoding = -1;
bool _isUserReadOnly = false; bool _isUserReadOnly = false;

View File

@ -1107,16 +1107,16 @@ INT_PTR CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPAR
int ID2Check = IDC_RADIO_F_WIN; int ID2Check = IDC_RADIO_F_WIN;
switch (ndds._format) switch (ndds._format)
{ {
case FormatType::windows: case EolType::windows:
ID2Check = IDC_RADIO_F_WIN; ID2Check = IDC_RADIO_F_WIN;
break; break;
case FormatType::macos: case EolType::macos:
ID2Check = IDC_RADIO_F_MAC; ID2Check = IDC_RADIO_F_MAC;
break; break;
case FormatType::unix: case EolType::unix:
ID2Check = IDC_RADIO_F_UNIX; ID2Check = IDC_RADIO_F_UNIX;
break; break;
case FormatType::unknown: case EolType::unknown:
assert(false); assert(false);
break; break;
} }
@ -1255,17 +1255,17 @@ INT_PTR CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPAR
case IDC_RADIO_F_MAC: case IDC_RADIO_F_MAC:
{ {
ndds._format = FormatType::macos; ndds._format = EolType::macos;
return TRUE; return TRUE;
} }
case IDC_RADIO_F_UNIX: case IDC_RADIO_F_UNIX:
{ {
ndds._format = FormatType::unix; ndds._format = EolType::unix;
return TRUE; return TRUE;
} }
case IDC_RADIO_F_WIN: case IDC_RADIO_F_WIN:
{ {
ndds._format = FormatType::windows; ndds._format = EolType::windows;
return TRUE; return TRUE;
} }