ULAPI
8.0
|
A string wrapper class for use in the Ultralingua API. More...
#include <ulstring.h>
Public Types | |
enum | { UTF8, UTF16BE, UTF16LE } |
Public Member Functions | |
ULString () | |
ULString (const ULString &s) | |
ULString (const char *s) | |
ULString (ulchar ch) | |
virtual | ~ULString () |
void | clear () |
ULString & | operator= (const ULString &s) |
ULString & | operator= (const char *s) |
ULString & | operator+= (const ULString &s) |
ULString & | operator+= (const char *s) |
ULString & | operator+= (ulchar ch) |
ulchar | operator[] (int n) const |
operator const char * () | |
uluint32 | length () const |
void | setAt (uluint32 index, ulchar value) |
int | getEncoding () const |
void | setEncoding (const char *encodingName) |
void | setEncoding (int newEncoding) |
const char * | getBuffer () |
void | fromUTF8 (const char *utf8Buffer) |
ULStringIterator | begin () const |
ULStringReverseIterator | rbegin () const |
ULStringIterator | end () const |
ULStringReverseIterator | rend () const |
bool | contains (ulchar ch) const |
bool | contains (const char *s) const |
bool | contains (const ULString &s) const |
ULStringIterator | find (ulchar ch) const |
ULStringIterator | find (const char *s) const |
ULStringIterator | find (const ULString &s) const |
ULStringIterator | rfind (ulchar ch) const |
ULStringIterator | rfind (const char *s) const |
ULStringIterator | rfind (const ULString &s) const |
bool | startsWith (const ULString &head) const |
bool | startsWith (const ULString &head, ULCollator *collator, bool ignoreCase, bool ignoreAccents) const |
bool | endsWith (const ULString &tail) const |
bool | endsWith (const ULString &tail, ULLanguage language, bool ignoreCase, bool ignoreAccents) const |
void | replace (const ULString &textToReplace, const ULString &replacementText) |
void | replace (ulchar charToReplace, const ULString &replacementText) |
void | replace (const ULStringIterator &iterator, uluint32 nCharsToReplace, const ULString &replacementText) |
void | replace (uluint32 index, uluint32 nCharsToReplace, const ULString &replacementText) |
void | erase (ULStringIterator &iterator, uluint32 nCharsToErase=1) |
void | erase (uluint32 start, uluint32 nCharsToErase=1) |
void | insert (const ULStringIterator &iterator, const ULString &s) |
void | insert (ulint32 insertionIndex, const ULString &s) |
ULString | substr (ulint32 start, ulint32 nChars) const |
ULString | substr (const ULStringIterator &start, const ULStringIterator &end) const |
ulint32 | compare (const ULString &s, const ULLanguage &language) const |
ulint32 | compare (const ULString &s, const ULLanguage &language, bool ignoreCase, bool ignoreAccents) const |
bool | equals (const ULString &s, bool ignoreCase, bool ignoreAccents) const |
uluint32 | hash (uluint32 tableSize) const |
ULString & | reverse () |
ULString & | toLower () |
ULString & | toLower (const ULLanguage &language) |
ULString & | toUpper () |
ULString & | toUpper (const ULLanguage &language) |
ULString & | toBase () |
ULString & | toBase (const ULLanguage &language) |
int | getIntegerValue () const |
void | appendInteger (int n, uluint32 base=10) |
void | split (const ULString &s, ULList< ULString > &stringList, bool stripParts=false) const |
void | strip (const char *charactersToRemove=0) |
ULString | join (const ULList< ULString > &stringList) const |
Friends | |
class | ULStringIterator |
class | ULStringReverseIterator |
class | ULCollator |
bool | operator== (const ULString &a, const ULString &b) |
bool | operator< (const ULString &a, const ULString &b) |
A string wrapper class for use in the Ultralingua API.
This wrapper will enable us to swap string libraries in and out of ULAPI depending on the constraints of a particular application or platform.
If UL_USING_ICU is #defined, then an implementation based on ICU (http://site.icu-project.org/) will be used. Otherwise, a "legacy" implementation based on ULAPI version 7 will be used.
ULString::ULString | ( | ) |
Default constructor.
ULString::ULString | ( | const ULString & | s | ) |
Copy constructor.
ULString::ULString | ( | const char * | s | ) |
[in] | s | The string to be stored in this ULString object. |
Strings stored as char *'s need to be in an escaped form using only "invariant" characters (essentially printable ASCII). To represent the French word for "to be" as a char * literal, for example, you would use "\\u00EAtre", where 00EA is the hexadecimal codepoint for a lower-case e with a circumflex. The double backslash is necessary because the escape sequence will be interpreted at run-time, not at compile-time.
Non-invariant characters can be represented using either the or the escape sequence (again, with the backslash doubled).
For more details on ICU string literals, see http://userguide.icu-project.org/strings, especially the subsection entitled "Compiler-dependent definitions.".
Note that we are using the ICU string literals even in non-ICU implementations of ULString, to preserve the ULString interfaces.
ULString::ULString | ( | ulchar | ch | ) |
Constructor.
[in] | ch | The character with which to initialize this string. |
|
virtual |
Destructor.
void ULString::appendInteger | ( | int | n, |
uluint32 | base = 10 |
||
) |
Appends to this string characters representing the specified integer in the specified base.
[in] | n | The integer to append to this string. |
[in] | base | The base in which to represent the integer. |
ULStringIterator ULString::begin | ( | ) | const |
void ULString::clear | ( | ) |
Sets this string to the empty string.
ulint32 ULString::compare | ( | const ULString & | s, |
const ULLanguage & | language | ||
) | const |
Language-dependent collation function.
[in] | s | The string to compare with this string. |
[in] | language | The language in which to compare the strings. |
ulint32 ULString::compare | ( | const ULString & | s, |
const ULLanguage & | language, | ||
bool | ignoreCase, | ||
bool | ignoreAccents | ||
) | const |
Language-dependent collation function, with control over case and and accent sensitivity.
[in] | s | The string to compare with this string. |
[in] | language | The language in which to compare the strings. |
[in] | ignoreCase | True if the comparison should be case-insensitive. |
[in] | ignoreAccents | True if the comparison should be accent-insensitive. |
bool ULString::contains | ( | ulchar | ch | ) | const |
[in] | ch | the character to be found. |
bool ULString::contains | ( | const char * | s | ) | const |
See ULString::ULString(const char *) for information on string literals.
[in] | s | the substring to be found. |
bool ULString::contains | ( | const ULString & | s | ) | const |
[in] | s | the substring to be found. |
ULStringIterator ULString::end | ( | ) | const |
bool ULString::endsWith | ( | const ULString & | tail | ) | const |
[in] | tail | The characters to match with the end of this string. |
bool ULString::endsWith | ( | const ULString & | tail, |
ULLanguage | language, | ||
bool | ignoreCase, | ||
bool | ignoreAccents | ||
) | const |
[in] | tail | The characters to match with the end of this string. |
[in] | ignoreCase | If true, the comparison between head and the end of this string will be case-insensitive. |
[in] | ignoreAccents | If true, the comparison is done both case- and accent-insensitively. |
bool ULString::equals | ( | const ULString & | s, |
bool | ignoreCase, | ||
bool | ignoreAccents | ||
) | const |
[in] | s | the string with which to compare this string. |
[in] | ignoreCase | true if the strings should be compared case-insensitively. |
[in] | ignoreAccents | true if the strings should be compared accent-insensitively. |
void ULString::erase | ( | ULStringIterator & | iterator, |
uluint32 | nCharsToErase = 1 |
||
) |
Removes characters from this string.
[in,out] | iterator | This parameter initially points to the first character to be erased. After the erasure, it points to the character that immediately followed the last erased character (or the end of the string, if the final character was erased). |
[in] | nCharsToErase | The number of characters to erase (default=1). |
void ULString::erase | ( | uluint32 | start, |
uluint32 | nCharsToErase = 1 |
||
) |
Removes characters from this string.
[in] | start | The index of the first character to be erased. |
[in] | nCharsToErase | The number of characters to erase. |
ULStringIterator ULString::find | ( | ulchar | ch | ) | const |
[in] | ch | The character to be found. |
ULStringIterator ULString::find | ( | const char * | s | ) | const |
See ULString::ULString(const char *) for information on string literals.
[in] | s | The substring to be found. |
ULStringIterator ULString::find | ( | const ULString & | s | ) | const |
[in] | s | The substring to be found. |
void ULString::fromUTF8 | ( | const char * | utf8Buffer | ) |
TODO this doc plus more of this type of method.
const char * ULString::getBuffer | ( | ) |
Note that getBuffer is a non-const method to enable conversion to be done lazily. For the most part, a string will undergo many changes before it needs to be written to disk or viewed on screen. Performing a conversion from ULString's native representation into the encoded form at every change is thus a big time waste. The price we pay for better performance is a non-const getBuffer.
int ULString::getEncoding | ( | ) | const |
int ULString::getIntegerValue | ( | ) | const |
uluint32 ULString::hash | ( | uluint32 | tableSize | ) | const |
[in] | tableSize | The size of the hash table for which this hash value will be used. |
void ULString::insert | ( | const ULStringIterator & | iterator, |
const ULString & | s | ||
) |
Inserts characters into this string.
[in] | iterator | An iterator pointing to the character in front of which to insert the new characters (or to the end of this string, in which case the new characters will be appended to this string). |
[in] | s | The characters to insert into this string. |
void ULString::insert | ( | ulint32 | insertionIndex, |
const ULString & | s | ||
) |
Inserts characters into this string.
[in] | insertionIndex | The 0-based index of the character in front of which to insert the new characters. If -1, the characters will be appended to the end of this string. |
[in] | s | The characters to insert into this string. |
[in] | stringList | the list to be joined. |
uluint32 ULString::length | ( | ) | const |
ULString::operator const char * | ( | ) |
ULString & ULString::operator+= | ( | const char * | s | ) |
Appends the specified string literal to this ULString object.
[in] | s | The string to be appended to this ULString object. See ULString::ULString(const char *) for information on string literals. |
ULString & ULString::operator+= | ( | ulchar | ch | ) |
ULString & ULString::operator= | ( | const char * | s | ) |
[in] | s | The string to be copied into this ULString object. See ULString::ULString(const char *) for information on string literals. |
ulchar ULString::operator[] | ( | int | n | ) | const |
[in] | n | The index of the desired character. If n is negative, the character returned is the nth from the end (-1 means the last character, -2 the second to last, etc.). |
ULStringReverseIterator ULString::rbegin | ( | ) | const |
ULStringReverseIterator ULString::rend | ( | ) | const |
Replaces all occurrences in this string of the specified substring with the specified replacement text.
[in] | textToReplace | The substring to be replaced. |
[in] | replacementText | The text with which to replace each occurrence of the substring. |
void ULString::replace | ( | ulchar | charToReplace, |
const ULString & | replacementText | ||
) |
Replaces all occurrences in this string of the specified character with the specified replacement text.
[in] | charToReplace | The substring to be replaced. |
[in] | replacementText | The text with which to replace each occurrence of the substring. |
void ULString::replace | ( | const ULStringIterator & | iterator, |
uluint32 | nCharsToReplace, | ||
const ULString & | replacementText | ||
) |
Replaces a substring of this string with the specified replacement text.
[in] | iterator | The beginning of the substring to replace. |
[in] | nCharsToReplace | The number of characters to replace. |
[in] | replacementText | The text with which to replace the substring. |
void ULString::replace | ( | uluint32 | index, |
uluint32 | nCharsToReplace, | ||
const ULString & | replacementText | ||
) |
Replaces a substring of this string with the specified replacement text.
[in] | index | The beginning of the substring to replace. |
[in] | nCharsToReplace | The number of characters to replace. |
[in] | replacementText | The text with which to replace the substring. |
ULString & ULString::reverse | ( | ) |
Reverses this ULString in place.
ULStringIterator ULString::rfind | ( | ulchar | ch | ) | const |
[in] | ch | The character to be found. |
ULStringIterator ULString::rfind | ( | const char * | s | ) | const |
See ULString::ULString(const char *) for information on string literals.
[in] | s | The substring to be found. |
ULStringIterator ULString::rfind | ( | const ULString & | s | ) | const |
[in] | s | The substring to be found. |
void ULString::setAt | ( | uluint32 | index, |
ulchar | value | ||
) |
Sets the character at the specified index to the specified character.
[in] | index | The index of the character to change. |
[in] | value | The value to which to set the character. |
void ULString::setEncoding | ( | const char * | encodingName | ) |
Sets the encoding for this string, to be used when getBuffer is called.
[in] | encodingName | the name of the desired encoding. Possible values include "utf-8", "UTF-8", "utf-16be", "UTF-16BE", "utf-16le", and "UTF-16LE" (where "BE" and "LE" stand for "big endian" and "little endian", respectively). |
void ULString::setEncoding | ( | int | newEncoding | ) |
Sets the encoding for this string, to be used when getBuffer is called.
[in] | newEncoding | the desired encoding. Possible values are enumerated in the ulstring.h header file, and include ULString::UTF8, ULString::UTF16BE (big endian), and ULString::UTF16LE (little endian). |
void ULString::split | ( | const ULString & | delimiter, |
ULList< ULString > & | stringList, | ||
bool | stripParts = false |
||
) | const |
Creates a list of strings consisting of the substrings of this string between occurrences of the string s. For example, if this string is "abracadabra" and s is "a", then the resulting list is ("", "br", "c", "d", "br", "").
[in] | delimiter | The delimiter substring. |
[out] | stringList | The list of substrings obtained by the splitting. |
[in] | stripParts | True if the substrings should be stripped of white space on the left and right before being added to the string list. |
bool ULString::startsWith | ( | const ULString & | head | ) | const |
[in] | head | The characters to match with the beginning of this string. |
bool ULString::startsWith | ( | const ULString & | head, |
ULCollator * | collator, | ||
bool | ignoreCase, | ||
bool | ignoreAccents | ||
) | const |
[in] | head | The characters to match with the beginning of this string. |
[in] | collator | A collator with which to compare the head to this string. |
[in] | ignoreCase | If true, the comparison between head and the beginning of this string will be case-insensitive. |
[in] | ignoreAccents | If true, the comparison is done both case- and accent-insensitively. |
void ULString::strip | ( | const char * | charactersToRemove = 0 | ) |
Removes zero or more copies of the specified characters from both ends of this string. For example, if charactersToRemove = ",.!?:; ", then strip will remove punctuation and spaces from both ends of the string.
[in] | charactersToRemove | the characters to strip. If this pointer is null, then strip removes white space (spaces, tabs, linefeeds, and carriage returns). |
ULString ULString::substr | ( | ulint32 | start, |
ulint32 | nChars | ||
) | const |
[in] | start | The index of the first character of the desired substring. |
[in] | nChars | The number of characters in the substring. |
ULString ULString::substr | ( | const ULStringIterator & | start, |
const ULStringIterator & | end | ||
) | const |
[in] | start | An iterator pointing to the first character of the desired substring. |
[in] | end | An iterator pointing to the position immediately following the end of the substring. |
ULString & ULString::toBase | ( | ) |
Removes accents from this string using the default locale.
ULString & ULString::toBase | ( | const ULLanguage & | language | ) |
Removes accents from this string using a locale appropriate for the specified language.
[in] | language | The language. |
ULString & ULString::toLower | ( | ) |
Changes this string to lower case using the default locale.
ULString & ULString::toLower | ( | const ULLanguage & | language | ) |
Changes this string to lower case using a locale appropriate for the specified language.
[in] | language | The language. |
ULString & ULString::toUpper | ( | ) |
Changes this string to upper case using the default locale.
ULString & ULString::toUpper | ( | const ULLanguage & | language | ) |
Changes this string to upper case using a locale appropriate for the specified language.
[in] | language | The language. |
[in] | a | The first string. |
[in] | s | The second string. |
[in] | a | The first string. |
[in] | s | The second string. |
|
friend |
|
friend |
|
friend |