#include <cel_string.h>
Public Types | |
| enum | UnicodeNormalizeForm { , U_NFC = 1, U_NFKD = 2, U_NFKC = 3 } |
Public Member Functions | |
| String () | |
| String (NULL_STRING null) | |
| String (const utf8s &inString, size_t length=STR_AUTOSIZE) | |
| String (const char *inString, size_t length=STR_AUTOSIZE) | |
| String (const std::string &inString, size_t length=STR_AUTOSIZE) | |
| String (const String &inString) | |
| String (const String &inString, size_t start, size_t length) | |
| String (const ReferableString *inString) | |
| String (const UChar2 *inString, size_t length=STR_AUTOSIZE) | |
| String (const UChar4 *inString, size_t length=STR_AUTOSIZE) | |
| String & | operator= (NULL_STRING null) |
| String & | operator= (const utf8s &inString) |
| String & | operator= (const char *inString) |
| String & | operator= (const String &inString) |
| String & | operator= (const UChar2 *inString) |
| String & | operator= (const UChar4 *inString) |
| void | clear () |
| void | format (const char *format,...) |
| void | format (const wchar_t *format,...) |
| void | format_utf8 (const char *format,...) |
| String | substring (size_t start, size_t length=STR_AUTOSIZE) const |
| String | substringByChar (size_t startChar, size_t charCount=STR_AUTOSIZE) const |
| String | removeBoms () const |
| String | operator+ (const String &str) const |
| String & | operator+= (const String &str) |
| bool | isEmpty () const |
| int | compare (const String &str) const |
| int | compareI (const String &str) const |
| bool | operator== (const String &str) const |
| bool | operator< (const String &str) const |
| bool | operator> (const String &str) const |
| bool | operator<= (const String &str) const |
| bool | operator>= (const String &str) const |
| bool | operator!= (const String &str) const |
| UChar1 | operator[] (size_t n) const |
| UChar1 & | operator[] (size_t n) |
| UChar4 | operator() (size_t n) const |
| size_t | getNumOfChars () const |
| size_t | getLength () const |
| const UChar1 * | c_str () const |
| const utf8s | c_utf8str () const |
| size_t | getNthCharPos (size_t nCharPos) const |
| const UChar1 * | getNthCharPtr (size_t nCharPos) const |
| const utf8s | getNthCharUtf8Ptr (size_t nCharPos) const |
| UChar4 | getNthUnicodeChar (size_t nCharPos) const |
| int | toInt () const |
| size_t | toSizeT () const |
| uint64_t | toUInt64 () const |
| double | toDouble () const |
| const UChar1 * | getFirstCharPtr (UChar4 u) const |
| size_t | getCharPos (UChar4 u, size_t from=0) const |
| size_t | getFirstCharPos (UChar4 u) const |
| const UChar1 * | getLastCharPtr (UChar4 u) const |
| size_t | getLastCharPos (UChar4 u) const |
| const UChar1 * | pbrk (const String &str, size_t from=0) const |
| size_t | nbrk (const String &str, size_t from=0) const |
| size_t | getPatternPos (const String &str, size_t from=0) const |
| UChar1 * | allocate (size_t length) |
| String | trimHeadingSpaces () const |
| String | trimTrailingSpaces () const |
| String | trimSpaces () const |
| String | chomp () const |
| size_t | findPos (const String &inPattern) const |
| bool | startWith (const String &inPattern) const |
| bool | endWith (const String &inPattern) const |
| bool | split (const String &inPattern, SimpleArray< String > &outSubstrs, bool inRemoveEmptyStrings=false) const |
| bool | match (const String &inPattern, SimpleArray< String > &outMatches) const |
| AutoPtr< Region > | match (const String &inPattern) const |
| size_t | findOneOf (const UChar4 *inChars, size_t inCharCount) const |
| size_t | findOneOf (const String &inChars) const |
| const UChar1 * | findPtr (const String &inPattern) const |
| String | replace (const String &inReplacee, const String &inReplacer, u32 inFlags=0) const |
| String | erase (size_t inPos, size_t inLength) const |
| String | erase (const String &inPattern) const |
| void | serialize (Stream *inStream, size_t inLevel, Endian inEndian) const |
| void | deserialize (Stream *inStream, size_t inLevel, Endian inEndian) |
| const UChar1 * | begin () const |
| const UChar1 * | end () const |
| const UChar1 * | raw_ptr () const |
| const UChar1 * | raw_end () const |
| String | toUpper () const |
| String | toLower () const |
| String | applyTransform (Transform &inTransform) |
| String | normalize (UnicodeNormalizeForm form) const |
| const char * | toMbs () const |
| const wchar_t * | toWcs () const |
| const UChar2 * | toUcs2 () const |
| const UChar4 * | toUcs4 () const |
| String | resolveEntityReferences () const |
Static Public Member Functions | |
| static int | compare (const String &str1, const String &str2) |
| static int | compareI (const String &str1, const String &str2) |
| static String | concat (const utf8s &str1, const Celartem::String &str2) |
| static String | concat (const SimpleArray< String > &inStrings, const String &inSeparator=NullString) |
| static const UChar1 * | next (const UChar1 *inStrPtr) |
| static UChar1 * | next (UChar1 *inStrPtr) |
| static size_t | getCharSize (const UChar1 *inStrPtr) |
| static UChar4 | getCharcode (const UChar1 *inStrPtr) |
| static bool | isWhiteSpace (const UChar1 *inStrPtr) |
| static bool | isLineTerminator (const UChar1 *inStrPtr) |
| static bool | isValidUTF8Sequence (const u8 *inDataToValidate, size_t inSize) |
Classes | |
| class | Transform |
Definition at line 251 of file cel_string.h.
Normalization Form Selector; used with normalize function. For more information, see Unicode Standard Annex #15 Unicode Normalization Forms.
Definition at line 1309 of file cel_string.h.
| Celartem::String::String | ( | ) |
This constructor initializes the String instance with "", not NULL; The string contains a '\0'.
| Celartem::String::String | ( | NULL_STRING | null | ) |
This constructor accepts NullString and initializes the String instance with "", not NULL; The string contains a '\0'.
| null | It should be NullString. |
| Celartem::String::String | ( | const utf8s & | inString, | |
| size_t | length = STR_AUTOSIZE | |||
| ) |
This constructor initializes the String with UTF-8 string.
| inString | UTF-8 string to be preserved. | |
| length | the length of the string to be preserved; you can remove the trailing string by intensionally set the length less than actual size. You can also omit the parameter and then String automatically measures the length of string (regarding the string is terminated by '\0'). |
| Celartem::String::String | ( | const char * | inString, | |
| size_t | length = STR_AUTOSIZE | |||
| ) |
This constructor initializes the String with platform dependent multibyte string. Since String stores strings as UTF-8 string, this constructor converts the input string into UTF-8 string. If the input string is only contains ASCII 7bit characters and you think you don't want to take the conversion cost, use the utf8s version of the constructor. Mac OS X's native multibyte is UTF-8 and this constructor does not cost so much in Mac OS X.
| inString | Platform/Locale specific multibyte character string. | |
| length | The length of the string to be preserved; you can remove the trailing string by intensionally set the length less than actual size. You can also omit the parameter and then String automatically measures the length of string (regarding the string is terminated by '\0'). |
| Celartem::String::String | ( | const std::string & | inString, | |
| size_t | length = STR_AUTOSIZE | |||
| ) |
This constructor initializes the String with std::string. Since String stores strings as UTF-8 string, this constructor converts the input string into UTF-8 string.
| inString | Platform/Locale specific multibyte character string. | |
| length | The length of the string to be preserved; you can remove the trailing string by intensionally set the length less than actual size. You can also omit the parameter and then String automatically measures the length of string (regarding the string is terminated by '\0'). |
| Celartem::String::String | ( | const String & | inString | ) |
| Celartem::String::String | ( | const String & | inString, | |
| size_t | start, | |||
| size_t | length | |||
| ) |
This constructor duplicates the input String.
Since the String class manages the strings by reference count mechanism, this constructor does not cost so much.
| inString | string to copy. | |
| start | The position of the substring to copy. | |
| length | The length of the string to be preserved; you can remove the trailing string by intensionally set the length less than actual size. You can also omit the parameter and then String automatically measures the length of string (regarding the string is terminated by '\0'). |
| Celartem::String::String | ( | const ReferableString * | inString | ) |
| Celartem::String::String | ( | const UChar2 * | inString, | |
| size_t | length = STR_AUTOSIZE | |||
| ) |
This constructor initializes the String with UTF-16 string. Since the String class stores strings as UTF-8, this constructor is more effecient than the multibyte version.
| inString | String in UTF-16. | |
| length | The length of the string to be preserved in characters; you can remove the trailing string by intensionally set the length less than actual size. You can also omit the parameter and then String automatically measures the length of string (regarding the string is terminated by '\0'). |
| Celartem::String::String | ( | const UChar4 * | inString, | |
| size_t | length = STR_AUTOSIZE | |||
| ) |
This constructor initializes the String with UTF-32 string. Since the String class stores strings as UTF-8, this constructor is more effecient than the multibyte version.
| inString | A string in UCS-4(UTF-32). | |
| length | the length of the string to be preserved; you can remove the trailing string by intensionally set the length less than actual size. You can also omit the parameter and then String automatically measures the length of string (regarding the string is terminated by '\0'). |
| String& Celartem::String::operator= | ( | NULL_STRING | null | ) |
This method accepts NullString and clears the string.
| null | It should be NullString. |
This method duplicates the specified UTF-8 string.
| inString | string to be copied. |
String s = utf8s("Hello, world!");
| String& Celartem::String::operator= | ( | const char * | inString | ) |
This method duplicates the specified multibyte string. Since String stores strings as UTF-8 string, this method converts the input string into UTF-8 string. If the input string is only contains ASCII 7bit characters and you think you don't want to take the conversion cost, use the utf8s version of the constructor. Mac OS X's native multibyte is UTF-8 and this constructor does not cost so much in Mac OS X.
| inString | Platform/Locale depended multibyte string. |
This method duplicates the specified string.
| inString | String in UTF-16. |
This method duplicates the specified string.
| inString | String in UCS-4(UTF-32). |
| void Celartem::String::clear | ( | ) |
This method resets the string to "". This method also confirms the memory block is zero-cleared.
| void Celartem::String::format | ( | const char * | format, | |
| ... | ||||
| ) |
This method formats the string; the result is identical to sprintf. This method may be affected by the current locale and can be used with platform specific printf extensions.
| format | String that specifies the format of parameters. |
| void Celartem::String::format | ( | const wchar_t * | format, | |
| ... | ||||
| ) |
This method formats the string; the result is identical to swprintf. This method may be affected by the current locale and can be used with platform specific printf extensions.
| format | String that specifies the format of parameters. |
| void Celartem::String::format_utf8 | ( | const char * | format, | |
| ... | ||||
| ) |
This method is UTF-8 version of format method. It formats the string; the result is identical to sprintf. This function is not affected by the current locale and it does not accept platform specific printf extensions.
| format | String that specifies the format of parameters. |
| String Celartem::String::substring | ( | size_t | start, | |
| size_t | length = STR_AUTOSIZE | |||
| ) | const |
This method extracts a portion of the string. There is no guarantee that the result string is a vaild UTF-8 string if you specify some invalid position and/or length.
| start | 0 based index from which we extract the sub-string. If this value is larger than the length of the string, this function returns NullString. | |
| length | the number of characters to be extracted. You don't have to think about the room for terminating '\0'. If length exceeds the length of the string, this method fits the length to the original string. |
Referenced by Celartem::DjVu::Link::getType().
| String Celartem::String::substringByChar | ( | size_t | startChar, | |
| size_t | charCount = STR_AUTOSIZE | |||
| ) | const |
This method extracts a portion of the string. This method works much like as if the string were stored as UCS-4 character array.
| startChar | 0 based index in UCS-4 character array. If this value points exceeds the end of the string, this function returns NullString. | |
| charCount | the number of UCS-4 characters to be extracted. You don't have to think about the room for terminating '\0'. If length exceeds the length of the string, this method fits the length to the original string. |
| String Celartem::String::removeBoms | ( | ) | const |
This method removes any heading BOMs from the string. BOM is usually only on the head of Unicode strings but it may be in the middle of the string due to incorrect string operations. This function checks all the string and removes all occurrences of BOM. If the string does not contain BOMs, this function simply returns the string.
This method concatenates the specified string to the tail. This method DOES NOT modify the original.
| str | A string to concatenate. |
This method concatenates the specified string to the tail. This method DOES modify the original. The behavior of this method is almost identical to strcat function.
| str | A string to concatenate. |
*this ). | bool Celartem::String::isEmpty | ( | ) | const |
This method verifies the string is empty or not.
true if the string is empty, otherwise false. Referenced by Celartem::DjVu::Link::getType(), Celartem::DjVu::TextWithFontConfig::isEmpty(), Celartem::DjVu::Link::isEmptyLink(), and Celartem::DjVu::FontConfig::isValid().
This function compares two strings.
| str1 | ||
| str2 | Strings to compare. |
This function compares two strings in 7-bit ASCII case insensitive manner.
| str1 | ||
| str2 | Strings to compare. |
| int Celartem::String::compare | ( | const String & | str | ) | const |
This method compares this string with another string.
| str | String to compare with. |
| int Celartem::String::compareI | ( | const String & | str | ) | const |
This method compares this string with another string in 7-bit ASCII case insensitive manner.
| str | String to compare with. |
| bool Celartem::String::operator== | ( | const String & | str | ) | const |
For direct comparison with the other String. This method internally uses compare method.
| str | A string to compare with. |
true if the strings are same value, otherwise false. | bool Celartem::String::operator< | ( | const String & | str | ) | const |
For direct comparison with the other String. This method internally uses compare method.
| str | A string to compare with. |
true if the string is less than str in the dictionary order, otherwise false. | bool Celartem::String::operator> | ( | const String & | str | ) | const |
For direct comparison with the other String. This method internally uses compare method.
| str | A string to compare with. |
true if the string is larger than str in the dictionary order, otherwise false. | bool Celartem::String::operator<= | ( | const String & | str | ) | const |
For direct comparison with the other String. This method internally uses compare method.
| str | A string to compare with. |
true if the string is no more than str in the dictionary order, otherwise false. | bool Celartem::String::operator>= | ( | const String & | str | ) | const |
For direct comparison with the other String. This method internally uses compare method.
| str | A string to compare with. |
true if the string is no less than str in the dictionary order, otherwise false. | bool Celartem::String::operator!= | ( | const String & | str | ) | const |
For direct comparison with the other String. This method internally uses compare method.
| str | A string to compare with. |
true if the strings are not equal value in the dictionary order, otherwise false. | UChar1 Celartem::String::operator[] | ( | size_t | n | ) | const |
This method is to get the character of specified position.
| n | The position of the character. |
| UChar1& Celartem::String::operator[] | ( | size_t | n | ) |
This method is to get the character of specified position. This method may internally duplicate the string to realize modification of the string and it potentially has heavy overhead.
| n | The position of the character. |
| UChar4 Celartem::String::operator() | ( | size_t | n | ) | const [inline] |
This method is to get the character of specified position. This method works much like as if the string were stored as UCS-4 character array.
| n | The position of the UCS-4 character. |
Definition at line 700 of file cel_string.h.
| size_t Celartem::String::getNumOfChars | ( | ) | const |
This method returns the number of UCS-4 characters in the string.
| size_t Celartem::String::getLength | ( | ) | const |
This method returns the number of characters in the string.
Referenced by Celartem::Base64T< Base64Traits >::decode(), end(), and Celartem::DjVu::Link::getType().
| const UChar1* Celartem::String::c_str | ( | ) | const |
This method returns the pointer to the raw UTF-8 string. Be careful to use this function with String related methods; they may regard the string as the environment native multibyte rather than UTF-8.
Since String class internally uses Pascal style non null-terminated string, the function may take some time to convert the raw string into C/C++ compatible null-terminated string. If you don't want such overheads, use raw_ptr() and raw_end() function.
Referenced by begin(), c_utf8str(), Celartem::Base64T< Base64Traits >::decode(), end(), Celartem::RegularExpression::findFirst(), Celartem::DataStore::get(), and Celartem::RegularExpression::RegularExpression().
| const utf8s Celartem::String::c_utf8str | ( | ) | const [inline] |
This method returns the pointer to the raw UTF-8 string. This method is identical to c_str() method except it returns utf8s string proxy object.
Since String class internally uses Pascal style non null-terminated string, the function may take some time to convert the raw string into C/C++ compatible null-terminated string. If you don't want such overheads, use raw_ptr() and raw_end() function.
Definition at line 748 of file cel_string.h.
| size_t Celartem::String::getNthCharPos | ( | size_t | nCharPos | ) | const |
This method returns the position of n-th UCS-4 character in the string.
| nCharPos | The position of the UCS-4 character. |
| const UChar1* Celartem::String::getNthCharPtr | ( | size_t | nCharPos | ) | const |
This method returns the pointer to n-th UCS-4 character in the string.
| nCharPos | The position of the UCS-4 character. |
NULL. Referenced by getNthCharUtf8Ptr(), and getNthUnicodeChar().
| const utf8s Celartem::String::getNthCharUtf8Ptr | ( | size_t | nCharPos | ) | const [inline] |
This method returns the pointer to n-th UCS-4 character in the string by utf8s proxy object.
| nCharPos | The position of the UCS-4 character. |
Definition at line 785 of file cel_string.h.
| UChar4 Celartem::String::getNthUnicodeChar | ( | size_t | nCharPos | ) | const [inline] |
This method returns n-th UCS-4 character in the string.
| nCharPos | The position of the UCS-4 character. |
Definition at line 798 of file cel_string.h.
Referenced by operator()().
| int Celartem::String::toInt | ( | ) | const |
This method converts the string into int value.
Referenced by Celartem::DjVu::Link::getType().
| size_t Celartem::String::toSizeT | ( | ) | const |
This method converts the string into size_t value.
| uint64_t Celartem::String::toUInt64 | ( | ) | const |
This method converts the string into uint64_t value.
| double Celartem::String::toDouble | ( | ) | const |
This method converts the string into double value.
This method searches the string for the first occurrence of a character that matches the specified character. The behavior is almost identical to strchr function except it accepts UCS-4 character code.
| u | UCS-4 character code to search. |
NULL. | size_t Celartem::String::getCharPos | ( | UChar4 | u, | |
| size_t | from = 0 | |||
| ) | const |
This method searches the string for the occurrence of a character that matches the specified character.
| u | UCS-4 character code to search. | |
| from | Where the search starts from. For the further information, see the sample code below: |
size_t pos = 0; for(;;) { pos = str.getCharPos('/', pos); if(pos == notFound) break; // no more occurrences // do the task for this occurrence // .... pos++; // prepare for the next search };
| size_t Celartem::String::getFirstCharPos | ( | UChar4 | u | ) | const |
This method searches the string for the first occurrence of a character that matches the specified character. The behavior is almost identical to strchr function except it accepts UCS-4 character code and returns 0-based index.
| u | UCS-4 character code to search. |
This method searches the string for the last occurrence of a specified character. The behavior is almost identical to strrchr function except it accepts UCS-4 character code.
| u | UCS-4 character code to search. |
NULL. | size_t Celartem::String::getLastCharPos | ( | UChar4 | u | ) | const |
This method searches the string for the last occurrence of a specified character. The behavior is almost identical to strrchr function except it accepts UCS-4 character code and returns 0-based index.
| u | UCS-4 character code to search. |
This method searches the string for the first occurrence of a character contained in a specified string. This search does not include the null terminator. The behavior is almost identical to strpbrk function.
| str | The string that contains the characters for which to search. | |
| from | Where the search starts from. |
NULL. | size_t Celartem::String::nbrk | ( | const String & | str, | |
| size_t | from = 0 | |||
| ) | const |
This method searches the string for the first occurrence of a character contained in a specified string. This search does not include the null terminator. The behavior is almost identical to strpbrk function except it returns 0-based index.
This method is just an alias of getPatternPos.
| str | The string that contains the characters for which to search. | |
| from | Where the search starts from. |
Referenced by getPatternPos().
| size_t Celartem::String::getPatternPos | ( | const String & | str, | |
| size_t | from = 0 | |||
| ) | const [inline] |
This method searches the string for the first occurrence of a character contained in a specified string. This search does not include the null terminator. The behavior is almost identical to strpbrk function except it returns 0-based index. This method is just an alias of nbrk.
| str | The string that contains the characters for which to search. | |
| from | Where the search starts from. |
Definition at line 966 of file cel_string.h.
| UChar1* Celartem::String::allocate | ( | size_t | length | ) |
This method allocates bytes specified by length. You don't have to make the room for trailing null-terminator. It will be automatically appended and initialized with '\0'.
UChar1 *p = str1.allocate(3); std::memcpy(p, "123", 4); // You don't have to add '\0'. UChar1 *q = str2.allocate(5); q[0] = '0'; q[0] = '1'; q[0] = '2'; q[0] = '3'; q[0] = '4';
| length | the buffer length to allocate. It don't have to include the terminating '\0'. |
Referenced by Celartem::Base64T< Base64Traits >::encode().
| String Celartem::String::trimHeadingSpaces | ( | ) | const |
This method removes any space characters (' ', \t) in the head of the string if exist.
| String Celartem::String::trimTrailingSpaces | ( | ) | const |
This method removes any space characters (' ', \t) in the tail of the string if exist.
| String Celartem::String::trimSpaces | ( | ) | const |
This method removes any space characters (' ', \t) in both of the head and the tail of the string if exist.
| String Celartem::String::chomp | ( | ) | const |
This method removes the trailing CR/LF/CRLF codes if exist.
| size_t Celartem::String::findPos | ( | const String & | inPattern | ) | const |
This function tries to find the specified pattern from the string and return the index to the character.
| inPattern | The string to find. |
| bool Celartem::String::startWith | ( | const String & | inPattern | ) | const |
This function checks whether the string starts from the specified pattern or not.
| inPattern | The pattern in String. |
true if the string starts from the specified pattern, otherwise false. | bool Celartem::String::endWith | ( | const String & | inPattern | ) | const |
This function checks whether the string ends with the specified pattern or not.
| inPattern | The pattern in String. |
true if the string ends with the specified pattern, otherwise false. | bool Celartem::String::split | ( | const String & | inPattern, | |
| SimpleArray< String > & | outSubstrs, | |||
| bool | inRemoveEmptyStrings = false | |||
| ) | const |
This function tries to split the string by the specified regular expression pattern and returns the splitted substrings. For more information, see RegularExpression.
| inPattern | The regular expression pattern to separates the string. | |
| outSubstrs | The splitted substrings. | |
| inRemoveEmptyStrings | Whether to remove empty substrings or not. |
true if the split process is successful, otherwise false. | bool Celartem: |