API for working with strings.
Modules | |
| String array | |
| String array implementation. | |
Classes | |
| class | Common::String |
Macros | |
| #define | tag2str(x) Common::tag2string(x).c_str() |
| #define | tag2strP(x) Common::tag2string(x, true).c_str() |
Functions | |
| String | Common::operator+ (const String &x, const String &y) |
| String | Common::operator+ (const char *x, const String &y) |
| String | Common::operator+ (const String &x, const char *y) |
| String | Common::operator+ (const String &x, char y) |
| String | Common::operator+ (char x, const String &y) |
| bool | Common::operator== (const char *x, const String &y) |
| bool | Common::operator!= (const char *x, const String &y) |
| char * | Common::ltrim (char *t) |
| char * | Common::rtrim (char *t) |
| char * | Common::trim (char *t) |
| String | Common::lastPathComponent (const String &path, const char sep) |
| String | Common::firstPathComponents (const String &path, const char sep) |
| String | Common::normalizePath (const String &path, const char sep) |
| bool | Common::matchString (const char *str, const char *pat, bool ignoreCase=false, const char *wildcardExclusions=NULL) |
| void | Common::replace (Common::String &source, const Common::String &what, const Common::String &with) |
| String | Common::tag2string (uint32 tag, bool nonPrintable=false) |
| void | Common::strcpy_s (char *dst, size_t size, const char *src) |
| template<typename T , size_t N> | |
| FORCEINLINE void | Common::strcpy_s (T(&dst)[N], const char *src) |
| void | Common::strcat_s (char *dst, size_t size, const char *src) |
| template<typename T , size_t N> | |
| FORCEINLINE void | Common::strcat_s (T(&dst)[N], const char *src) |
| int | Common::vsprintf_s (char *dst, size_t size, const char *format, va_list ap) GCC_PRINTF(3 |
| template<typename T , size_t N> | |
| int FORCEINLINE | Common::GCC_PRINTF (2, 0) int vsprintf_s(T(&dst)[N] |
| return | Common::vsprintf_s ((char *) dst, N, format, ap) |
| int | Common::sprintf_s (char *dst, size_t size, MSVC_PRINTF const char *format,...) GCC_PRINTF(3 |
| template<typename T , size_t N> | |
| int | Common::GCC_PRINTF (2, 3) int sprintf_s(T(&dst)[N] |
| Common::va_start (ap, format) | |
| Common::va_end (ap) | |
| size_t | Common::strlcpy (char *dst, const char *src, size_t size) |
| size_t | Common::strlcat (char *dst, const char *src, size_t size) |
| size_t | Common::strnlen (const char *src, size_t maxSize) |
| String | Common::toPrintable (const String &src, bool keepNewLines=true) |
| String | Common::percentEncodeString (const String &src) |
Variables | |
| int FORCEINLINE const char * | Common::format |
| int FORCEINLINE const char va_list | Common::ap |
| int MSVC_PRINTF const char int | Common::ret |
| #define tag2str | ( | x | ) | Common::tag2string(x).c_str() |
Convenience wrapper for tag2string which "returns" a C string. Note: It is NOT safe to do anything with the return value other than directly copying or printing it.
| #define tag2strP | ( | x | ) | Common::tag2string(x, true).c_str() |
Convenience wrapper for tag2string with non-printable characters which "returns" a C string. Note: It is NOT safe to do anything with the return value other than directly copying or printing it.
Returns the last component of a given path.
Examples: /foo/bar.txt would return 'bar.txt' /foo/bar/ would return 'bar' /foo/./bar// would return 'bar'
| path | the path of which we want to know the last component |
| sep | character used to separate path components |
Returns the first components of a given path (complementary to lastPathComponent)
Examples: /foo/bar.txt would return '/foo/' /foo/bar/ would return '/foo/' /foo/./bar// would return '/foo/./'
| path | the path of which we want to know the last component |
| sep | character used to separate path components |
Normalize a given path to a canonical form. In particular:
| path | the path to normalize |
| sep | the separator token (usually '/' on Unix-style systems, or '\' on Windows based stuff) |
| bool Common::matchString | ( | const char * | str, |
| const char * | pat, | ||
| bool | ignoreCase = false, |
||
| const char * | wildcardExclusions = NULL |
||
| ) |
Simple DOS-style pattern matching function (understands * and ? like used in DOS). Taken from exult/files/listfiles.cc
Token meaning: "*": any character, any amount of times. "?": any character, only once. "#": any decimal digit, only once.
Example strings/patterns: String: monkey.s01 Pattern: monkey.s?? => true String: monkey.s101 Pattern: monkey.s?? => false String: monkey.s99 Pattern: monkey.s?1 => false String: monkey.s101 Pattern: monkey.s* => true String: monkey.s99 Pattern: monkey.s*1 => false String: monkey.s01 Pattern: monkey.s## => true String: monkey.s01 Pattern: monkey.### => false
| str | Text to be matched against the given pattern. |
| pat | Glob pattern. |
| ignoreCase | Whether to ignore the case when doing pattern match |
| wildcardExclusions | Characters which are excluded from wildcards and must be matched explicitly. |
| void Common::replace | ( | Common::String & | source, |
| const Common::String & | what, | ||
| const Common::String & | with | ||
| ) |
| String Common::tag2string | ( | uint32 | tag, |
| bool | nonPrintable = false |
||
| ) |
Take a 32 bit value and turn it into a four character string, where each of the four bytes is turned into one character. Most significant byte is printed first.
| tag | tag value to convert |
| nonPrintable | indicate if non-printable characters need to be printed as octals |
| void Common::strcpy_s | ( | char * | dst, |
| size_t | size, | ||
| const char * | src | ||
| ) |
Copy up to size - 1 characters from src to dst and also zero terminate the result. Note that src must be a zero terminated string.
| dst | The destination buffer. |
| size | The size of the destination buffer. |
| src | The source string. |
| FORCEINLINE void Common::strcpy_s | ( | T(&) | dst[N], |
| const char * | src | ||
| ) |
Copy up to N - 1 characters from src to dst and also zero terminate the result. Note that src must be a zero terminated string.
| dst | The destination buffer as a reference to a constant size array. |
| src | The source string. |
| void Common::strcat_s | ( | char * | dst, |
| size_t | size, | ||
| const char * | src | ||
| ) |
Append the string src to the string dst. Note that both src and dst must be zero terminated. The result will be zero terminated. At most "size - strlen(dst) - 1" bytes will be appended.
| dst | The string the source string should be appended to. |
| size | The (total) size of the destination buffer. |
| src | The source string. |
| FORCEINLINE void Common::strcat_s | ( | T(&) | dst[N], |
| const char * | src | ||
| ) |
Append the string src to the string dst. Note that both src and dst must be zero terminated. The result will be zero terminated. At most "N - strlen(dst) - 1" bytes will be appended.
| dst | The string the source string should be appended to as a reference to a constant size array. |
| src | The source string. |
| int Common::vsprintf_s | ( | char * | dst, |
| size_t | size, | ||
| const char * | format, | ||
| va_list | ap | ||
| ) |
A sprintf shim which warns when the buffer overruns and null terminates in this case
| dst | Where the resulting string will be stored. |
| size | The (total) size of the destination buffer. |
| format | The format string. |
| int FORCEINLINE Common::GCC_PRINTF | ( | 2 | , |
| 0 | |||
| ) | )[N] & |
A sprintf shim which warns when the buffer overruns and null terminates in this case The size of the buffer is automatically determined.
| dst | Where the resulting string will be stored. |
| format | The format string. |
| int Common::sprintf_s | ( | char * | dst, |
| size_t | size, | ||
| MSVC_PRINTF const char * | format, | ||
| ... | |||
| ) |
A sprintf shim which warns when the buffer overruns and null terminates in this case
| dst | Where the resulting string will be stored. |
| size | The (total) size of the destination buffer. |
| format | The format string. |
|
inline |
A sprintf shim which warns when the buffer overruns and null terminates in this case The size of the buffer is automatically determined.
| dst | Where the resulting string will be stored. |
| format | The format string. |
| size_t Common::strlcpy | ( | char * | dst, |
| const char * | src, | ||
| size_t | size | ||
| ) |
Copy up to size - 1 characters from src to dst and also zero terminate the result. Note that src must be a zero terminated string.
In case size is zero this function just returns the length of the source string.
| dst | The destination buffer. |
| src | The source string. |
| size | The size of the destination buffer. |
| size_t Common::strlcat | ( | char * | dst, |
| const char * | src, | ||
| size_t | size | ||
| ) |
Append the string src to the string dst. Note that both src and dst must be zero terminated. The result will be zero terminated. At most "size - strlen(dst) - 1" bytes will be appended.
In case the dst string does not contain a zero within the first "size" bytes the dst string will not be changed and size + strlen(src) is returned.
| dst | The string the source string should be appended to. |
| src | The source string. |
| size | The (total) size of the destination buffer. |
| size_t Common::strnlen | ( | const char * | src, |
| size_t | maxSize | ||
| ) |
Determine the length of a string up to a maximum of maxSize characters. This should be used instead of strlen when reading the length of a C string from potentially unsafe or corrupt sources, like game assets.
| src | The source string. |
| maxSize | The maximum size of the string. |
Converts string with all non-printable characters properly escaped with use of C++ escape sequences
| src | The source string. |
| keepNewLines | Whether keep newlines or convert them to ' ', default: true. |
Converts string with special URL characters to URL encoded (percent encoded) strings
| va_list Common::ap |
| return Common::ret |