28 typedef std::u16string ustring;
33 std::runtime_error(what) {}
38 static const size_t npos = -1;
39 typedef ustring::size_type size_type;
40 typedef ustring::value_type value_type;
51 unicode(
const char* encoded_string,
const std::string& encoding=
"ascii");
56 unicode(
const std::string& utf8_string,
const std::string &encoding=
"ascii");
57 unicode(
const char16_t *utf16_string);
59 template<
class InputIterator>
60 unicode(InputIterator begin, InputIterator end):
65 std::wstring::size_type length()
const {
66 return string_.size();
69 std::string encode()
const;
80 unicode substr(std::size_t pos = 0, std::size_t len = npos)
const;
91 bool contains(
const unicode& thing)
const;
92 bool contains(
const std::string& thing)
const;
93 bool contains(
const char* thing)
const;
94 bool contains(
const wchar_t ch)
const;
96 void push_back(
const wchar_t c);
99 unicode slice(int32_t beg, int32_t end)
const;
100 unicode slice(int32_t beg,
void*
null)
const;
101 unicode slice(
void*
null, int32_t end)
const;
103 bool empty()
const {
return string_.empty(); }
104 bool starts_with(
const unicode& thing)
const;
105 bool ends_with(
const unicode& thing)
const;
107 std::vector<unicode> split(
const unicode& on, int32_t count=-1,
bool keep_empty=
true)
const;
109 unicode join(
const std::vector<unicode>& parts)
const;
110 unicode join(
const std::vector<std::string>& parts)
const;
112 bool operator==(
const unicode& rhs)
const {
113 return string_ == rhs.string_;
116 bool operator!=(
const unicode& rhs)
const {
117 return !(*
this == rhs);
120 unicode& operator=(
const std::string& rhs) {
126 unicode& operator=(
const char* rhs) {
132 std::size_t find(
const char16_t c)
const {
133 return string_.find(c);
136 std::size_t find(
const unicode& what)
const {
137 return string_.find(what.string_);
140 std::size_t rfind(
const unicode& what)
const {
141 return string_.rfind(what.string_);
144 char16_t& operator[](ustring::size_type pos) {
148 const char16_t& operator[](ustring::size_type pos)
const {
153 string_.append(rhs.string_);
164 unicode operator*(
const uint32_t rhs)
const {
166 for(uint32_t i = 0; i < rhs; ++i) {
172 bool operator<(
const unicode& rhs)
const {
174 return encode() < rhs.encode();
177 ustring::iterator begin() {
return string_.begin(); }
178 ustring::iterator end() {
return string_.end(); }
179 ustring::const_iterator begin()
const {
return string_.begin(); }
180 ustring::const_iterator end()
const {
return string_.end(); }
182 ustring::reverse_iterator rbegin() {
return string_.rbegin(); }
183 ustring::reverse_iterator rend() {
return string_.rend(); }
184 ustring::const_reverse_iterator rbegin()
const {
return string_.rbegin(); }
185 ustring::const_reverse_iterator rend()
const {
return string_.rend(); }
187 uint32_t count(
const unicode& str)
const;
190 int32_t to_int()
const;
191 float to_float()
const;
192 bool to_boolean()
const;
193 ustring to_ustring()
const {
return string_; }
198 std::ostream& operator<< (std::ostream& os,
const unicode& str);
199 bool operator==(
const char* c_str,
const unicode& uni_str);
200 bool operator!=(
const char* c_str,
const unicode& uni_str);
206 size_t operator()(
const unicode& str)
const {
207 hash<ustring> make_hash;
208 return make_hash(str.to_ustring());