CHANGED: #1471 moved some ucstring handling code to the NELGUI library ( required for CViewText )
This commit is contained in:
parent
6c88f02261
commit
a08a666e58
12 changed files with 145 additions and 124 deletions
29
code/nel/include/nel/gui/string_case.h
Normal file
29
code/nel/include/nel/gui/string_case.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef STRING_CASE_H
|
||||
#define STRING_CASE_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/misc/ucstring.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
|
||||
enum TCaseMode
|
||||
{
|
||||
CaseNormal = 0, // Nothing done
|
||||
CaseLower, // All letters in lowercase
|
||||
CaseUpper, // All letters in uppercase
|
||||
CaseFirstStringLetterUp, // The first letter of the string is uppercase, the others are lowercase
|
||||
CaseFirstSentenceLetterUp, // The first letter of the string and each sentences are uppercase, the others are lowercase. Sentences are seprated with '.'.
|
||||
CaseFirstWordLetterUp, // The first letter of each word is uppercase, the others are lowercase
|
||||
CaseCount
|
||||
};
|
||||
|
||||
|
||||
void setCase( ucstring &str, TCaseMode mode );
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
99
code/nel/src/gui/string_case.cpp
Normal file
99
code/nel/src/gui/string_case.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include "nel/gui/string_case.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
inline bool isSeparator (ucchar c)
|
||||
{
|
||||
return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r');
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -42,6 +42,8 @@
|
|||
#include "game_share/chat_group.h"
|
||||
#include "interface_v3/skill_manager.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
||||
|
|
|
@ -81,6 +81,8 @@
|
|||
#include "bg_downloader_access.h"
|
||||
#include "main_loop.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
////////////////
|
||||
// Namespaces //
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
#include "chat_window.h"
|
||||
#include "people_interraction.h"
|
||||
|
||||
#include "../misc.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
|
||||
#include "../client_cfg.h"
|
||||
|
||||
#include "../misc.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "../misc.h"
|
||||
|
||||
using namespace NLMISC;
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -14,21 +14,18 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
#include "stdpch.h"
|
||||
|
||||
#include "nel/misc/bit_mem_stream.h"
|
||||
#include "nel/misc/i18n.h"
|
||||
|
||||
#include "view_text.h"
|
||||
#include "interface_manager.h"
|
||||
#include "nel/gui/view_renderer.h"
|
||||
#include "nel/gui/widget_manager.h"
|
||||
#include "group_container.h" // CCtrlResizer
|
||||
#include "nel/gui/ctrl_tooltip.h"
|
||||
|
||||
#include "nel/misc/xml_auto_ptr.h"
|
||||
#include "nel/gui/lua_ihm.h"
|
||||
#include "lua_ihm_ryzom.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
@ -2415,7 +2412,7 @@ void CViewText::setTextFormatTaged(const ucstring &text)
|
|||
|
||||
// color format is available only if multilined
|
||||
if (!_MultiLine)
|
||||
CLuaIHMRyzom::debugInfo(toString("ViewText isn't multilined : uc_hardtext_format will not act as wanted !\n%s", text.toString().c_str()));
|
||||
nlwarning( toString("ViewText isn't multilined : uc_hardtext_format will not act as wanted !\n%s", text.toString().c_str()).c_str() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -2472,7 +2469,7 @@ void CViewText::setSingleLineTextFormatTaged(const ucstring &text)
|
|||
|
||||
// this color format is available only if not multilined
|
||||
if (_MultiLine)
|
||||
CLuaIHMRyzom::debugInfo(toString("ViewText is multilined : uc_hardtext_single_line_format will not act as wanted !\n%s", text.toString().c_str()));
|
||||
nlwarning( toString("ViewText is multilined : uc_hardtext_single_line_format will not act as wanted !\n%s", text.toString().c_str()).c_str() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define NL_VIEW_TEXT_H
|
||||
|
||||
#include "nel/gui/view_base.h"
|
||||
#include "../misc.h"
|
||||
#include "nel/gui/string_case.h"
|
||||
#include "nel/3d/u_text_context.h"
|
||||
|
||||
namespace NLGUI
|
||||
|
@ -408,10 +408,6 @@ private:
|
|||
void getFormatTagChange(uint textIndex, uint &ctIndex, CFormatInfo &wordFormat) const;
|
||||
};
|
||||
|
||||
// change case of a string
|
||||
void setCase (ucstring &str, TCaseMode mode);
|
||||
|
||||
|
||||
#endif // NL_VIEW_TEXT_H
|
||||
|
||||
/* End of view_text.h */
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
#include "game_share/crypt.h"
|
||||
#include "game_share/bg_downloader_msg.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
void ConnectToShard();
|
||||
|
||||
// ***************************************************************************
|
||||
|
|
|
@ -976,100 +976,6 @@ std::string getStringCategoryIfAny(const ucstring &src, ucstring &dest)
|
|||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
inline bool isSeparator (ucchar c)
|
||||
{
|
||||
return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r');
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
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 = toLower (str);
|
||||
break;
|
||||
case CaseUpper:
|
||||
str = toUpper (str);
|
||||
break;
|
||||
case CaseFirstStringLetterUp:
|
||||
for (i=0; i<length; i++)
|
||||
{
|
||||
if (!isSeparator (str[i]))
|
||||
{
|
||||
if (newString)
|
||||
str[i] = toUpper (str[i]);
|
||||
else
|
||||
str[i] = 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] = toUpper (str[i]);
|
||||
else
|
||||
str[i] = 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] = toUpper (str[i]);
|
||||
else
|
||||
str[i] = toLower (str[i]);
|
||||
|
||||
newWord = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
sint ucstrnicmp(const ucstring &s0, uint p0, uint n0, const ucstring &s1)
|
||||
{
|
||||
|
|
|
@ -185,24 +185,6 @@ enum TFilter3d
|
|||
RYZOM_MAX_FILTER_3D,
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum TCaseMode
|
||||
{
|
||||
CaseNormal = 0, // Nothing done
|
||||
CaseLower, // All letters in lowercase
|
||||
CaseUpper, // All letters in uppercase
|
||||
CaseFirstStringLetterUp, // The first letter of the string is uppercase, the others are lowercase
|
||||
CaseFirstSentenceLetterUp, // The first letter of the string and each sentences are uppercase, the others are lowercase. Sentences are seprated with '.'.
|
||||
CaseFirstWordLetterUp, // The first letter of each word is uppercase, the others are lowercase
|
||||
CaseCount
|
||||
};
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// change the case mode of a string
|
||||
void setCase (ucstring &str, TCaseMode mode);
|
||||
|
||||
// compare 2 ucstring s0 and s1, without regard to case. give start and size for sequence p0
|
||||
sint ucstrnicmp(const ucstring &s0, uint p0, uint n0, const ucstring &s1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue