libcdos-fw
CFString.h
1 #ifndef __CFSTRING_H__
2 #define __CFSTRING_H__
3 
4 #include <Core/CFTypes.h>
5 #include <string>
6 
7 class CFStringList;
8 
21 class CFString {
22 
23 public:
27  CFString();
28 
34  CFString(const CFChar* str);
35 
41  CFString(const CFUChar* str);
42 
47  CFString(const CFString& other);
48 
54  ~CFString();
55 
62  CFUInt clength();
63 
70  CFUInt length();
71 
79  char* toCString();
80 
88  std::string toStdString();
89 
97  CFUChar* toUtf8();
98 
105  CFStringList split(const CFString& splitStr);
106 
114  CFString sub(CFUInt pos, CFInt len);
115 
124  CFInt indexOf(CFUChar chr, int from = 0, bool caseSensitive = true);
125 
134  CFInt indexOf(const CFString& str, int from = 0, bool caseSensitive = true);
135 
141  bool isUtf8() const ;
142 
148  bool isEmpty() const;
149 
157  bool equal(const CFString& other);
158 
168  CFInt compare(const CFString& other);
169 
170  void display();
171 
172 public:
173  friend CFString operator+(const CFString& str1, const CFString& str2);
174  friend CFString operator+(const CFString& str1, const CFUChar* str2);
175  friend CFString operator+(const CFUChar* str1, const CFString& str2);
176  friend CFString operator+(const CFString& str1, const CFChar* str2);
177  friend CFString operator+(const CFChar* str1, const CFString& str2);
178  // friend CFString operator+(const CFUChar* str1, const CFUChar* str2);
179 
180  CFString& operator=(const CFString& str1);
181  CFString& operator+=(const CFString& str1);
182 
183  bool operator==(const CFString& other);
184  bool operator!=(const CFString& other);
185  bool operator>(const CFString& other);
186  bool operator>=(const CFString& other);
187  bool operator<(const CFString& other);
188  bool operator<=(const CFString& other);
189 
190 private:
191  CFUInt getUTF8length();
192  void create(const CFUChar* strdata);
193 
194  // 将字符所在位置的值转换成字符数据中的索引值.
195  // 若为纯ascii字符串,则字符所在位置与其索引值相同.
196  // 若为含有UTF-8字符的字符串,则字符所在位置比其索引值小.
197  CFUInt convertPosToIndex(CFUInt pos);
198 
199  // 将字符数据中的索引值转换成字符所在位置的值
200  // 若为纯ascii字符串,则字符所在位置与其索引值相同.
201  // 若为含有UTF-8字符的字符串,则字符所在位置比其索引值小.
202  CFInt convertIndexToPos(CFInt index);
203 
204  CFUInt dataLength(const CFUChar* strdata);
205  CFUInt wordWidth(CFUChar chr) const;
206  bool charEqual(CFUChar destChr, CFUChar srcChr, bool caseSensitive = true);
207 
208 private:
209  CFUChar* m_data;
210  CFUInt m_strLen;
211  CFUInt m_utfLen;
212 };
213 
214 #endif // __CFSTRING_H__
CFStringList split(const CFString &splitStr)
字符串分割.
CFString 字符串类.
Definition: CFString.h:21
CFInt indexOf(CFUChar chr, int from=0, bool caseSensitive=true)
字符串查找.
CFString sub(CFUInt pos, CFInt len)
字符串截取.
CFUInt length()
获取字符串长度.
CFUInt clength()
获取C字符串长度.
bool isEmpty() const
判断是否为空字符串.
CFUChar * toUtf8()
获取UTF-8编码字符串.
std::string toStdString()
获取C++标准库字符串.
结构与枚举类型定义.
bool equal(const CFString &other)
判断字符串是否与 other 字符串相同.
char * toCString()
获取C语言字符串.
CFString()
默认构造函数.
~CFString()
析构函数.
Definition: CFStringList.h:7
bool isUtf8() const
判断是否包含UTF-8编码的字符.
CFInt compare(const CFString &other)
比较字符串和 other 字符串.