CartoType C++ API 7.8.2, 2022-03-25
for Windows, Linux, Qt and other platforms supporting C++ development
|
#include <cartotype_string.h>
Public Member Functions | |
virtual | ~MString () |
template<typename T > | |
MString & | operator= (const T &aText) |
template<typename T > | |
MString & | operator+= (const T &aText) |
size_t | Length () const |
bool | IsEmpty () const |
virtual const uint16_t * | Text () const =0 |
void | Delete (size_t aStart, size_t aEnd) |
void | Clear () |
void | SetLengthToZero () |
std::basic_string< uint16_t > | CreateUtf16String () const |
std::string | CreateUtf8String () const |
operator std::string () const | |
uint16_t | operator[] (size_t aIndex) const |
TText | First (size_t aLength) const |
TText | Last (size_t aLength) const |
void | DeletePrefix (const MString &aPrefix) |
void | DeleteSuffix (const MString &aSuffix) |
void | SetCase (TLetterCase aCase, const CStringTypeDictionary *aTitleCaseDictionary=0) |
void | SetSentenceCase () |
int32_t | Compare (MIter< int32_t > &aIter, TStringMatchMethod aStringMatchMethod) const noexcept |
TResult | Replace (size_t aStart, size_t aEnd, MIter< int32_t > &aText, size_t aMaxLength) |
int32_t | Compare (const MString &aString) const |
int32_t | Compare (const MString &aString, TStringMatchMethod aStringMatchMethod) const noexcept |
size_t | Find (const MString &aString, TStringMatchMethod aStringMatchMethod=TStringMatchMethod::Exact, size_t *aEndPos=nullptr) const noexcept |
void | Replace (size_t aStart, size_t aEnd, const MString &aString) |
void | Insert (size_t aIndex, const MString &aString) |
void | Append (const MString &aString) |
void | AppendCommaSeparated (const CString &aLabel, const CString &aText, size_t &aItems, size_t aMaxItems=SIZE_MAX) |
void | Set (const MString &aString) |
int32_t | Compare (const uint16_t *aText) const |
int32_t | Compare (const uint16_t *aText, size_t aLength) const |
int32_t | Compare (const char16_t *aText, size_t aLength=npos) const |
int32_t | Compare (const uint16_t *aText, size_t aLength, TStringMatchMethod aStringMatchMethod) const noexcept |
void | Replace (size_t aStart, size_t aEnd, const uint16_t *aText, size_t aLength=npos) |
void | Insert (size_t aIndex, const uint16_t *aText, size_t aLength=npos) |
void | Append (const uint16_t *aText, size_t aLength=npos) |
void | Set (const uint16_t *aText, size_t aLength=npos) |
int32_t | Compare (const char *aText, size_t aLength=npos, TStringMatchMethod aStringMatchMethod=TStringMatchMethod::Exact) const noexcept |
int32_t | CompareExact (const char *aText, size_t aLength=npos) const noexcept |
int32_t | CompareFoldCase (const char *aText, size_t aLength=npos) const noexcept |
void | Replace (size_t aStart, size_t aEnd, const char *aText, size_t aLength=npos, int32_t aCodePage=0) |
bool | operator== (const char *aText) const noexcept |
bool | operator% (const char *aText) const noexcept |
bool | operator!= (const char *aText) const |
void | Insert (size_t aIndex, const char *aText, size_t aLength=npos, int32_t aCodePage=0) |
void | Append (const char *aText, size_t aLength=npos, int32_t aCodePage=0) |
template<typename T > | |
void | Append (const std::basic_string< T > aString) |
template<typename T > | |
void | Set (const std::basic_string< T > aString) |
void | Set (const char *aText, size_t aLength=npos) |
void | Set (const char *aText, size_t aLength, int32_t aCodePage) |
void | Replace (size_t aStart, size_t aEnd, uint16_t aChar) |
void | Insert (size_t aIndex, uint16_t aChar) |
void | Append (uint16_t aChar) |
void | Set (uint16_t aChar) |
void | Trim () |
bool | operator== (const MString &aString) const |
bool | operator== (const uint16_t *aText) const |
bool | operator== (const char16_t *aText) const |
bool | operator!= (const MString &aString) const |
bool | operator!= (const uint16_t *aText) const |
bool | operator!= (const char16_t *aText) const |
bool | operator% (const MString &aString) const |
bool | operator% (const uint16_t *aText) const |
bool | WildMatch (const MString &aWildText) const noexcept |
bool | WildMatch (const char *aWildText) const noexcept |
bool | LayerMatch (const MString &aWildText) const |
bool | LayerMatch (const char *aWildText) const noexcept |
template<class T > | |
bool | operator< (const T &aOther) const |
template<class T > | |
bool | operator<= (const T &aOther) const |
template<class T > | |
bool | operator> (const T &aOther) const |
template<class T > | |
bool | operator>= (const T &aOther) const |
int32_t | ToInt32 (size_t *aLengthUsed=nullptr, int32_t aBase=10) const noexcept |
int64_t | ToInt64 (size_t *aLengthUsed=nullptr, int32_t aBase=10) const noexcept |
uint32_t | ToUint32 (size_t *aLengthUsed=nullptr, int32_t aBase=10) const noexcept |
double | ToDouble (size_t *aLengthUsed=nullptr) const noexcept |
double | ToDimension (size_t *aLengthUsed=nullptr) const noexcept |
void | Shape (TBidiParDir aParDir, CBidiEngine *aBidiEngine, bool aParStart, bool aReorderFontSelectors) |
void | Abbreviate (const CAbbreviationDictionary &aDictionary) |
void | Transliterate (const CStringTypeDictionary *aTitleCaseDictionary=nullptr, const char *aLocale=nullptr) |
bool | IsLineBreak (size_t aPos) const noexcept |
size_t | LineBreakBefore (size_t aPos) const noexcept |
size_t | LineBreakAfter (size_t aPos) const noexcept |
void | SetAttribute (const MString &aKey, const MString &aValue) |
void | SetAttribute (const CString &aKey, const CString &aValue) |
TText | GetAttribute (const MString &aKey) const noexcept |
TText | GetAttribute (const CString &aKey) const noexcept |
bool | NextAttribute (size_t &aPos, TText &aKey, TText &aValue) const noexcept |
Static Public Member Functions | |
static int32_t | Compare (MIter< int32_t > &aIter1, MIter< int32_t > &aIter2, TStringMatchMethod aStringMatchMethod) noexcept |
static bool | FuzzyMatch (MIter< int32_t > &aIter1, MIter< int32_t > &aIter2, int32_t aMaxDistance) noexcept |
static bool | FuzzyMatch (const char *aText1, const char *aText2, int32_t aMaxDistance) noexcept |
static int32_t | ToInt32 (const uint8_t *aText, size_t aLength, size_t *aLengthUsed=nullptr, int32_t aBase=10) noexcept |
Static Public Attributes | |
static constexpr int | KMaxFuzzyDistance = 4 |
Protected Member Functions | |
MString () | |
MString (size_t aLength) | |
Protected Attributes | |
size_t | iLength |
The string interface class. All strings implement this interface. The private part of the interface allows completely general compare, append, insert, delete and replace functions to be implemented in MString.
Although the M prefix of MString implies that this class is a pure mix-in with no data, it has one data item, the length, which was moved to the base class for efficiency reasons after profiling indicated a bottleneck accessing the various virtual Length functions of derived classes.
|
inlinevirtual |
A virtual destructor. Provided so that templated collection classes can be created using MString as the template class, while still being able to own the strings.
|
inlineprotected |
Constructs the MString base class part of a string and gives it zero length.
|
inlineprotected |
Constructs the MString base class part of a string and gives it a specified length.
void CartoType::MString::Abbreviate | ( | const CAbbreviationDictionary & | aDictionary | ) |
Abbreviate a string by replacing words according to the entries in aDictionary. Replacements are made only if the abbreviation is shorter than the original word.
|
inline |
Appends the eight-bit string aText. If aLength is npos the text must be null-terminated, otherwise the length is aLength. A code page of 0 (the default) implies UTF-8.
|
inline |
Appends aString.
|
inline |
Appends a standard string.
|
inline |
Appends aText. If aLength is npos the text must be null-terminated, otherwise the length is aLength.
|
inline |
Appends aChar.
void CartoType::MString::AppendCommaSeparated | ( | const CString & | aLabel, |
const CString & | aText, | ||
size_t & | aItems, | ||
size_t | aMaxItems = SIZE_MAX |
||
) |
Append aText, prefixing it with a comma and a space if aItems is greater than zero. and prefixing it with aLabel and an equals sign if aLabel is not empty, then increment aItems. Append the text only if aItems is less than aMaxItems.
|
inline |
Deletes all the text.
|
noexcept |
Compares two strings lexicographically.
|
inline |
Compares UTF16 text with a specified length with this string lexicographically. If aLength is npos (the default) the text is assumed to be null-terminated.
Returns 0 if the strings are equal, otherwise:
returns -2 if this string is less than aText and not a prefix of aText; returns -1 if this string is a prefix of aText; returns 1 if aText is a prefix of this string; returns 2 if aText is less than this string and not a prefix of it.
|
inline |
Compares two strings lexicographically.
Returns 0 if the strings are equal, otherwise:
returns -2 if this string is less than aString and not a prefix of aString; returns -1 if this string is a prefix of aString; returns 1 if aString is a prefix of this string; returns 2 if aString is less than this string and not a prefix of it.
|
noexcept |
Compares two strings lexicographically using a specified string match method.
Returns 0 if the strings are equal, or TStringMatchMethodFlag::Prefix is set and aString is a prefix of this string; otherwise:
returns -2 if this string is less than aString and not a prefix of aString; returns -1 if this string is a prefix of aString; returns 1 if aString is a prefix of this string; returns 2 if aString is less than this string and not a prefix of it.
|
inline |
Compares null-terminated UTF16 text with this string lexicographically.
Returns 0 if the strings are equal, otherwise:
returns -2 if this string is less than aText and not a prefix of aText; returns -1 if this string is a prefix of aText; returns 1 if aText is a prefix of this string; returns 2 if aText is less than this string and not a prefix of it.
|
inline |
Compares UTF16 text with a specified length with this string lexicographically. If aLength is npos the text is assumed to be null-terminated.
Returns 0 if the strings are equal, otherwise:
returns -2 if this string is less than aText and not a prefix of aText; returns -1 if this string is a prefix of aText; returns 1 if aText is a prefix of this string; returns 2 if aText is less than this string and not a prefix of it.
|
noexcept |
Compares two strings lexicographically.
|
noexcept |
Compares two strings lexicographically.
|
staticnoexcept |
A static function to compare two strings taken from iterators lexicographically using a specified string matching method.
If the method includes the flag TStringMatchMethodFlag::Prefix, excess characters in aIter1 are ignored after all the characters of aIter2 have been used: the test is whether aIter2 is a prefix of, or equal to, aIter1.
Return 0 if the strings are equal, or TStringMatchMethodFlag::Prefix is set and aIter2 is a prefix of aIter1; otherwise:
-2 if aIter1 is less than aIter2 and not a prefix of aIter2, -1 if aIter1 is a prefix of aIter2, 1 if aIter2 is a prefix of aIter1, 2 if aIter2 is less than aIter1 and not a prefix of it
but if fuzzy matching is used, the values 0 (equal) and 1 (unequal) only are returned.
The Next functions of the iterators must be guaranteed to either return no error or KErrorEndOfData.
|
noexcept |
Compares two strings lexicographically, ignoring differences in letter case.
|
noexcept |
Compares two strings lexicographically, ignoring differences in letter case.
std::basic_string< uint16_t > CartoType::MString::CreateUtf16String | ( | ) | const |
Create a UTF-16 copy of a string.
std::string CartoType::MString::CreateUtf8String | ( | ) | const |
Create a UTF8 copy of a string.
|
inline |
Deletes the text in the range aStart...aEnd.
void CartoType::MString::DeletePrefix | ( | const MString & | aPrefix | ) |
Deletes aPrefix if it occurs at the start of the string.
void CartoType::MString::DeleteSuffix | ( | const MString & | aSuffix | ) |
Deletes aSuffix if it occurs at the end of the string.
|
noexcept |
Find the first instance of aString in this string and return its start position. Return npos if not found.
If aEndPos is non-null it is used to return the end position of the found string in this string.
Strings are compared using the specified string match method, ignoring TStringMatchMethodFlag::Prefix, which is not relevant.
The returned start and end positions are maximal if non-alphanumeric characters are ignored. For example, if the search is for "x" in " (x) " the positions returned are 0 and 5. Therefore if the start and end positions are 0 and the length of this string, the target matches the whole string.
TText CartoType::MString::First | ( | size_t | aLength | ) | const |
Return a TText object referring to the first aLength characters of a string, or the entire string, whichever is less.
|
staticnoexcept |
Performs a fuzzy match on the two UTF-8 strings. Returns true if the strings are equal within an edit distance of less than aMaxDistance, which cannot be greater than MString::KMaxFuzzyDistance.
|
staticnoexcept |
Performs a fuzzy match on the strings provided by the two iterators. Returns true if the strings are equal within an edit distance of less than aMaxDistance, which cannot be greater than MString::KMaxFuzzyDistance.
An overload of GetAttribute that takes CString, and hence can take const char* and std::string.
Treating a string as a set of map object attributes of the form label|key1=value1|key2=value2| ... |keyN=valueN, where | is character code 0, get a named attribute. An empty name refers to the label. If the return value is empty the attribute does not exist in the string.
|
inline |
Inserts the eight-bit string aText at aIndex. If aLength is -1 the text must be null-terminated, otherwise the length is aLength. A code page of 0 (the default) implies UTF-8.
|
inline |
Inserts aString at aIndex.
|
inline |
Inserts aText at aIndex. If aLength is npos the text must be null-terminated, otherwise the length is aLength.
|
inline |
Inserts aChar at aIndex.
|
inline |
Returns true if the text is empty.
|
noexcept |
Determine whether a position in a string is a possible line break. Positions at or before the start of the string return false. Positions after the end of the string return false. The end of the string returns true if the string is not empty.
This function does not yet implement the Unicode Standard for line breaking. It breaks lines before spaces, after hyphens, line feeds, line breaks and paragraph breaks, and between ideographic characters.
TText CartoType::MString::Last | ( | size_t | aLength | ) | const |
Return a TText object referring to the last aLength characters of a string, or the entire string, whichever is less.
|
noexcept |
A special wild-card matching function for map layers with a structure like that of file paths separated by '/' characters. A final '/' matches both the string without '/', and the string with '*' appended. So the pattern 'road/' matches 'road' and 'road/major' but not 'road2' or 'road/'.
bool CartoType::MString::LayerMatch | ( | const MString & | aWildText | ) | const |
A special wild-card matching function for map layers with a structure like that of file paths separated by '/' characters. A final '/' matches both the string without '/', and the string with '*' appended. So the pattern 'road/' matches 'road' and 'road/major' but not 'road2' or 'road/'.
|
inline |
Returns the length of the text.
|
noexcept |
Find the first line break at or after the specified position. Return npos if no break is found, which happens only if aPos is after the end of the text.
|
noexcept |
Find the first line break at or before the specified position. Return npos if no break is found.
|
noexcept |
Treating a string as a set of map object attributes of the form label|key1=value1|key2=value2| ... |keyN=valueN, where | is character code 0, get the next key-value pair, updating aPos.
To use this function call it with aPos=0, then keep calling it till it returns false, meaning that no key-value pair has been found.
The first key-value pair returned always has an empty key, the value being the label.
|
inline |
A conversion operator to convert a string to a UTF-8 string.
|
inline |
The inequality operator for comparing MString objects with null-terminated UTF8 strings
|
inline |
The inequality operator for comparing MString objects with null-terminated UTF16 strings
|
inline |
The inequality operator.
|
inline |
The inequality operator for comparing MString objects with null-terminated UTF16 strings
|
noexcept |
The equality operator, ignoring case, for comparing MString objects with null-terminated UTF8 strings. The % operator was chosen so that its precedence was not lower than ==, so that
"if (condition || string1 % string2)"
has the same order of evaluation as
"if (condition || string1 == string2)."
Use with care nevertheless.
|
inline |
The equality operator, ignoring case.
|
inline |
The equality operator, ignoring case, for comparing MString objects with null-terminated UTF16 strings
|
inline |
Appends aText to this string.
|
inline |
The less-than operator.
|
inline |
The less-than-or-equals operator.
|
inline |
The assignment operator.
|
noexcept |
The equality operator for comparing MString objects with null-terminated UTF8 strings
|
inline |
The equality operator for comparing MString objects with null-terminated UTF16 strings.
|
inline |
The equality operator.
|
inline |
The equality operator for comparing MString objects with null-terminated UTF16 strings.
|
inline |
The greater-than operator.
|
inline |
The greater-than-or-equals operator.
|
inline |
Gets the character at the position aIndex.
void CartoType::MString::Replace | ( | size_t | aStart, |
size_t | aEnd, | ||
const char * | aText, | ||
size_t | aLength = npos , |
||
int32_t | aCodePage = 0 |
||
) |
Replace the text from aStart to aEnd with the 8-bit text starting at aText. If aLength is npos aText must point to null-terminated text. If aCodePage is zero the text is UTF-8, otherwise it is in the specified Windows code page.
|
inline |
Replaces the text aStart...aEnd with aString.
void CartoType::MString::Replace | ( | size_t | aStart, |
size_t | aEnd, | ||
const uint16_t * | aText, | ||
size_t | aLength = npos |
||
) |
Replace the text from aStart to aEnd with the UTF16 text starting at aText. If aLength is npos aText must point to null-terminated text.
TResult CartoType::MString::Replace | ( | size_t | aStart, |
size_t | aEnd, | ||
MIter< int32_t > & | aText, | ||
size_t | aMaxLength | ||
) |
Replace the text from aStart to aEnd with a maximum of aMaxLength UTF32 characters from aText, or up to the end of the data, whichever comes first.
|
inline |
Replaces the range aStart...aEnd with the single character aChar.
|
inline |
Sets the string to the eight-bit string aText. If aLength is -1 the text must be null-terminated, otherwise the length is aLength. A code page of 0 implies UTF-8.
void CartoType::MString::Set | ( | const char * | aText, |
size_t | aLength = npos |
||
) |
Sets the string to the UTF-8 string aText. If aLength is npos the text must be null-terminated, otherwise the length is aLength.
|
inline |
Sets the string to aString.
|
inline |
Sets the text to a standard string.
|
inline |
Sets the string to aText. If aLength is npos the text must be null-terminated, otherwise the length is aLength.
|
inline |
Sets the entire text to aChar.
An overload of SetAttribute that takes CString arguments, and hence can take const char* and std::string.
Treating a string as a set of map object attributes of the form label|key1=value1|key2=value2| ... |keyN=valueN, where | is character code 0, set a named attribute. An empty or zero-length key sets the label. An empty value deletes a key-value pair.
void CartoType::MString::SetCase | ( | TLetterCase | aCase, |
const CStringTypeDictionary * | aTitleCaseDictionary = 0 |
||
) |
Set the case of all the tokens in the string in the specified way. If aCase is TLetterCase::Title the optional word case dictionary specifies words like 'of', 'in', 'US', 'IV', etc., that require special treatment.
|
inline |
Sets the length of the string to zero without discarding reserved memory if any.
void CartoType::MString::SetSentenceCase | ( | ) |
Convert the string into sentence case: that is, set the first letter to title case unless it is already a capital or title case, or has no case.
void CartoType::MString::Shape | ( | TBidiParDir | aParDir, |
CBidiEngine * | aBidiEngine, | ||
bool | aParStart, | ||
bool | aReorderFontSelectors | ||
) |
Perform shaping; that is, convert a string to its presentation form by performing bidirectional reordering, so that text in Arabic, Hebrew and other right-to-left languages is ordered correctly; converting directional right-to-left characters with mirror equivalents to their mirror images; and performing contextual shaping for Arabic.
If aBidiEngine is non-null, use the supplied bidirectional engine to provide the current state, and start a new paragraph if aParStart is true. If not, always start a new paragraph.
If aReorderFontSelectors is true, reorder any embedded font selector characters to preserve the original fonts.
|
pure virtual |
Returns a constant pointer to Unicode text stored in UTF16 format.
Implemented in CartoType::TWritableText, CartoType::TTextBuffer< aMaxLength >, CartoType::TText, and CartoType::CString.
|
noexcept |
Converts the string to a floating point dimension; meters are assumed, but ' and " can be used for feet and inches, or ft, in, km, mi, nmi (nautical miles). For OSM dimension attributes.
|
noexcept |
Convert the string to a floating point value and optionally return the length of the text used for the conversion. Return 0 if no conversion can be done.
|
staticnoexcept |
Converts 8-bit text to an integer value and returns the length of the text used for the conversion. The optional argument aBase, which has the default value 10, allows bases from 2 to 16 to be used.
|
noexcept |
Convert the string to a 32-bit integer value and optionally return the length of the text used for the conversion. The optional argument aBase, which has the default value 10, allows bases from 2 to 16 to be used.
|
noexcept |
Convert the string to a 64-bit integer and optionally return the length of the text used for the conversion. The optional argument aBase, which has the default value 10, allows bases from 2 to 16 to be used.
|
noexcept |
Convert the string to an unsigned 32-bit integer and optionally return the length of the text used for the conversion. The optional argument aBase, which has the default value 10, allows bases from 2 to 16 to be used.
void CartoType::MString::Transliterate | ( | const CStringTypeDictionary * | aTitleCaseDictionary = nullptr , |
const char * | aLocale = nullptr |
||
) |
Transliterate a string from a non-Latin script to the Latin script. Transliteration is performed only if all letters in non-Latin scripts are transliteratable.
If transliteration is impossible or unsupported the error KErrorUntransliterable is returned.
void CartoType::MString::Trim | ( | ) |
Strips ASCII whitespace from the start and end of the string, but preserves any private-use characters used as font selectors, etc., even if they are outside leading or trailing whitespace.
|
noexcept |
Return true if this string matches aWildText, which may contain the wild-card characters '?', meaning any character, and '*', meaning any sequence of zero or more characters.
|
noexcept |
Return true if this string matches aWildText, which may contain the wild-card characters '?', meaning any character, and '*', meaning any sequence of zero or more characters.
|
protected |
The length of the text in 16-bit UTF16 values.
|
staticconstexpr |
Maximum edit distance allowed by fuzzy matching: the maximum value for aMaxDistance in MString::FuzzyMatch().