cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cocos2d::StringUtils Namespace Reference

Functions

CC_DLL bool UTF8ToUTF16 (const std::string &utf8, std::u16string &outUtf16)
 Converts utf8 string to utf16 string. More...
 
CC_DLL bool UTF16ToUTF8 (const std::u16string &utf16, std::string &outUtf8)
 Converts utf16 string to utf8 string. More...
 
CC_DLL void trimUTF16Vector (std::vector< char16_t > &str)
 Trims the unicode spaces at the end of char16_t vector. More...
 
CC_DLL bool isUnicodeSpace (char16_t ch)
 Whether the character is a whitespace character. More...
 
CC_DLL bool isCJKUnicode (char16_t ch)
 Whether the character is a Chinese/Japanese/Korean character. More...
 
CC_DLL long getCharacterCountInUTF8String (const std::string &utf8)
 Returns the length of the string in characters. More...
 
CC_DLL unsigned int getIndexOfLastNotChar16 (const std::vector< char16_t > &str, char16_t c)
 Gets the index of the last character that is not equal to the character given. More...
 
CC_DLL std::vector< char16_t > getChar16VectorFromUTF16String (const std::u16string &utf16)
 Gets char16_t vector from a given utf16 string. More...
 
template<typename T >
std::string toString (T arg)
 
std::string CC_DLL format (const char *format,...) CC_FORMAT_PRINTF(1
 

Function Documentation

std::string CC_DLL cocos2d::StringUtils::format ( const char *  format,
  ... 
)
CC_DLL std::vector<char16_t> cocos2d::StringUtils::getChar16VectorFromUTF16String ( const std::u16string &  utf16)

Gets char16_t vector from a given utf16 string.

CC_DLL long cocos2d::StringUtils::getCharacterCountInUTF8String ( const std::string &  utf8)

Returns the length of the string in characters.

Parameters
utf8an UTF-8 encoded string.
Returns
the length of the string in characters
CC_DLL unsigned int cocos2d::StringUtils::getIndexOfLastNotChar16 ( const std::vector< char16_t > &  str,
char16_t  c 
)

Gets the index of the last character that is not equal to the character given.

Parameters
strthe string to be searched.
cthe character to be searched for.
Returns
the index of the last character that is not c.
CC_DLL bool cocos2d::StringUtils::isCJKUnicode ( char16_t  ch)

Whether the character is a Chinese/Japanese/Korean character.

Parameters
chthe unicode character
Returns
whether the character is a Chinese character.
See also
http://www.searchtb.com/2012/04/chinese_encode.html
http://tieba.baidu.com/p/748765987
CC_DLL bool cocos2d::StringUtils::isUnicodeSpace ( char16_t  ch)

Whether the character is a whitespace character.

Parameters
chthe unicode character
Returns
whether the character is a white space character.
See also
http://en.wikipedia.org/wiki/Whitespace_character#Unicode
std::string cocos2d::StringUtils::toString ( arg)
CC_DLL void cocos2d::StringUtils::trimUTF16Vector ( std::vector< char16_t > &  str)

Trims the unicode spaces at the end of char16_t vector.

CC_DLL bool cocos2d::StringUtils::UTF16ToUTF8 ( const std::u16string &  utf16,
std::string &  outUtf8 
)

Converts utf16 string to utf8 string.

Parameters
utf16The utf16 string to be converted
outUtf8The output utf8 string
Returns
true if succeed, otherwise false
Note
Please check the return value before using outUtf8 e.g.
std::string utf8;
bool ret = StringUtils::UTF16ToUTF8(u"\u4f60\u597d", utf16);
if (ret) {
do_some_thing_with_utf8(utf8);
}
CC_DLL bool cocos2d::StringUtils::UTF8ToUTF16 ( const std::string &  utf8,
std::u16string &  outUtf16 
)

Converts utf8 string to utf16 string.

Parameters
utf8The utf8 string to be converted
outUtf16The output utf16 string
Returns
true if succeed, otherwise false
Note
Please check the return value before using outUtf16 e.g.
std::u16string utf16;
bool ret = StringUtils::UTF8ToUTF16("你好hello", utf16);
if (ret) {
do_some_thing_with_utf16(utf16);
}