StringMgr Class Reference

#include <stringmgr.h>

Collaboration diagram for StringMgr:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual char * upperLatin1 (char *text, unsigned int max=0) const
virtual char * upperUTF8 (char *text, unsigned int max=0) const

Static Public Member Functions

static StringMgrgetSystemStringMgr ()
static bool hasUTF8Support ()
static void setSystemStringMgr (StringMgr *newStringMgr)

Protected Member Functions

 StringMgr (const StringMgr &)
 StringMgr ()
virtual bool supportsUnicode () const
virtual ~StringMgr ()

Static Private Attributes

static StringMgrsystemStringMgr = 0

Friends

class __staticsystemStringMgr

Detailed Description

StringMgr is a way to provide UTf8 handling by the Sword frontend Each platform, if it's up-to-date, should provide functions to handle unicode and utf8. This class makes it possible to implement Unicode support on the user-side and not in Sword itself.

Definition at line 36 of file stringmgr.h.


Constructor & Destructor Documentation

StringMgr::StringMgr (  )  [protected]

Default constructor. Protected to make instances on user side impossible, because this is a Singleton

Default constructor

Definition at line 134 of file stringmgr.cpp.

00134                      {
00135 }

StringMgr::StringMgr ( const StringMgr m  )  [protected]

Copy constructor

Definition at line 139 of file stringmgr.cpp.

00139                                        {
00140 }

StringMgr::~StringMgr (  )  [protected, virtual]

Destructor

Definition at line 144 of file stringmgr.cpp.

00144                       {
00145 }


Member Function Documentation

StringMgr * StringMgr::getSystemStringMgr (  )  [static]

Returns the global StringMgr handle

Returns:
The global string handle

Definition at line 165 of file stringmgr.cpp.

00165                                          {
00166     if (!systemStringMgr) {
00167 #ifdef _ICU_
00168         systemStringMgr = new ICUStringMgr();
00169 //      SWLog::getSystemLog()->logInformation("created default ICUStringMgr");
00170 #else
00171         systemStringMgr = new StringMgr();
00172 //          SWLog::getSystemLog()->logInformation("created default StringMgr");
00173 #endif
00174     }
00175     
00176     return systemStringMgr;
00177 }

static bool StringMgr::hasUTF8Support (  )  [inline, static]

Checks whether Utf8 support is available. Override the function supportsUnicode() to tell whether your implementation has utf8 support.

Returns:
True if this implementation provides support for Utf8 handling or false if just latin1 handling is available

Definition at line 53 of file stringmgr.h.

00053                                         {
00054         return getSystemStringMgr()->supportsUnicode();
00055     };

void StringMgr::setSystemStringMgr ( StringMgr newStringMgr  )  [static]

Sets the global StringMgr handle

Parameters:
newStringMgr The new global StringMgr. This pointer will be deleted by this StringMgr

Definition at line 150 of file stringmgr.cpp.

00150                                                           {
00151     if (systemStringMgr) 
00152         delete systemStringMgr;
00153     
00154     systemStringMgr = newStringMgr;
00155 
00156    // TODO: this is magic. apparently we have to reset the system localemgr upon changing stringmgr.
00157    // setting system stringmgr should be set before localemgr and not possible to change.
00158    // rework this design.
00159     LocaleMgr::getSystemLocaleMgr()->setSystemLocaleMgr(new LocaleMgr());
00160 }

bool StringMgr::supportsUnicode (  )  const [protected, virtual]

Definition at line 235 of file stringmgr.cpp.

00235                                       {
00236     return false; //default impl has no UTF8 support
00237 }

char * StringMgr::upperLatin1 ( char *  buf,
unsigned int  maxlen = 0 
) const [virtual]

Converts the param to an uppercase latin1 string

Parameters:
text The text encoded in latin1 which should be turned into an upper case string
max Max buffer size
Returns:
text buffer (only for convenience)

Converts the param to an uppercase latin1 string

Parameters:
The text encoded in latin1 which should be turned into an upper case string

Definition at line 220 of file stringmgr.cpp.

00220                                                                  {
00221     if (!buf)
00222         return 0;
00223         
00224     char *ret = buf;
00225     bool checkMax = maxlen;
00226 
00227     while (*buf && (!checkMax || maxlen--)) {
00228         *buf = SW_toupper(*buf);
00229         buf++;
00230     }
00231 
00232     return ret;
00233 }

char * StringMgr::upperUTF8 ( char *  t,
unsigned int  maxlen = 0 
) const [virtual]

Converts the param to an upper case Utf8 string

Parameters:
text The text encoded in utf8 which should be turned into an upper case string
max Max buffer size
Returns:
text buffer (only for convenience)

This is a fallback method. It should never be called. If UTF8 support is desired, then a UTF8 StringMgr needs to be used.

Here we just do our best.

Converts the param to an upper case UTF8 string

Parameters:
t - The text encoded in utf8 which should be turned into an upper case string

Definition at line 191 of file stringmgr.cpp.

00191                                                              {
00192     // try to decide if it's worth trying to toupper.  Do we have more
00193     // characters which are probably lower latin than not?
00194     // we still don't use isValidUTF8 optimally. what if we have 1 unicode
00195     // character in the string?  should we not try to upper any of the string?
00196     // dunno.  Best solution is to upper all other characters. Don't have
00197     // time to write that before release.
00198     long performOp = 0;
00199     if (!isValidUTF8((unsigned char *)t)) {
00200         performOp = 1;
00201     }
00202     else {
00203         for (const char *ch = t; *ch; ch++) {
00204             performOp += (*ch > 0) ? 1 : -1;
00205         }
00206     }
00207 
00208     if (performOp > 0) {
00209         return upperLatin1(t);
00210     }
00211 
00212     return t;
00213 }


Friends And Related Function Documentation

friend class __staticsystemStringMgr [friend]

Definition at line 73 of file stringmgr.h.


Member Data Documentation

SWORD_NAMESPACE_START StringMgr * StringMgr::systemStringMgr = 0 [static, private]

Definition at line 90 of file stringmgr.h.


The documentation for this class was generated from the following files:

Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1