kaetemi 4 years ago
parent 2de4907b83
commit 2eb088ef1c

@ -25,7 +25,6 @@
namespace NLGUI namespace NLGUI
{ {
enum TCaseMode enum TCaseMode
{ {
CaseNormal = 0, // Nothing done CaseNormal = 0, // Nothing done
@ -37,11 +36,7 @@ namespace NLGUI
CaseCount CaseCount
}; };
void setCase( ucstring &str, TCaseMode mode );
void setCase( std::string &str, TCaseMode mode ); void setCase( std::string &str, TCaseMode mode );
} }
#endif #endif

@ -32,18 +32,6 @@ namespace NLGUI
return (c == (u32char)' ') || (c == (u32char)'\t') || (c == (u32char)'\n') || (c == (u32char)'\r'); 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) inline bool isEndSentence (u32char c, u32char lastChar)
{ {
// Ex: One sentence. Another sentence. // Ex: One sentence. Another sentence.
@ -54,90 +42,6 @@ namespace NLGUI
&& (lastChar == (u32char)'.') || (lastChar == (u32char)'!') || (lastChar == (u32char)'?'); && (lastChar == (u32char)'.') || (lastChar == (u32char)'!') || (lastChar == (u32char)'?');
} }
inline bool isEndSentence (ucstring& str, uint index)
{
// Ex: One sentence. Another sentence.
// ^
// Counterexample: nevrax.com
// ^
ucchar c = str[index];
if ((str[index] == ' ') || (str[index] == '\n'))
{
if (index < 1)
return false;
c = str[index-1];
return (c == '.') || (c == '!') || (c == '?');
}
return false;
}
void setCase( ucstring &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:
for (i=0; i<length; i++)
{
if (!isSeparator (str[i]))
{
if (newString)
str[i] = NLMISC::toUpper (str[i]);
else
str[i] = NLMISC::toLower (str[i]);
newString = false;
}
}
break;
case CaseFirstSentenceLetterUp:
for (i=0; i<length; i++)
{
if (isEndSentence (str, i))
newSentence = true;
else
{
if (newSentence)
str[i] = NLMISC::toUpper (str[i]);
else
str[i] = NLMISC::toLower (str[i]);
if (!isSeparator (str[i]))
newSentence = false;
}
}
break;
case CaseFirstWordLetterUp:
for (i=0; i<length; i++)
{
if (isSeparator (str[i]) || isEndSentence (str, i))
newWord = true;
else
{
if (newWord)
str[i] = NLMISC::toUpper (str[i]);
else
str[i] = NLMISC::toLower (str[i]);
newWord = false;
}
}
break;
default:
break;
}
}
void setCase(std::string &str, TCaseMode mode) void setCase(std::string &str, TCaseMode mode)
{ {
const uint length = (uint)str.length(); const uint length = (uint)str.length();
@ -240,8 +144,6 @@ namespace NLGUI
break; break;
} }
} }
} }
/* end of file */

Loading…
Cancel
Save