Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

SLString Class Reference
[segusoland C++ Library]

This class output localized UTF8 strings from any char* encoding. More...

#include <SLString.hpp>

Inheritance diagram for SLString:

Inheritance graph
[legend]
Collaboration diagram for SLString:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SLString (const char *str, const char *locale=SL_LOCALE_DEFAULT, const char *encoding=SL_ENCODING_DEFAULT)
int cmp (const SLString &other) const
bool operator== (const SLString &other) const
bool operator< (const SLString &other) const
SLString operator+ (const SLString &) const
unsigned long getByteSize () const
const char * to_utf8 () const
const char * get_locale () const
SLHashTable::HashCode getHashCode () const
SLStringclone () const
bool operator== (const SLHashTable::Element &other) const

Protected Attributes

boost::shared_ptr< Data > _shared_ptr

Static Protected Attributes

const char * emptyCString

Detailed Description

This class output localized UTF8 strings from any char* encoding.

Author:
Alexandre Sauve

Todo:
Make real UTF8 conversion with SLString::to_utf8() actually it is the original c_str that is returned, which is not important at this stage 'cause US-ASCII is a subpart of UTF8.
The purpose of this class is not to handle i18n what GNU gettext do very well, but rather to have a generic format for compatibility from various string sources.

For example the "Actions" list in the GUI may be loaded from an XML source where the various localized messages may be in ISO-8859-1, ISO-8859-15 or UTF8 and all these encodings can be from the same country in Europe. So having a class holding all in UTF8 format makes things very simple.

SLString uses shared_ptr, see the Library section for details.

Code Examples :

#include "segusoland.hpp" #include "SLString.hpp" SL_USE_NAMESPACE // code, etc... SLString str("hello", "fr_FR@euro", "ISO-8859-15"); SLString str2("there", "it_IT", "UTF8"); str = str2; // this is safe because SLString uses shared_ptr str = str; // this is safe too (but not usefull) str = SLString(str2); // safe too


Constructor & Destructor Documentation

SLString::SLString const char *  str,
const char *  locale = SL_LOCALE_DEFAULT,
const char *  encoding = SL_ENCODING_DEFAULT
 

This constructor makes a deep copy of its parameters. So there is no need to keep track of input data. In fact it behaves much like the std::string object.

If locale or encoding are the empty string "" or NULL, then the global user defined system encoding is used (from LC_* shell variables)

Parameters:
str is the raw data of the string chars (may be UTF8 string)
locale is the locale of the string (example "fr_FR", "it_IT@euro", etc...) if not provided, then the "C" locale is used.
encoding is the encoding of str (example "ISO-8859-1", "UTF8", etc...) if not provided, then the "C" locale is used.


Member Function Documentation

SLString* SLString::clone  )  const [virtual]
 

Implements SLHashTable::Element::clone()

Implements SLHashTable::Element.

int SLString::cmp const SLString other  )  const
 

Comparison function.

Returns:
respectively
  • negative if this < other
  • 0 if this == other
  • positive if this > other

const char* SLString::get_locale  )  const
 

Get the locale associated with this string.

Warning:
the original SLString must not be destroyed while you use the data. Otherwise make a deep copy of the chars.
Returns:
\0 terminated string in std US-ASCII format.

unsigned long SLString::getByteSize  )  const
 

Returns the size of the UTF8 string in bytes.

SLHashTable::HashCode SLString::getHashCode  )  const [virtual]
 

Implements SLHashTable::Element::getHashCode()

Implements SLHashTable::Element.

SLString SLString::operator+ const SLString  )  const
 

Concatenation of strings The two original strings are left untouched.

Returns:
a new String that is the concatenation of the 2 others.

bool SLString::operator< const SLString other  )  const
 

inferior operator : comparison uses UTF8 strings.

bool SLString::operator== const SLHashTable::Element other  )  const
 

Implements SLHashTable::Element::operator==()

bool SLString::operator== const SLString other  )  const
 

Equality operator.

Returns:
true if UTF8 strings match.

const char* SLString::to_utf8  )  const
 

Returns the UTF8 formatted chars from the given input string and locales

Warning:
the original SLString must not be destroyed while you use the UTF8 data. Otherwise make a deep copy of it.
Returns:
\0 terminated string in UTF8 format.


Member Data Documentation

boost::shared_ptr<Data> SLString::_shared_ptr [protected]
 

This variable hold the various data used by the string in an efficient and memory leaks proof way.

const char* SLString::emptyCString [static, protected]
 

Provides a pointer for fast empty c_string comparison.

Example of code :

char *a = SLString::emptyCString; char *b = a; if (b == emptyString) { // in this case only the adress is compared, making // the code much faster. }


The documentation for this class was generated from the following file:
Generated on Mon Apr 19 01:03:39 2004 for segusoLand by doxygen 1.3.6-20040222