diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 0f7f89f80..6897338fc 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -926,7 +926,7 @@ bool NppParameters::reloadStylers(const TCHAR* stylePath) _pXmlUserStylerDoc = NULL; return false; } - _lexerStylerArray.eraseAll(); + _lexerStylerVect.eraseAll(); _widgetStyleArray.setNbStyler( 0 ); getUserStylersFromXmlTree(); @@ -2776,9 +2776,9 @@ std::pair NppParameters::feedUserLang(TiXmlNode *n // styles that were not read from xml file should get default values for (int i=0; i_styleArray.getStyler(i); + Style & style = _userLangArray[_nbUserLang - 1]->_styles.getStyler(i); if (style._styleID == -1) - _userLangArray[_nbUserLang - 1]->_styleArray.addStyler(i, globalMappper().styleNameMapper[i].c_str()); + _userLangArray[_nbUserLang - 1]->_styles.addStyler(i, globalMappper().styleNameMapper[i].c_str()); } } @@ -3554,7 +3554,7 @@ void NppParameters::feedUserStyles(TiXmlNode *node) if (globalMappper().styleIdMapper.find(styleName) != globalMappper().styleIdMapper.end()) { id = globalMappper().styleIdMapper[styleName]; - _userLangArray[_nbUserLang - 1]->_styleArray.addStyler((id | L_USER << 16), childNode); + _userLangArray[_nbUserLang - 1]->_styles.addStyler((id | L_USER << 16), childNode); } } } @@ -3570,7 +3570,7 @@ bool NppParameters::feedStylerArray(TiXmlNode *node) childNode ; childNode = childNode->NextSibling(TEXT("LexerType")) ) { - if (!_lexerStylerArray.hasEnoughSpace()) return false; + if (!_lexerStylerVect.hasEnoughSpace()) return false; TiXmlElement *element = childNode->ToElement(); const TCHAR *lexerName = element->Attribute(TEXT("name")); @@ -3579,7 +3579,7 @@ bool NppParameters::feedStylerArray(TiXmlNode *node) const TCHAR *lexerExcluded = element->Attribute(TEXT("excluded")); if (lexerName) { - _lexerStylerArray.addLexerStyler(lexerName, lexerDesc, lexerUserExt, childNode); + _lexerStylerVect.addLexerStyler(lexerName, lexerDesc, lexerUserExt, childNode); if (lexerExcluded != NULL && (lstrcmp(lexerExcluded, TEXT("yes")) == 0)) { int index = getExternalLangIndexFromName(lexerName); @@ -3613,7 +3613,7 @@ bool NppParameters::feedStylerArray(TiXmlNode *node) void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt , TiXmlNode *lexerNode) { - LexerStyler & ls = _lexerStylerArray[_nbLexerStyler++]; + LexerStyler & ls = _lexerStylerVect[_nbLexerStyler++]; ls.setLexerName(lexerName); if (lexerDesc) ls.setLexerDesc(lexerDesc); @@ -3647,7 +3647,7 @@ void LexerStylerArray::eraseAll() for (int i = 0 ; i < _nbLexerStyler ; ++i) { - _lexerStylerArray[i].setNbStyler( 0 ); + _lexerStylerVect[i].setNbStyler( 0 ); } _nbLexerStyler = 0; @@ -3661,11 +3661,16 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode) { styleID = (styleID & 0xFFFF); index = styleID; - if (index >= SCE_USER_STYLE_TOTAL_STYLES || _styleArray[index]._styleID != -1) + if (index >= SCE_USER_STYLE_TOTAL_STYLES || _styleVect[index]._styleID != -1) + return; + } + else + { + if (index >= STYLE_ARR_MAX_SIZE) return; } - _styleArray[index]._styleID = styleID; + _styleVect[index]._styleID = styleID; if (styleNode) { @@ -3679,16 +3684,16 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode) if (str) { if (isUser) - _styleArray[index]._styleDesc = globalMappper().styleNameMapper[index].c_str(); + _styleVect[index]._styleDesc = globalMappper().styleNameMapper[index].c_str(); else - _styleArray[index]._styleDesc = str; + _styleVect[index]._styleDesc = str; } str = element->Attribute(TEXT("fgColor")); if (str) { unsigned long result = hexStrVal(str); - _styleArray[index]._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); + _styleVect[index]._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); } @@ -3696,46 +3701,46 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode) if (str) { unsigned long result = hexStrVal(str); - _styleArray[index]._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); + _styleVect[index]._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); } str = element->Attribute(TEXT("colorStyle")); if (str) { - _styleArray[index]._colorStyle = decStrVal(str); + _styleVect[index]._colorStyle = decStrVal(str); } str = element->Attribute(TEXT("fontName")); - _styleArray[index]._fontName = str; + _styleVect[index]._fontName = str; str = element->Attribute(TEXT("fontStyle")); if (str) { - _styleArray[index]._fontStyle = decStrVal(str); + _styleVect[index]._fontStyle = decStrVal(str); } str = element->Attribute(TEXT("fontSize")); if (str) { - _styleArray[index]._fontSize = decStrVal(str); + _styleVect[index]._fontSize = decStrVal(str); } str = element->Attribute(TEXT("nesting")); if (str) { - _styleArray[index]._nesting = decStrVal(str); + _styleVect[index]._nesting = decStrVal(str); } str = element->Attribute(TEXT("keywordClass")); if (str) { - _styleArray[index]._keywordClass = getKwClassFromName(str); + _styleVect[index]._keywordClass = getKwClassFromName(str); } TiXmlNode *v = styleNode->FirstChild(); if (v) { - _styleArray[index]._keywords = new generic_string(v->Value()); + _styleVect[index]._keywords = new generic_string(v->Value()); } } ++_nbStyler; @@ -7071,7 +7076,7 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl TiXmlElement *element = childNode->ToElement(); const TCHAR *nm = element->Attribute(TEXT("name")); - LexerStyler *pLs = _lexerStylerArray.getLexerStylerByName(nm); + LexerStyler *pLs = _lexerStylerVect.getLexerStylerByName(nm); LexerStyler *pLs2 = lexersStylers.getLexerStylerByName(nm); if (pLs) @@ -7107,7 +7112,7 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl TiXmlElement *element = childNode->ToElement(); const TCHAR *nm = element->Attribute(TEXT("name")); - LexerStyler *pLs = _lexerStylerArray.getLexerStylerByName(nm); + LexerStyler *pLs = _lexerStylerVect.getLexerStylerByName(nm); LexerStyler *pLs2 = lexersStylers.getLexerStylerByName(nm); if (pLs) @@ -7289,7 +7294,7 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i) { TiXmlElement *styleElement = (styleRootElement->InsertEndChild(TiXmlElement(TEXT("WordsStyle"))))->ToElement(); - Style style2Write = userLang->_styleArray.getStyler(i); + Style style2Write = userLang->_styles.getStyler(i); if (style2Write._styleID == -1) continue; @@ -7349,7 +7354,7 @@ void NppParameters::stylerStrOp(bool op) { for (int j = 0 ; j < SCE_USER_STYLE_TOTAL_STYLES ; ++j) { - Style & style = _userLangArray[i]->_styleArray.getStyler(j); + Style & style = _userLangArray[i]->_styles.getStyler(j); if (op == DUP) { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 826ce3a2b..376245cf6 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -44,6 +44,7 @@ #endif + class NativeLangSpeaker; const bool POS_VERTICAL = true; @@ -469,6 +470,7 @@ struct GlobalOverride final bool enableUnderLine = false; }; +const int STYLE_ARR_MAX_SIZE = 31; struct StyleArray { @@ -480,7 +482,7 @@ public: this->_nbStyler = sa._nbStyler; for (int i = 0 ; i < _nbStyler ; ++i) { - this->_styleArray[i] = sa._styleArray[i]; + this->_styleVect[i] = sa._styleVect[i]; } } return *this; @@ -491,19 +493,19 @@ public: Style& getStyler(size_t index) { - assert(index < SCE_STYLE_ARRAY_SIZE); - return _styleArray[index]; + assert(index < STYLE_ARR_MAX_SIZE); + return _styleVect[index]; } - bool hasEnoughSpace() {return (_nbStyler < SCE_STYLE_ARRAY_SIZE);}; + bool hasEnoughSpace() {return (_nbStyler < STYLE_ARR_MAX_SIZE);}; void addStyler(int styleID, TiXmlNode *styleNode); void addStyler(int styleID, const TCHAR *styleName) { - _styleArray[styleID]._styleID = styleID; - _styleArray[styleID]._styleDesc = styleName; - _styleArray[styleID]._fgColor = black; - _styleArray[styleID]._bgColor = white; + _styleVect[styleID]._styleID = styleID; + _styleVect[styleID]._styleDesc = styleName; + _styleVect[styleID]._fgColor = black; + _styleVect[styleID]._bgColor = white; ++_nbStyler; } @@ -511,7 +513,7 @@ public: { for (int i = 0 ; i < _nbStyler ; ++i) { - if (_styleArray[i]._styleID == id) + if (_styleVect[i]._styleID == id) return i; } return -1; @@ -523,14 +525,14 @@ public: return -1; for (int i = 0 ; i < _nbStyler ; ++i) { - if (!lstrcmp(_styleArray[i]._styleDesc, name)) + if (!lstrcmp(_styleVect[i]._styleDesc, name)) return i; } return -1; } protected: - Style _styleArray[SCE_STYLE_ARRAY_SIZE]; + std::vector