My Project
|
string manipulation helpers for ParaEngine More...
#include <StringHelper.h>
Static Public Member Functions | |
static bool | UTF8ToUTF16 (const std::string &utf8, std::u16string &outUtf16) |
Converts utf8 string to utf16 string. More... | |
static bool | UTF8ToUTF16_Safe (const std::string &utf8, std::u16string &outUtf16) |
similar to UTF8ToUTF16. More... | |
static void | TrimUTF16VectorFromIndex (std::vector< char16_t > &str, int index) |
static bool | IsUnicodeSpace (char16_t ch) |
static bool | IsCJKUnicode (char16_t ch) |
static void | TrimUTF16Vector (std::vector< char16_t > &str) |
static unsigned int | GetIndexOfLastNotChar16 (const std::vector< char16_t > &str, char16_t c) |
static bool | UTF16ToUTF8 (const std::u16string &utf16, std::string &outUtf8) |
Converts utf16 string to utf8 string. More... | |
static const WCHAR * | MultiByteToWideChar (const char *name, unsigned int nCodePage=0, size_t *outLen=nullptr) |
static const char * | WideCharToMultiByte (const WCHAR *name, unsigned int nCodePage=0, size_t *outLen=nullptr) |
static int | WideCharToMultiByte (const WCHAR *name, char *szText, int nLength, unsigned int nCodePage=0) |
get the text of the control More... | |
static const WCHAR * | AnsiToWideChar (const char *name) |
static const char * | WideCharToAnsi (const WCHAR *name) |
static const char * | UTF8ToAnsi (const char *name) |
static const char * | AnsiToUTF8 (const char *name) |
static int | GetUnicodeCharNum (const char *str) |
get the number of characters in str. More... | |
static string | UniSubString (const char *str, int nFrom, int nTo) |
same as LUA string.sub(), except that the index is character. More... | |
static string | SimpleEncode (const string &source) |
encode a string using really simple algorithm. More... | |
static string | SimpleDecode (const string &source) |
decode a string using really simple algorithm. More... | |
static const std::string & | EncodingConvert (const std::string &srcEncoding, const std::string &dstEncoding, const std::string &bytes) |
Converts an entire byte array from one encoding to another. More... | |
static bool | CopyTextToClipboard (const string &text) |
copy text to clipboard. More... | |
static const char * | GetTextFromClipboard () |
get text from clipboard. More... | |
static void | DevideString (const string &input, string &str1, string &str2, char separator=';') |
divide string | |
static void | split (const std::string &src, const std::string &token, std::vector< std::string > &vect) |
splite string by token | |
static void | make_lower (string &str) |
Makes the string lower case. | |
static void | make_upper (string &str) |
Makes the string upper case. | |
static bool | checkValidXMLChars (const std::string &data) |
Checks whether the given input is valid UTF-8. More... | |
static bool | removeInValidXMLChars (std::string &data) |
remove invalid characters in the given input. More... | |
static bool | IsNumber (const char *str) |
static bool | IsLetter (const char *str) |
static int | StrToInt (const char *str) |
static double | StrToFloat (const char *str) |
static bool | RegularMatch (const char *input, const char *expression) |
static std::string | ToCString (const char *input) |
static std::string | StrReplace (const char *inputstring, char srcchar, char destchar) |
static RECT * | GetImageAndRect (const std::string &str, std::string &imagefile, RECT *pOut=NULL) |
static std::string | md5 (const std::string &source, bool bBinary=false) |
convert the md5 of the input source string. More... | |
static std::string | sha1 (const std::string &source, bool bBinary=false) |
static std::string | base64 (const std::string &source) |
convert the base64 of the input source string. More... | |
static std::string | unbase64 (const std::string &source) |
return unbase64 of the input source string. More... | |
static void | fast_sprintf (char *s, const char *fmt,...) |
a fast printf function that support limited functions. More... | |
static void | fast_snprintf (char *s, int nMaxCount, const char *fmt,...) |
e.g. More... | |
static int | fast_itoa (int64 value, char *result, int buf_size, int base=10) |
fast itoa modified from http://code.google.com/p/maxmods/ More... | |
static int | fast_dtoa (double num, char *str, int nBuffSize=40, int max_decimal=5, int radix=10) |
doing a fast (may not be accurate) double to string conversion. More... | |
static bool | MatchWildcard (const std::string &str, const std::string &sWildcardPattern) |
check if the input string matches the wild card pattern More... | |
static bool | StrEndsWith (const string &str, const string &sequence) |
check whether str ends with sequence More... | |
string manipulation helpers for ParaEngine
|
static |
convert the base64 of the input source string.
|
static |
Checks whether the given input is valid UTF-8.
data | The data to check for validity. |
|
static |
copy text to clipboard.
Input is GUI UTF8 encoding
|
static |
Converts an entire byte array from one encoding to another.
srcEncoding | any encoding name. If nil or "", it is the default coding in NPL. see Encoding.GetEncoding(). Below are some commonly used field | Code Page | Name | | 950 | big5 | | 936 | gb2312 | | 65001 | utf-8 | | 65005 | utf-32 | There is one special code name called "HTML", which contains HTML special characters in ascii code page. This is usually true for most "iso8859-15" encoding in western worlds. It just writes the unicode number+XXXX in ascii character "&#XXXX;" where & is optional. |
dstEncoding | save as above. If nil or "", it will be converted to default coding in NPL. : the source bytes. e.g. The most common use of this function is to create HTML special character to NPL string, like below local text = ParaMisc.EncodingConvert("HTML", "", "Chinese characters: 开发") log(text); |
|
static |
doing a fast (may not be accurate) double to string conversion.
by Xizhi, 2010.11.17 use fast_itoa to compute fast_dtoa.
it is similar to "%.xxf", except that it will remove all trailing zero, and ensures that nBuffSize is not exceed for out of range numbers, etc.
num | Value to be converted to a string. NaN, +Inf,-Inf will generate "0" |
str | output string, array in memory where to store the resulting null-terminated string. |
nBuffSize | the output buff size. |
max_decimal | max number of numbers after the decimal point. It will remove trailing '0' |
radix | the radix. |
Please note accuracy is not guaranteed. I.e.0 0.999 may be rounded to 1 current only base 10 is supported.
|
static |
fast itoa modified from http://code.google.com/p/maxmods/
value | the value to be converted. |
result | the array to hold the result. |
buf_size | the result buffer size. |
base | can only be [2,16] |
|
static |
e.g.
fast_snprintf(line, MAX_LINE, "%f ok", 10.f);
|
static |
a fast printf function that support limited functions.
The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X' 'f'. Zero padding and field width are also supported. One very important feature is that f behaves like d if float is integer
|
static |
get text from clipboard.
text is converted to ANSI code page when returned.
|
static |
get the number of characters in str.
Str is assumed to be in ANSI code page. it is converted to Unicode and return the character count.
|
static |
check if the input string matches the wild card pattern
sWildcardPattern | such as "*.*" or "*" or "main_*.pkg", etc. |
|
static |
convert the md5 of the input source string.
bBinary | if false (default), result is 32 hex number chars. if true, result is 16 bytes binary string. |
|
static |
remove invalid characters in the given input.
data | The data to check for validity. |
|
static |
decode a string using really simple algorithm.
str = SimpleDecode(SimpleEncode(str))
|
static |
encode a string using really simple algorithm.
it just makes the source ineligible. It is still not immune to crackers. str = SimpleDecode(SimpleEncode(str))
|
static |
check whether str ends with sequence
sequence | it may contain ?, which matches to 1 any character. |
|
static |
return unbase64 of the input source string.
|
static |
same as LUA string.sub(), except that the index is character.
get a sub string of a ANSI Code page string. However, the index are unicode characters.
str | the string to use |
nFrom | character index beginning from 1. |
|
static |
Converts utf16 string to utf8 string.
utf16 | The utf16 string to be converted |
outUtf8 | The output utf8 string |
outUtf8
e.g.
|
static |
Converts utf8 string to utf16 string.
utf8 | The utf8 string to be converted |
outUtf16 | The output utf16 string |
outUtf16
e.g.
|
static |
similar to UTF8ToUTF16.
except that if UTF8ToUTF16 returns false, it will replace invalid utf8 character with ?. and then return the converted string.
|
static |
get the text of the control
szText | [out] buffer to receive the text |
nLength | size of the input buffer |