00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _SUPPORT_STRING_H
00038 #define _SUPPORT_STRING_H
00039
00040 #include <string>
00041
00042 namespace alp {
00043
00044 class string : public std::string
00045 {
00046 public:
00047 string(const std::string& _other) : std::string(_other), utf8(*this) { ; }
00048 string(const char* _other, size_type _pos = 0, size_type _n = npos) : std::string(NULL == _other ? "" : _other, _pos, _n), utf8(*this) { ; }
00049 string(const char* _other, size_t _length) : std::string(NULL == _other ? "" : _other, _length), utf8(*this) { ; }
00050 string(const string& _other) : std::string(_other.c_str()), utf8(*this) { ; }
00051 string() : utf8(*this) { ; }
00052
00053 string& operator<<(const string& _other);
00054 string& operator<<(const char* _other);
00055 string& operator<<(uint32_t _val);
00056 string& operator<<(int32_t _val);
00057 string& operator<<(int64_t _val);
00058 string& operator<<(uint64_t _val);
00059 string& operator=(const string& _other) { std::string::operator=(_other); return *this; }
00060
00061 public:
00062 class utf8_impl
00063 {
00064 public:
00065 utf8_impl(alp::string& _self) : fSelf(_self) { }
00066
00067 size_t length() const;
00068
00069 private:
00070 alp::string& fSelf;
00071 };
00072
00073 public:
00074 utf8_impl utf8;
00075 };
00076
00077
00078 inline size_t
00079 utf8_char_len(uint8_t ch)
00080 {
00081 return ((0xe5000000 >> ((ch >> 3) & 0x1e)) & 3) + 1;
00082 }
00083
00084
00085 inline uint32_t
00086 utf8_char_to_uint32(const uint8_t *src, uint32_t length)
00087 {
00088 uint32_t result = 0;
00089
00090 for (uint32_t index = 0; index < length; index++)
00091 result |= src[index] << (24 - index * 8);
00092
00093 return result;
00094 }
00095
00096
00097
00102 size_t uint32_to_utf8(uint32_t _source, uint8_t* _result);
00103
00104
00105 }
00106
00107 std::string& operator<<(std::string& _lhs, const std::string& _other);
00108 std::string& operator<<(std::string& _lhs, const char* _other);
00109 std::string& operator<<(std::string& _lhs, uint32_t _val);
00110 std::string& operator<<(std::string& _lhs, int32_t _val);
00111
00112
00113 #endif