|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
|
#include "nel/gui/string_case.h"
|
|
|
|
|
#include "nel/misc/utf_string_view.h"
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_NEW
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
@ -26,13 +27,33 @@
|
|
|
|
|
|
|
|
|
|
namespace NLGUI
|
|
|
|
|
{
|
|
|
|
|
inline bool isSeparator (u32char c)
|
|
|
|
|
{
|
|
|
|
|
return (c == (u32char)' ') || (c == (u32char)'\t') || (c == (u32char)'\n') || (c == (u32char)'\r');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool isSeparator (ucchar c)
|
|
|
|
|
{
|
|
|
|
|
return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool isSeparator (char c)
|
|
|
|
|
{
|
|
|
|
|
return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
|
|
inline bool isEndSentence (u32char c, u32char lastChar)
|
|
|
|
|
{
|
|
|
|
|
// Ex: One sentence. Another sentence.
|
|
|
|
|
// ^
|
|
|
|
|
// Counterexample: nevrax.com
|
|
|
|
|
// ^
|
|
|
|
|
return ((c == (u32char)' ') || (c == (u32char)'\n'))
|
|
|
|
|
&& (lastChar == (u32char)'.') || (lastChar == (u32char)'!') || (lastChar == (u32char)'?');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool isEndSentence (ucstring& str, uint index)
|
|
|
|
|
{
|
|
|
|
|
// Ex: One sentence. Another sentence.
|
|
|
|
@ -117,6 +138,109 @@ namespace NLGUI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setCase(std::string &str, TCaseMode mode)
|
|
|
|
|
{
|
|
|
|
|
const uint length = (uint)str.length();
|
|
|
|
|
uint i;
|
|
|
|
|
bool newString = true;
|
|
|
|
|
bool newSentence = true;
|
|
|
|
|
bool newWord = true;
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case CaseLower:
|
|
|
|
|
str = NLMISC::toLower(str);
|
|
|
|
|
break;
|
|
|
|
|
case CaseUpper:
|
|
|
|
|
str = NLMISC::toUpper(str);
|
|
|
|
|
break;
|
|
|
|
|
case CaseFirstStringLetterUp:
|
|
|
|
|
{
|
|
|
|
|
NLMISC::CUtfStringView sv(str);
|
|
|
|
|
std::string res;
|
|
|
|
|
res.reserve(sv.largestSize());
|
|
|
|
|
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it)
|
|
|
|
|
{
|
|
|
|
|
u32char c = *it;
|
|
|
|
|
if (c < 0x10000)
|
|
|
|
|
{
|
|
|
|
|
if (!isSeparator(c))
|
|
|
|
|
{
|
|
|
|
|
if (newString)
|
|
|
|
|
c = NLMISC::toUpper((ucchar)c);
|
|
|
|
|
else
|
|
|
|
|
c = NLMISC::toLower((ucchar)c);
|
|
|
|
|
newString = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NLMISC::CUtfStringView::append(res, c);
|
|
|
|
|
}
|
|
|
|
|
str = nlmove(res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CaseFirstSentenceLetterUp:
|
|
|
|
|
{
|
|
|
|
|
NLMISC::CUtfStringView sv(str);
|
|
|
|
|
std::string res;
|
|
|
|
|
res.reserve(sv.largestSize());
|
|
|
|
|
u32char lastChar = 0;
|
|
|
|
|
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it)
|
|
|
|
|
{
|
|
|
|
|
u32char c = *it;
|
|
|
|
|
if (c < 0x10000)
|
|
|
|
|
{
|
|
|
|
|
if (isEndSentence(c, lastChar))
|
|
|
|
|
newSentence = true;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (newSentence)
|
|
|
|
|
c = NLMISC::toUpper((ucchar)c);
|
|
|
|
|
else
|
|
|
|
|
c = NLMISC::toLower((ucchar)c);
|
|
|
|
|
|
|
|
|
|
if (!isSeparator(c))
|
|
|
|
|
newSentence = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NLMISC::CUtfStringView::append(res, c);
|
|
|
|
|
lastChar = c;
|
|
|
|
|
}
|
|
|
|
|
str = nlmove(res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CaseFirstWordLetterUp:
|
|
|
|
|
{
|
|
|
|
|
NLMISC::CUtfStringView sv(str);
|
|
|
|
|
std::string res;
|
|
|
|
|
res.reserve(sv.largestSize());
|
|
|
|
|
u32char lastChar = 0;
|
|
|
|
|
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it)
|
|
|
|
|
{
|
|
|
|
|
u32char c = *it;
|
|
|
|
|
if (c < 0x10000)
|
|
|
|
|
{
|
|
|
|
|
if (isSeparator(c) || isEndSentence(c, lastChar))
|
|
|
|
|
newWord = true;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (newWord)
|
|
|
|
|
c = NLMISC::toUpper((ucchar)c);
|
|
|
|
|
else
|
|
|
|
|
c = NLMISC::toLower((ucchar)c);
|
|
|
|
|
|
|
|
|
|
newWord = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NLMISC::CUtfStringView::append(res, c);
|
|
|
|
|
lastChar = c;
|
|
|
|
|
}
|
|
|
|
|
str = nlmove(res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|