123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- #ifndef __cocos2dx__ccUTF8__
- #define __cocos2dx__ccUTF8__
- #include "platform/CCPlatformMacros.h"
- #include <vector>
- #include <string>
- #include <sstream>
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
- #include "platform/android/jni/JniHelper.h"
- #endif
- NS_CC_BEGIN
- namespace StringUtils {
- template<typename T>
- std::string toString(T arg)
- {
- std::stringstream ss;
- ss << arg;
- return ss.str();
- }
- std::string CC_DLL format(const char* format, ...) CC_FORMAT_PRINTF(1, 2);
- CC_DLL bool UTF8ToUTF16(const std::string& inUtf8, std::u16string& outUtf16);
- CC_DLL bool UTF8ToUTF32(const std::string& inUtf8, std::u32string& outUtf32);
- CC_DLL bool UTF16ToUTF8(const std::u16string& inUtf16, std::string& outUtf8);
-
- CC_DLL bool UTF16ToUTF32(const std::u16string& inUtf16, std::u32string& outUtf32);
- CC_DLL bool UTF32ToUTF8(const std::u32string& inUtf32, std::string& outUtf8);
-
- CC_DLL bool UTF32ToUTF16(const std::u32string& inUtf32, std::u16string& outUtf16);
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
- CC_DLL std::string getStringUTFCharsJNI(JNIEnv* env, jstring srcjStr, bool* ret = nullptr);
- CC_DLL jstring newStringUTFJNI(JNIEnv* env, const std::string& utf8Str, bool* ret = nullptr);
- #endif
- CC_DLL void trimUTF16Vector(std::vector<char16_t>& str);
-
- CC_DLL void trimUTF32Vector(std::vector<char32_t>& str);
- CC_DLL bool isUnicodeSpace(char32_t ch);
- CC_DLL bool isCJKUnicode(char32_t ch);
- CC_DLL long getCharacterCountInUTF8String(const std::string& utf8);
- CC_DLL unsigned int getIndexOfLastNotChar16(const std::vector<char16_t>& str, char16_t c);
- CC_DLL std::vector<char16_t> getChar16VectorFromUTF16String(const std::u16string& utf16);
- class CC_DLL StringUTF8
- {
- public:
- struct CharUTF8
- {
- std::string _char;
- bool isAnsi() { return _char.size() == 1; }
- };
- typedef std::vector<CharUTF8> CharUTF8Store;
- StringUTF8();
- StringUTF8(const std::string& newStr);
- ~StringUTF8();
- std::size_t length() const;
- void replace(const std::string& newStr);
- std::string getAsCharSequence() const;
- bool deleteChar(std::size_t pos);
- bool insert(std::size_t pos, const std::string& insertStr);
- bool insert(std::size_t pos, const StringUTF8& insertStr);
- CharUTF8Store& getString() { return _str; }
- private:
- CharUTF8Store _str;
- };
- }
- CC_DEPRECATED_ATTRIBUTE CC_DLL int cc_wcslen(const unsigned short* str);
- CC_DEPRECATED_ATTRIBUTE CC_DLL void cc_utf8_trim_ws(std::vector<unsigned short>* str);
- CC_DEPRECATED_ATTRIBUTE CC_DLL bool isspace_unicode(unsigned short ch);
- CC_DEPRECATED_ATTRIBUTE CC_DLL bool iscjk_unicode(unsigned short ch);
- CC_DEPRECATED_ATTRIBUTE CC_DLL long cc_utf8_strlen (const char * p, int max = -1);
- CC_DEPRECATED_ATTRIBUTE CC_DLL unsigned int cc_utf8_find_last_not_char(const std::vector<unsigned short>& str, unsigned short c);
- CC_DEPRECATED_ATTRIBUTE CC_DLL std::vector<unsigned short> cc_utf16_vec_from_utf16_str(const unsigned short* str);
- CC_DEPRECATED_ATTRIBUTE CC_DLL unsigned short* cc_utf8_to_utf16(const char* str_old, int length = -1, int* rUtf16Size = nullptr);
- CC_DEPRECATED_ATTRIBUTE CC_DLL char * cc_utf16_to_utf8 (const unsigned short *str,
- int len = -1,
- long *items_read = nullptr,
- long *items_written = nullptr);
- NS_CC_END
- #endif
|