@@ -2095,7 +2095,7 @@ void NppParameters::updateLangXml(TiXmlElement* mainElemUser, TiXmlElement* main
20952095 langFromModel = langFromModel->NextSiblingElement (L" Language" ))
20962096 {
20972097 std::wstring modelLanguageName = langFromModel->Attribute (L" name" );
2098- if (! modelLanguageName.length ())
2098+ if (modelLanguageName.empty ())
20992099 continue ;
21002100
21012101 // see if language already exists in UserLanguages
@@ -2120,7 +2120,7 @@ void NppParameters::updateLangXml(TiXmlElement* mainElemUser, TiXmlElement* main
21202120 keywordsFromModel = keywordsFromModel->NextSiblingElement (L" Keywords" ))
21212121 {
21222122 std::wstring modelKeywordsName = keywordsFromModel->Attribute (L" name" );
2123- if (! modelKeywordsName.length ())
2123+ if (modelKeywordsName.empty ())
21242124 continue ;
21252125
21262126 // does this Keywords element exist in User already?
@@ -2129,8 +2129,8 @@ void NppParameters::updateLangXml(TiXmlElement* mainElemUser, TiXmlElement* main
21292129 // if Keywords element in user langs.xml, need to check to see if any words are missing from its contents
21302130
21312131 // start by extracting the list of words in the user version of this Keywords element
2132- TiXmlNode* pChild = mapUserKeywords[modelKeywordsName]->FirstChild ();
2133- std::wstring wsText = pChild ? pChild ->Value () : L" " ;
2132+ TiXmlNode* pKwsValue = mapUserKeywords[modelKeywordsName]->FirstChild ();
2133+ std::wstring wsText = pKwsValue ? pKwsValue ->Value () : L" " ;
21342134 std::vector<std::wstring> vwsUserWords{};
21352135 std::map<std::wstring, bool > mapUserWords{};
21362136 if (!wsText.empty ())
@@ -2146,57 +2146,68 @@ void NppParameters::updateLangXml(TiXmlElement* mainElemUser, TiXmlElement* main
21462146
21472147 // then go through each word in the model, and add it to the list if it's not already there
21482148 int nWordsAdded = 0 ;
2149- TiXmlNode* pChildModel = keywordsFromModel->FirstChild ();
2150- std::wstring wsTextModel = pChildModel ? pChildModel ->Value () : L" " ;
2151- if (!wsTextModel. empty () )
2149+ TiXmlNode* pKwsValueModel = keywordsFromModel->FirstChild ();
2150+ std::wstring wsTextModel = pKwsValueModel ? pKwsValueModel ->Value () : L" " ;
2151+ if (!pKwsValue )
21522152 {
2153- std::wstring wsToken;
2154- std::wistringstream wstrm (wsTextModel);
2155- while (wstrm >> wsToken)
2153+ if (pKwsValueModel)
21562154 {
2157- if (!mapUserWords.contains (wsToken))
2158- {
2159- vwsUserWords.push_back (wsToken);
2160- mapUserWords[wsToken] = true ;
2161- ++nWordsAdded;
2162- }
2155+ TiXmlNode* p_clone = pKwsValueModel->Clone ();
2156+ mapUserKeywords[modelKeywordsName]->LinkEndChild (p_clone);
21632157 }
21642158 }
2165-
2166- // if there were any words added to the list, need to update the element contents
2167- if (nWordsAdded)
2159+ else
21682160 {
2169- // sort the words in standard case-sensitive alphabetical order
2170- std::sort (vwsUserWords.begin (), vwsUserWords.end ());
2171-
2172- // convert that list into space-separated string, with at most 8000 characters per line
2173- size_t lineLength = 0 , maxLineLength = 8000 ;
2174- bool first = true ;
2175- std::wstring wsOutputWords (L" " );
2176- for (auto wsWord : vwsUserWords)
2161+
2162+ if (!wsTextModel.empty ())
21772163 {
2178- if (!first)
2164+ std::wstring wsToken;
2165+ std::wistringstream wstrm (wsTextModel);
2166+ while (wstrm >> wsToken)
21792167 {
2180- // space between words
2181- wsOutputWords += L" " ;
2182- lineLength += 1 ;
2168+ if (!mapUserWords.contains (wsToken))
2169+ {
2170+ vwsUserWords.push_back (wsToken);
2171+ ++nWordsAdded;
2172+ }
21832173 }
2184- first = false ;
2174+ }
21852175
2186- if (lineLength + wsWord.length () >= maxLineLength)
2176+ // if there were any words added to the list, need to update the element contents
2177+ if (nWordsAdded)
2178+ {
2179+ // sort the words in standard case-sensitive alphabetical order
2180+ std::sort (vwsUserWords.begin (), vwsUserWords.end ());
2181+
2182+ // convert that list into space-separated string, with at most 8000 characters per line
2183+ size_t lineLength = 0 , maxLineLength = 8000 ;
2184+ bool first = true ;
2185+ std::wstring wsOutputWords (L" " );
2186+ for (auto wsWord : vwsUserWords)
21872187 {
2188- // start next line
2189- lineLength = 0 ;
2190- wsOutputWords += L" \n " ;
2188+ if (!first)
2189+ {
2190+ // space between words
2191+ wsOutputWords += L" " ;
2192+ lineLength += 1 ;
2193+ }
2194+ first = false ;
2195+
2196+ if (lineLength + wsWord.length () >= maxLineLength)
2197+ {
2198+ // start next line
2199+ lineLength = 0 ;
2200+ wsOutputWords += L" \n " ;
2201+ }
2202+
2203+ // add this word to the output string
2204+ wsOutputWords += wsWord;
2205+ lineLength += wsWord.length ();
21912206 }
21922207
2193- // add this word to the output string
2194- wsOutputWords += wsWord;
2195- lineLength += wsWord.length ();
2208+ // and update the XML's value
2209+ pKwsValue->SetValue (wsOutputWords);
21962210 }
2197-
2198- // and update the XML's value
2199- pChild->SetValue (wsOutputWords);
22002211 }
22012212 }
22022213 else
@@ -2250,7 +2261,7 @@ void NppParameters::updateStylesXml(TiXmlElement* rootUser, TiXmlElement* rootMo
22502261 lexerFromModel = lexerFromModel->NextSiblingElement (L" LexerType" ))
22512262 {
22522263 std::wstring modelLexerName = lexerFromModel->Attribute (L" name" );
2253- if (! modelLexerName.length ())
2264+ if (modelLexerName.empty ())
22542265 continue ;
22552266
22562267 // see if lexer already exists in UserStyles
@@ -2275,7 +2286,7 @@ void NppParameters::updateStylesXml(TiXmlElement* rootUser, TiXmlElement* rootMo
22752286 wordsStyleFromModel = wordsStyleFromModel->NextSiblingElement (L" WordsStyle" ))
22762287 {
22772288 std::wstring modelWordsStyleID = wordsStyleFromModel->Attribute (L" styleID" );
2278- if (! modelWordsStyleID.length ())
2289+ if (modelWordsStyleID.empty ())
22792290 continue ;
22802291
22812292 // does it exist in User already?
@@ -2327,7 +2338,7 @@ void NppParameters::updateStylesXml(TiXmlElement* rootUser, TiXmlElement* rootMo
23272338 {
23282339 // use StyleID for the map's key, or if styleID not found or if "0" then use the widget's name (lowercase) instead
23292340 std::wstring widgetKey = widgetFromUser->Attribute (L" styleID" );
2330- if (! widgetKey.length () || widgetKey == L" 0" || (decStrVal (widgetKey.c_str ()) > 256 ) || (decStrVal (widgetKey.c_str ()) < 0 ))
2341+ if (widgetKey.empty () || widgetKey == L" 0" || (decStrVal (widgetKey.c_str ()) > 256 ) || (decStrVal (widgetKey.c_str ()) < 0 ))
23312342 widgetKey = widgetFromUser->Attribute (L" name" );
23322343
23332344 // add widget to map using the key
@@ -2345,9 +2356,9 @@ void NppParameters::updateStylesXml(TiXmlElement* rootUser, TiXmlElement* rootMo
23452356 {
23462357 // extract the key
23472358 std::wstring widgetKey = widgetFromModel->Attribute (L" styleID" );
2348- if (! widgetKey.length () || widgetKey == L" 0" || (decStrVal (widgetKey.c_str ()) > 256 ) || (decStrVal (widgetKey.c_str ()) < 0 ))
2359+ if (widgetKey.empty () || widgetKey == L" 0" || (decStrVal (widgetKey.c_str ()) > 256 ) || (decStrVal (widgetKey.c_str ()) < 0 ))
23492360 widgetKey = widgetFromModel->Attribute (L" name" );
2350- if (! widgetKey.length ())
2361+ if (widgetKey.empty ())
23512362 continue ;
23522363
23532364 // see if WidgetStyle already exists in UserStyles
0 commit comments