1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "nel/gui/string_case.h"
23 #include "nel/misc/utf_string_view.h"
31 inline bool isSeparator (char c
)
33 return (c
== ' ') || (c
== '\t') || (c
== '\n') || (c
== '\r');
36 inline bool isEndSentence (char c
, char lastChar
)
38 // Ex: One sentence. Another sentence.
40 // Counterexample: nevrax.com
42 return ((c
== ' ') || (c
== '\n'))
43 && ((lastChar
== '.') || (lastChar
== '!') || (lastChar
== '?') || (lastChar
== '\n'));
46 void setCase(std::string
&str
, TCaseMode mode
)
48 const uint length
= (uint
)str
.length();
50 bool newString
= true;
51 bool newSentence
= true;
56 str
= NLMISC::toLower(str
);
59 str
= NLMISC::toUpper(str
);
61 case CaseFirstStringLetterUp
:
64 res
.reserve(str
.size() + (str
.size() >> 2));
65 for (ptrdiff_t i
= 0; i
< (ptrdiff_t)str
.size();)
71 NLMISC::appendToTitle(res
, str
, i
);
73 NLMISC::appendToLower(res
, str
, i
);
85 case CaseFirstSentenceLetterUp
:
88 res
.reserve(str
.size() + (str
.size() >> 2));
90 for (ptrdiff_t i
= 0; i
< (ptrdiff_t)str
.size();)
93 if (isEndSentence(c
, lastChar
))
102 NLMISC::appendToTitle(res
, str
, i
);
104 NLMISC::appendToLower(res
, str
, i
);
114 case CaseFirstWordLetterUp
:
117 res
.reserve(str
.size() + (str
.size() >> 2));
119 for (ptrdiff_t i
= 0; i
< (ptrdiff_t)str
.size();)
122 if (isSeparator(c
) || isEndSentence(c
, lastChar
))
131 NLMISC::appendToTitle(res
, str
, i
);
133 NLMISC::appendToLower(res
, str
, i
);