fastdo  0.6.16
strings.hpp
浏览该文件的文档.
1 #ifndef __STRINGS_HPP__
2 #define __STRINGS_HPP__
3 //
4 // strings 提供字符串相关的功能
5 //
6 
7 #include <stdarg.h>
8 
9 namespace winux
10 {
15 template < typename _ChTy >
16 inline static XString<_ChTy> CharSeqToString( _ChTy const * str, size_t len = npos )
17 {
18  str = str ? str : winux::Literal<_ChTy>::nulStr;
19  return (ssize_t)len < 0 ? XString<_ChTy>(str) : XString<_ChTy>( str, len );
20 }
21 
23 template < typename _RetChTy, typename _ChTy = _RetChTy >
24 inline static XString<_RetChTy> CharToHexStr( _ChTy ch, bool padZero = false )
25 {
26  _RetChTy str[sizeof(ch) * 2 + 1] = { (_RetChTy)0 };
27  byte * pbyt = (byte*)&ch;
28  ssize_t i = sizeof(ch) - 1;
29  ssize_t j = 0;
30  bool hadNonZero = padZero;
31  for ( ; i >= 0; --i )
32  {
33  if ( pbyt[i] && !hadNonZero ) hadNonZero = true;
34  if ( hadNonZero )
35  {
36  str[j * 2] = Literal<_RetChTy>::hexadecLowerStr[((pbyt[i] & (byte)0xF0) >> 4)];
37  str[j * 2 + 1] = Literal<_RetChTy>::hexadecLowerStr[(pbyt[i] & (byte)0xF)];
38  j++;
39  }
40  }
41  if ( j == 0 )
42  {
45  }
46  return str;
47 }
48 
49 
50 template < typename _ChTy >
51 size_t StrSplit( XString<_ChTy> const & str, XString<_ChTy> const & delimList, XStringArray<_ChTy> * arr, bool alwaysRetOneElem = false );
52 template <>
53 WINUX_FUNC_DECL(size_t) StrSplit( XString<char> const & str, XString<char> const & delimList, XStringArray<char> * arr, bool alwaysRetOneElem );
54 template <>
55 WINUX_FUNC_DECL(size_t) StrSplit( XString<wchar> const & str, XString<wchar> const & delimList, XStringArray<wchar> * arr, bool alwaysRetOneElem );
56 template <>
57 WINUX_FUNC_DECL(size_t) StrSplit( XString<char16> const & str, XString<char16> const & delimList, XStringArray<char16> * arr, bool alwaysRetOneElem );
58 template <>
59 WINUX_FUNC_DECL(size_t) StrSplit( XString<char32> const & str, XString<char32> const & delimList, XStringArray<char32> * arr, bool alwaysRetOneElem );
68 #if defined(_UNICODE) || defined(UNICODE)
69 inline size_t StrSplit( UnicodeString const & str, UnicodeString const & delimList, UnicodeStringArray * arr, bool alwaysRetOneElem = false ) { return StrSplit<wchar>( str, delimList, arr, alwaysRetOneElem ); }
70 #else
71 inline size_t StrSplit( AnsiString const & str, AnsiString const & delimList, AnsiStringArray * arr, bool alwaysRetOneElem = false ) { return StrSplit<char>( str, delimList, arr, alwaysRetOneElem ); }
72 #endif
73 
74 
75 template < typename _ChTy >
76 XStringArray<_ChTy> StrSplit( XString<_ChTy> const & str, XString<_ChTy> const & delimList, bool alwaysRetOneElem = false );
77 template <>
78 WINUX_FUNC_DECL(XStringArray<char>) StrSplit( XString<char> const & str, XString<char> const & delimList, bool alwaysRetOneElem );
79 template <>
80 WINUX_FUNC_DECL(XStringArray<wchar>) StrSplit( XString<wchar> const & str, XString<wchar> const & delimList, bool alwaysRetOneElem );
81 template <>
82 WINUX_FUNC_DECL(XStringArray<char16>) StrSplit( XString<char16> const & str, XString<char16> const & delimList, bool alwaysRetOneElem );
83 template <>
84 WINUX_FUNC_DECL(XStringArray<char32>) StrSplit( XString<char32> const & str, XString<char32> const & delimList, bool alwaysRetOneElem );
92 #if defined(_UNICODE) || defined(UNICODE)
93 inline UnicodeStringArray StrSplit( UnicodeString const & str, UnicodeString const & delimList, bool alwaysRetOneElem = false ) { return StrSplit<wchar>( str, delimList, alwaysRetOneElem ); }
94 #else
95 inline AnsiStringArray StrSplit( AnsiString const & str, AnsiString const & delimList, bool alwaysRetOneElem = false ) { return StrSplit<char>( str, delimList, alwaysRetOneElem ); }
96 #endif
97 
98 
99 template < typename _ChTy >
100 size_t StrSplit2( XString<_ChTy> const & str, XString<_ChTy> const & delim, XStringArray<_ChTy> * arr, bool alwaysRetOneElem = false );
101 template <>
102 WINUX_FUNC_DECL(size_t) StrSplit2( XString<char> const & str, XString<char> const & delim, XStringArray<char> * arr, bool alwaysRetOneElem );
103 template <>
104 WINUX_FUNC_DECL(size_t) StrSplit2( XString<wchar> const & str, XString<wchar> const & delim, XStringArray<wchar> * arr, bool alwaysRetOneElem );
105 template <>
106 WINUX_FUNC_DECL(size_t) StrSplit2( XString<char16> const & str, XString<char16> const & delim, XStringArray<char16> * arr, bool alwaysRetOneElem );
107 template <>
108 WINUX_FUNC_DECL(size_t) StrSplit2( XString<char32> const & str, XString<char32> const & delim, XStringArray<char32> * arr, bool alwaysRetOneElem );
117 #if defined(_UNICODE) || defined(UNICODE)
118 inline size_t StrSplit2( UnicodeString const & str, UnicodeString const & delim, UnicodeStringArray * arr, bool alwaysRetOneElem = false ) { return StrSplit2<wchar>( str, delim, arr, alwaysRetOneElem ); }
119 #else
120 inline size_t StrSplit2( AnsiString const & str, AnsiString const & delim, AnsiStringArray * arr, bool alwaysRetOneElem = false ) { return StrSplit2<char>( str, delim, arr, alwaysRetOneElem ); }
121 #endif
122 
123 
124 template < typename _ChTy >
125 XStringArray<_ChTy> StrSplit2( XString<_ChTy> const & str, XString<_ChTy> const & delim, bool alwaysRetOneElem = false );
126 template <>
127 WINUX_FUNC_DECL(XStringArray<char>) StrSplit2( XString<char> const & str, XString<char> const & delim, bool alwaysRetOneElem );
128 template <>
129 WINUX_FUNC_DECL(XStringArray<wchar>) StrSplit2( XString<wchar> const & str, XString<wchar> const & delim, bool alwaysRetOneElem );
130 template <>
131 WINUX_FUNC_DECL(XStringArray<char16>) StrSplit2( XString<char16> const & str, XString<char16> const & delim, bool alwaysRetOneElem );
132 template <>
133 WINUX_FUNC_DECL(XStringArray<char32>) StrSplit2( XString<char32> const & str, XString<char32> const & delim, bool alwaysRetOneElem );
141 #if defined(_UNICODE) || defined(UNICODE)
142 inline UnicodeStringArray StrSplit2( UnicodeString const & str, UnicodeString const & delim, bool alwaysRetOneElem = false ) { return StrSplit2<wchar>( str, delim, alwaysRetOneElem ); }
143 #else
144 inline AnsiStringArray StrSplit2( AnsiString const & str, AnsiString const & delim, bool alwaysRetOneElem = false ) { return StrSplit2<char>( str, delim, alwaysRetOneElem ); }
145 #endif
146 
147 
148 template < typename _ChTy >
149 XString<_ChTy> StrJoin( XString<_ChTy> const & delim, XStringArray<_ChTy> const & arr );
150 template <>
152 template <>
154 template <>
156 template <>
159 #if defined(_UNICODE) || defined(UNICODE)
160 inline UnicodeString StrJoin( UnicodeString const & delim, UnicodeStringArray const & arr ) { return StrJoin<wchar>( delim, arr ); }
161 #else
162 inline AnsiString StrJoin( AnsiString const & delim, AnsiStringArray const & arr ) { return StrJoin<char>( delim, arr ); }
163 #endif
164 
165 
166 template < typename _ChTy >
167 XString<_ChTy> StrJoinEx( XString<_ChTy> const & delim, XStringArray<_ChTy> const & arr, size_t start = 0, size_t elemCount = -1 );
168 template <>
169 WINUX_FUNC_DECL(XString<char>) StrJoinEx( XString<char> const & delim, XStringArray<char> const & arr, size_t start, size_t elemCount );
170 template <>
171 WINUX_FUNC_DECL(XString<wchar>) StrJoinEx( XString<wchar> const & delim, XStringArray<wchar> const & arr, size_t start, size_t elemCount );
172 template <>
173 WINUX_FUNC_DECL(XString<char16>) StrJoinEx( XString<char16> const & delim, XStringArray<char16> const & arr, size_t start, size_t elemCount );
174 template <>
175 WINUX_FUNC_DECL(XString<char32>) StrJoinEx( XString<char32> const & delim, XStringArray<char32> const & arr, size_t start, size_t elemCount );
177 #if defined(_UNICODE) || defined(UNICODE)
178 inline UnicodeString StrJoinEx( UnicodeString const & delim, UnicodeStringArray const & arr, size_t start = 0, size_t elemCount = -1 ) { return StrJoinEx<wchar>( delim, arr, start, elemCount ); }
179 #else
180 inline AnsiString StrJoinEx( AnsiString const & delim, AnsiStringArray const & arr, size_t start = 0, size_t elemCount = -1 ) { return StrJoinEx<char>( delim, arr, start, elemCount ); }
181 #endif
182 
183 
184 template < typename _ChTy >
185 XString<_ChTy> StrInsert( XString<_ChTy> const & str, size_t start, size_t end, XString<_ChTy> const & insert );
186 template <>
187 WINUX_FUNC_DECL(XString<char>) StrInsert( XString<char> const & str, size_t start, size_t end, XString<char> const & insert );
188 template <>
189 WINUX_FUNC_DECL(XString<wchar>) StrInsert( XString<wchar> const & str, size_t start, size_t end, XString<wchar> const & insert );
190 template <>
191 WINUX_FUNC_DECL(XString<char16>) StrInsert( XString<char16> const & str, size_t start, size_t end, XString<char16> const & insert );
192 template <>
193 WINUX_FUNC_DECL(XString<char32>) StrInsert( XString<char32> const & str, size_t start, size_t end, XString<char32> const & insert );
195 #if defined(_UNICODE) || defined(UNICODE)
196 inline UnicodeString StrInsert( UnicodeString const & str, size_t start, size_t end, UnicodeString const & insert ) { return StrInsert<wchar>( str, start, end, insert ); }
197 #else
198 inline AnsiString StrInsert( AnsiString const & str, size_t start, size_t end, AnsiString const & insert ) { return StrInsert<char>( str, start, end, insert ); }
199 #endif
200 
201 
202 template < typename _ChTy >
203 XString<_ChTy> & StrMakeReplace( XString<_ChTy> * str, XString<_ChTy> const & findText, XString<_ChTy> const & replaceText, size_t offset = 0 );
204 template <>
205 WINUX_FUNC_DECL(XString<char> &) StrMakeReplace( XString<char> * str, XString<char> const & findText, XString<char> const & replaceText, size_t offset );
206 template <>
207 WINUX_FUNC_DECL(XString<wchar> &) StrMakeReplace( XString<wchar> * str, XString<wchar> const & findText, XString<wchar> const & replaceText, size_t offset );
208 template <>
209 WINUX_FUNC_DECL(XString<char16> &) StrMakeReplace( XString<char16> * str, XString<char16> const & findText, XString<char16> const & replaceText, size_t offset );
210 template <>
211 WINUX_FUNC_DECL(XString<char32> &) StrMakeReplace( XString<char32> * str, XString<char32> const & findText, XString<char32> const & replaceText, size_t offset );
213 #if defined(_UNICODE) || defined(UNICODE)
214 inline UnicodeString & StrMakeReplace( UnicodeString * str, UnicodeString const & findText, UnicodeString const & replaceText, size_t offset = 0 ) { return StrMakeReplace<wchar>( str, findText, replaceText, offset ); }
215 #else
216 inline AnsiString & StrMakeReplace( AnsiString * str, AnsiString const & findText, AnsiString const & replaceText, size_t offset = 0 ) { return StrMakeReplace<char>( str, findText, replaceText, offset ); }
217 #endif
218 
219 
220 template < typename _ChTy >
221 XString<_ChTy> StrTrim( XString<_ChTy> const & str, size_t * leftSpaceCount = nullptr, size_t * rightSpaceCount = nullptr );
222 template <>
223 WINUX_FUNC_DECL(XString<char>) StrTrim( XString<char> const & str, size_t * leftSpaceCount, size_t * rightSpaceCount );
224 template <>
225 WINUX_FUNC_DECL(XString<wchar>) StrTrim( XString<wchar> const & str, size_t * leftSpaceCount, size_t * rightSpaceCount );
226 template <>
227 WINUX_FUNC_DECL(XString<char16>) StrTrim( XString<char16> const & str, size_t * leftSpaceCount, size_t * rightSpaceCount );
228 template <>
229 WINUX_FUNC_DECL(XString<char32>) StrTrim( XString<char32> const & str, size_t * leftSpaceCount, size_t * rightSpaceCount );
230 
231 template < typename _ChTy >
232 XString<_ChTy> StrLTrim( XString<_ChTy> const & str, size_t * leftSpaceCount = nullptr );
233 template <>
234 WINUX_FUNC_DECL(XString<char>) StrLTrim( XString<char> const & str, size_t * leftSpaceCount );
235 template <>
236 WINUX_FUNC_DECL(XString<wchar>) StrLTrim( XString<wchar> const & str, size_t * leftSpaceCount );
237 template <>
238 WINUX_FUNC_DECL(XString<char16>) StrLTrim( XString<char16> const & str, size_t * leftSpaceCount );
239 template <>
240 WINUX_FUNC_DECL(XString<char32>) StrLTrim( XString<char32> const & str, size_t * leftSpaceCount );
241 
242 template < typename _ChTy >
243 XString<_ChTy> StrRTrim( XString<_ChTy> const & str, size_t * rightSpaceCount = nullptr );
244 template <>
245 WINUX_FUNC_DECL(XString<char>) StrRTrim( XString<char> const & str, size_t * rightSpaceCount );
246 template <>
247 WINUX_FUNC_DECL(XString<wchar>) StrRTrim( XString<wchar> const & str, size_t * rightSpaceCount );
248 template <>
249 WINUX_FUNC_DECL(XString<char16>) StrRTrim( XString<char16> const & str, size_t * rightSpaceCount );
250 template <>
251 WINUX_FUNC_DECL(XString<char32>) StrRTrim( XString<char32> const & str, size_t * rightSpaceCount );
252 
257 #if defined(_UNICODE) || defined(UNICODE)
258 inline UnicodeString StrTrim( UnicodeString const & str, size_t * leftSpaceCount = nullptr, size_t * rightSpaceCount = nullptr ) { return StrTrim<wchar>( str, leftSpaceCount, rightSpaceCount ); }
259 inline UnicodeString StrLTrim( UnicodeString const & str, size_t * leftSpaceCount = nullptr ) { return StrLTrim<wchar>( str, leftSpaceCount ); }
260 inline UnicodeString StrRTrim( UnicodeString const & str, size_t * rightSpaceCount = nullptr ) { return StrRTrim<wchar>( str, rightSpaceCount ); }
261 #else
262 inline AnsiString StrTrim( AnsiString const & str, size_t * leftSpaceCount = nullptr, size_t * rightSpaceCount = nullptr ) { return StrTrim<char>( str, leftSpaceCount, rightSpaceCount ); }
263 inline AnsiString StrLTrim( AnsiString const & str, size_t * leftSpaceCount = nullptr ) { return StrLTrim<char>( str, leftSpaceCount ); }
264 inline AnsiString StrRTrim( AnsiString const & str, size_t * rightSpaceCount = nullptr ) { return StrRTrim<char>( str, rightSpaceCount ); }
265 #endif
266 
267 
268 template < typename _ChTy >
270 template <>
272 template <>
274 template <>
276 template <>
279 #if defined(_UNICODE) || defined(UNICODE)
280 inline UnicodeString & StrMakeUpper( UnicodeString * str ) { return StrMakeUpper<wchar>(str); }
281 #else
282 inline AnsiString & StrMakeUpper( AnsiString * str ) { return StrMakeUpper<char>(str); }
283 #endif
284 
285 
286 template < typename _ChTy >
288 template <>
290 template <>
292 template <>
294 template <>
297 #if defined(_UNICODE) || defined(UNICODE)
298 inline UnicodeString StrUpper( UnicodeString str ) { return StrUpper<wchar>(str); }
299 #else
300 inline AnsiString StrUpper( AnsiString str ) { return StrUpper<char>(str); }
301 #endif
302 
303 
304 template < typename _ChTy >
306 template <>
308 template <>
310 template <>
312 template <>
315 #if defined(_UNICODE) || defined(UNICODE)
316 inline UnicodeString & StrMakeLower( UnicodeString * str ) { return StrMakeLower<wchar>(str); }
317 #else
318 inline AnsiString & StrMakeLower( AnsiString * str ) { return StrMakeLower<char>(str); }
319 #endif
320 
321 
322 template < typename _ChTy >
324 template <>
326 template <>
328 template <>
330 template <>
333 #if defined(_UNICODE) || defined(UNICODE)
334 inline UnicodeString StrLower( UnicodeString str ) { return StrLower<wchar>(str); }
335 #else
336 inline AnsiString StrLower( AnsiString str ) { return StrLower<char>(str); }
337 #endif
338 
339 
340 template < typename _ChTy >
341 XString<_ChTy> StrMultiple( XString<_ChTy> const & str, size_t multiple );
342 template <>
343 WINUX_FUNC_DECL(XString<char>) StrMultiple( XString<char> const & str, size_t multiple );
344 template <>
345 WINUX_FUNC_DECL(XString<wchar>) StrMultiple( XString<wchar> const & str, size_t multiple );
346 template <>
347 WINUX_FUNC_DECL(XString<char16>) StrMultiple( XString<char16> const & str, size_t multiple );
348 template <>
349 WINUX_FUNC_DECL(XString<char32>) StrMultiple( XString<char32> const & str, size_t multiple );
351 #if defined(_UNICODE) || defined(UNICODE)
352 inline UnicodeString StrMultiple( UnicodeString const & str, size_t multiple ) { return StrMultiple<wchar>( str, multiple ); }
353 #else
354 inline AnsiString StrMultiple( AnsiString const & str, size_t multiple ) { return StrMultiple<char>( str, multiple ); }
355 #endif
356 
357 
358 template < typename _ChTy >
360 template <>
362 template <>
364 template <>
366 template <>
369 #if defined(_UNICODE) || defined(UNICODE)
370 inline UnicodeString StrSubtract( UnicodeString str1, UnicodeString const & str2 ) { return StrSubtract<wchar>( str1, str2 ); }
371 #else
372 inline AnsiString StrSubtract( AnsiString str1, AnsiString const & str2 ) { return StrSubtract<char>( str1, str2 ); }
373 #endif
374 
375 
378 {
383 };
384 
385 template < typename _ChTy >
386 uint64 StrToXq( _ChTy const * nptr, _ChTy const ** endptr, int ibase, int flags );
387 template <>
388 WINUX_FUNC_DECL(uint64) StrToXq( char const * nptr, char const ** endptr, int ibase, int flags );
389 template <>
390 WINUX_FUNC_DECL(uint64) StrToXq( wchar const * nptr, wchar const ** endptr, int ibase, int flags );
391 template <>
392 WINUX_FUNC_DECL(uint64) StrToXq( char16 const * nptr, char16 const ** endptr, int ibase, int flags );
393 template <>
394 WINUX_FUNC_DECL(uint64) StrToXq( char32 const * nptr, char32 const ** endptr, int ibase, int flags );
396 #if defined(_UNICODE) || defined(UNICODE)
397 inline uint64 StrToXq( wchar const * nptr, wchar const ** endptr, int ibase, int flags ) { return StrToXq<wchar>( nptr, endptr, ibase, flags ); }
398 #else
399 inline uint64 StrToXq( char const * nptr, char const ** endptr, int ibase, int flags ) { return StrToXq<char>( nptr, endptr, ibase, flags ); }
400 #endif
401 
402 
403 template < typename _ChTy >
404 int64 StrToInt64( XString<_ChTy> const & numStr, int ibase );
405 template <>
406 WINUX_FUNC_DECL(int64) StrToInt64( XString<char> const & numStr, int ibase );
407 template <>
408 WINUX_FUNC_DECL(int64) StrToInt64( XString<wchar> const & numStr, int ibase );
409 template <>
410 WINUX_FUNC_DECL(int64) StrToInt64( XString<char16> const & numStr, int ibase );
411 template <>
412 WINUX_FUNC_DECL(int64) StrToInt64( XString<char32> const & numStr, int ibase );
413 #if defined(_UNICODE) || defined(UNICODE)
414 inline int64 StrToInt64( UnicodeString const & numStr, int ibase ) { return StrToInt64<wchar>( numStr, ibase ); }
415 #else
416 inline int64 StrToInt64( AnsiString const & numStr, int ibase ) { return StrToInt64<char>( numStr, ibase ); }
417 #endif
418 
419 
420 template < typename _ChTy >
421 uint64 StrToUInt64( XString<_ChTy> const & numStr, int ibase );
422 template <>
423 WINUX_FUNC_DECL(uint64) StrToUInt64( XString<char> const & numStr, int ibase );
424 template <>
425 WINUX_FUNC_DECL(uint64) StrToUInt64( XString<wchar> const & numStr, int ibase );
426 template <>
427 WINUX_FUNC_DECL(uint64) StrToUInt64( XString<char16> const & numStr, int ibase );
428 template <>
429 WINUX_FUNC_DECL(uint64) StrToUInt64( XString<char32> const & numStr, int ibase );
430 #if defined(_UNICODE) || defined(UNICODE)
431 inline uint64 StrToUInt64( UnicodeString const & numStr, int ibase ) { return StrToUInt64<wchar>( numStr, ibase ); }
432 #else
433 inline uint64 StrToUInt64( AnsiString const & numStr, int ibase ) { return StrToUInt64<char>( numStr, ibase ); }
434 #endif
435 
436 
437 template < typename _ChTy >
438 inline XString<_ChTy> AddSlashes( XString<_ChTy> const & str, XString<_ChTy> const & charlist );
439 template <>
440 WINUX_FUNC_DECL(XString<char>) AddSlashes( XString<char> const & str, XString<char> const & charlist );
441 template <>
442 WINUX_FUNC_DECL(XString<wchar>) AddSlashes( XString<wchar> const & str, XString<wchar> const & charlist );
443 template <>
445 template <>
448 #if defined(_UNICODE) || defined(UNICODE)
449 inline UnicodeString AddSlashes( UnicodeString const & str, UnicodeString const & charlist ) { return AddSlashes<wchar>( str, charlist ); }
450 #else
451 inline AnsiString AddSlashes( AnsiString const & str, AnsiString const & charlist ) { return AddSlashes<char>( str, charlist ); }
452 #endif
453 
454 
455 template < typename _ChTy >
456 inline XString<_ChTy> AddCSlashes( XString<_ChTy> const & str ) { return AddSlashes<_ChTy>( str, Literal<_ChTy>::cslashesStr ); }
458 #if defined(_UNICODE) || defined(UNICODE)
459 inline UnicodeString AddCSlashes( UnicodeString const & str ) { return AddCSlashes<wchar>(str); }
460 #else
461 inline AnsiString AddCSlashes( AnsiString const & str ) { return AddCSlashes<char>(str); }
462 #endif
463 
464 
465 template < typename _ChTy >
466 XString<_ChTy> StripSlashes( XString<_ChTy> const & str, XString<_ChTy> const & charlist );
467 template <>
468 WINUX_FUNC_DECL(XString<char>) StripSlashes( XString<char> const & str, XString<char> const & charlist );
469 template <>
471 template <>
473 template <>
476 #if defined(_UNICODE) || defined(UNICODE)
477 inline UnicodeString StripSlashes( UnicodeString const & str, UnicodeString const & charlist ) { return StripSlashes<wchar>( str, charlist ); }
478 #else
479 inline AnsiString StripSlashes( AnsiString const & str, AnsiString const & charlist ) { return StripSlashes<char>( str, charlist ); }
480 #endif
481 
482 
483 template < typename _ChTy >
484 inline XString<_ChTy> StripCSlashes( XString<_ChTy> const & str ) { return StripSlashes<_ChTy>( str, Literal<_ChTy>::cslashesStr ); }
486 #if defined(_UNICODE) || defined(UNICODE)
487 inline UnicodeString StripCSlashes( UnicodeString const & str ) { return StripCSlashes<wchar>(str); }
488 #else
489 inline AnsiString StripCSlashes( AnsiString const & str ) { return StripCSlashes<char>(str); }
490 #endif
491 
492 
493 template < typename _ChTy >
495 template <>
496 WINUX_FUNC_DECL(XString<char>) AddQuotes( XString<char> const & str, char quote );
497 template <>
499 template <>
501 template <>
504 #if defined(_UNICODE) || defined(UNICODE)
505 inline UnicodeString AddQuotes( UnicodeString const & str, UnicodeString::value_type quote = Literal<UnicodeString::value_type>::quoteChar ) { return AddQuotes<wchar>( str, quote ); }
506 #else
507 inline AnsiString AddQuotes( AnsiString const & str, AnsiString::value_type quote = Literal<AnsiString::value_type>::quoteChar ) { return AddQuotes<char>( str, quote ); }
508 #endif
509 
510 
511 template < typename _ChTy >
512 bool StrGetLine( XString<_ChTy> * line, XString<_ChTy> const & str, size_t * i, XString<_ChTy> * nl = nullptr );
513 template <>
514 WINUX_FUNC_DECL(bool) StrGetLine( XString<char> * line, XString<char> const & str, size_t * i, XString<char> * nl );
515 template <>
516 WINUX_FUNC_DECL(bool) StrGetLine( XString<wchar> * line, XString<wchar> const & str, size_t * i, XString<wchar> * nl );
517 template <>
518 WINUX_FUNC_DECL(bool) StrGetLine( XString<char16> * line, XString<char16> const & str, size_t * i, XString<char16> * nl );
519 template <>
520 WINUX_FUNC_DECL(bool) StrGetLine( XString<char32> * line, XString<char32> const & str, size_t * i, XString<char32> * nl );
533 #if defined(_UNICODE) || defined(UNICODE)
534 inline bool StrGetLine( UnicodeString * line, UnicodeString const & str, size_t * i, UnicodeString * nl = nullptr ) { return StrGetLine<wchar>( line, str, i, nl ); }
535 #else
536 inline bool StrGetLine( AnsiString * line, AnsiString const & str, size_t * i, AnsiString * nl = nullptr ) { return StrGetLine<char>( line, str, i, nl ); }
537 #endif
538 
539 
540 template < typename _ChTy >
541 bool StrGetLine( XString<_ChTy> * line, _ChTy const * str, size_t len, size_t * i, XString<_ChTy> * nl = nullptr );
542 template <>
543 WINUX_FUNC_DECL(bool) StrGetLine( XString<char> * line, char const * str, size_t len, size_t * i, XString<char> * nl );
544 template <>
545 WINUX_FUNC_DECL(bool) StrGetLine( XString<wchar> * line, wchar const * str, size_t len, size_t * i, XString<wchar> * nl );
546 template <>
547 WINUX_FUNC_DECL(bool) StrGetLine( XString<char16> * line, char16 const * str, size_t len, size_t * i, XString<char16> * nl );
548 template <>
549 WINUX_FUNC_DECL(bool) StrGetLine( XString<char32> * line, char32 const * str, size_t len, size_t * i, XString<char32> * nl );
563 #if defined(_UNICODE) || defined(UNICODE)
564 inline bool StrGetLine( UnicodeString * line, UnicodeString::value_type const * str, size_t len, size_t * i, UnicodeString * nl = nullptr ) { return StrGetLine<wchar>( line, str, len, i, nl ); }
565 #else
566 inline bool StrGetLine( AnsiString * line, AnsiString::value_type const * str, size_t len, size_t * i, AnsiString * nl = nullptr ) { return StrGetLine<char>( line, str, len, i, nl ); }
567 #endif
568 
569 
577 template < typename _ChTy >
578 void GetLineByPos( XString<_ChTy> const & content, ssize_t pos, ssize_t * lineHead, ssize_t * lineTail, XString<_ChTy> * line = nullptr );
579 template <>
580 WINUX_FUNC_DECL(void) GetLineByPos( XString<char> const & content, ssize_t pos, ssize_t * lineHead, ssize_t * lineTail, XString<char> * line );
581 template <>
582 WINUX_FUNC_DECL(void) GetLineByPos( XString<wchar> const & content, ssize_t pos, ssize_t * lineHead, ssize_t * lineTail, XString<wchar> * line );
583 template <>
584 WINUX_FUNC_DECL(void) GetLineByPos( XString<char16> const & content, ssize_t pos, ssize_t * lineHead, ssize_t * lineTail, XString<char16> * line );
585 template <>
586 WINUX_FUNC_DECL(void) GetLineByPos( XString<char32> const & content, ssize_t pos, ssize_t * lineHead, ssize_t * lineTail, XString<char32> * line );
587 
588 
591 {
592  wordRaw = 0x00,
593  wordAllUpper = 0x01,
594  wordAllLower = 0x02,
596 
603 };
604 
605 template < typename _ChTy >
607 template <>
608 WINUX_FUNC_DECL(XString<char>) CollateIdentifierToString( XString<char> const & identifier, XString<char> const & sep, winux::uint flags );
609 template <>
610 WINUX_FUNC_DECL(XString<wchar>) CollateIdentifierToString( XString<wchar> const & identifier, XString<wchar> const & sep, winux::uint flags );
611 template <>
612 WINUX_FUNC_DECL(XString<char16>) CollateIdentifierToString( XString<char16> const & identifier, XString<char16> const & sep, winux::uint flags );
613 template <>
614 WINUX_FUNC_DECL(XString<char32>) CollateIdentifierToString( XString<char32> const & identifier, XString<char32> const & sep, winux::uint flags );
616 #if defined(_UNICODE) || defined(UNICODE)
617 inline UnicodeString CollateIdentifierToString( UnicodeString const & identifier, UnicodeString const & sep, winux::uint flags = wordFirstCharUpper ) { return CollateIdentifierToString<wchar>( identifier, sep, flags ); }
618 #else
619 inline AnsiString CollateIdentifierToString( AnsiString const & identifier, AnsiString const & sep, winux::uint flags = wordFirstCharUpper ) { return CollateIdentifierToString<char>( identifier, sep, flags ); }
620 #endif
621 
622 
623 template < typename _ChTy >
625 template <>
627 template <>
629 template <>
631 template <>
634 #if defined(_UNICODE) || defined(UNICODE)
635 inline UnicodeStringArray CollateIdentifierToArray( UnicodeString const & identifier, winux::uint flags = wordFirstCharUpper ) { return CollateIdentifierToArray<wchar>( identifier, flags ); }
636 #else
637 inline AnsiStringArray CollateIdentifierToArray( AnsiString const & identifier, winux::uint flags = wordFirstCharUpper ) { return CollateIdentifierToArray<char>( identifier, flags ); }
638 #endif
639 
640 
642 template < typename _IndexType, typename _ChTy >
643 inline static std::vector<_IndexType> _Templ_KmpCalcNext( _ChTy const * substr, size_t sublen )
644 {
645  std::vector<_IndexType> next( sublen + 1 );
646  ssize_t j = 0, k = -1;
647  next[0] = -1;
648  while ( j < (ssize_t)sublen )
649  {
650  if ( k == -1 || substr[j] == substr[k] )
651  {
652  j++;
653  k++;
654  //if ( substr[j] != substr[k] )
655  next[j] = (_IndexType)k;
656  //else
657  // next[j] = next[k];
658  }
659  else
660  {
661  k = next[k];
662  }
663  }
664  return next;
665 }
666 
668 template < typename _IndexType, typename _ChTy >
669 inline static size_t _Templ_KmpMatchEx( _ChTy const * str, size_t len, _ChTy const * substr, size_t sublen, size_t pos, std::vector<_IndexType> const & next )
670 {
671  ssize_t i, j;
672  i = pos;
673  j = 0;
674  while ( i < (ssize_t)len && j < (ssize_t)sublen )
675  {
676  if ( str[i] == substr[j] )
677  {
678  j++;
679  i++;
680  }
681  else
682  {
683  j = next[j];
684 
685  if ( j == -1 )
686  {
687  j = 0;
688  i++;
689  }
690  }
691  }
692  return j == (ssize_t)sublen ? i - (ssize_t)sublen : -1;
693 }
694 
696 template < typename _IndexType, typename _ChTy >
697 inline static size_t _Templ_KmpMatch( _ChTy const * str, size_t len, _ChTy const * substr, size_t sublen, size_t pos )
698 {
699  return _Templ_KmpMatchEx<_IndexType, _ChTy>( str, len, substr, sublen, pos, _Templ_KmpCalcNext( substr, sublen ) );
700 }
701 
703 template < typename _ChTy >
704 inline std::vector<int> KmpCalcNext( _ChTy const * substr, size_t sublen )
705 {
706  return _Templ_KmpCalcNext< int, _ChTy >( substr, sublen );
707 }
709 template < typename _ChTy >
710 inline size_t KmpMatchEx( _ChTy const * str, size_t len, _ChTy const * substr, size_t sublen, size_t pos, std::vector<int> const & next )
711 {
712  return _Templ_KmpMatchEx< int, _ChTy >( str, len, substr, sublen, pos, next );
713 }
715 template < typename _ChTy >
716 inline size_t KmpMatch( _ChTy const * str, size_t len, _ChTy const * substr, size_t sublen, size_t pos )
717 {
718  return KmpMatchEx<_ChTy>( str, len, substr, sublen, pos, KmpCalcNext( substr, sublen ) );
719 }
720 
721 
723 template < typename _ChTy >
725 {
726 public:
731  XStringWriter( XString<_ChTy> * str, bool isAppend = false ) : _str(str), _sout(NULL), _isAppend(isAppend)
732  {
733  _sout = new std::basic_ostringstream<_ChTy>();
734  }
735  XStringWriter( XStringWriter const & other ) : _str(NULL), _sout(NULL)
736  {
737  this->operator = ( const_cast<XStringWriter &>(other) );
738  }
740  {
741  if ( _str )
742  {
743  if ( _isAppend )
744  {
745  *_str += _sout->str();
746  }
747  else
748  {
749  *_str = _sout->str();
750  }
751  }
752  if ( _sout ) delete _sout;
753  }
755  {
756  if ( this != &other )
757  {
758  _str = other._str;
759  _sout = other._sout;
760  _isAppend = other._isAppend;
761 
762  other._str = NULL;
763  other._sout = NULL;
764  other._isAppend = false;
765  }
766  return *this;
767  }
768 
769  template < typename _AnyType >
770  std::basic_ostream<_ChTy> & operator << ( _AnyType && t )
771  {
772  return *_sout << std::forward<_AnyType>(t);
773  }
774 
775 private:
776  XString<_ChTy> * _str;
777  std::basic_ostringstream<_ChTy> * _sout;
778  bool _isAppend;
779 };
780 
788 
791 {
792 public:
793  struct MatchResult
794  {
797  };
798 
799  struct MatchState
800  {
805  bool matched;
806 
807  void reset()
808  {
809  memset( this, 0, sizeof(*this) );
810  mr.pos = -1;
811  mr.item = -1;
812  }
813  };
814 
816  typedef std::vector<short> KmpNextValueArray;
817 
819  typedef std::vector<MatchState> MatchStates;
820 
822  typedef String (* ReplaceFuncType)( MultiMatch const * matchObj, ssize_t item, void * extra );
823 
825  typedef MatchResult ( MultiMatch:: * SearchFuncType )( String const & str, ssize_t offset ) const;
826 
830  MultiMatch();
831 
833  MultiMatch( StringArray const & matches, StringArray const & replaces );
834 
836  MultiMatch( StringArray const & matches, ReplaceFuncType replaceFunc, void * extra = NULL );
837 
839  template < size_t _Count >
840  MultiMatch( String (&matches)[_Count], String (&replaces)[_Count] ) : _replaceFunc(NULL), _extra(NULL)
841  {
842  this->init( StringArray( matches, matches + _Count ), StringArray( replaces, replaces + _Count ) );
843  }
844 
846  template < size_t _Count >
847  MultiMatch( String (&matches)[_Count], ReplaceFuncType replaceFunc, void * extra = NULL ) : _replaceFunc(NULL), _extra(NULL)
848  {
849  this->init( StringArray( matches, matches + _Count ), replaceFunc, extra );
850  }
851 
853  void init( StringArray const & matches, StringArray const & replaces );
854 
856  void init( StringArray const & matches, ReplaceFuncType replaceFunc, void * extra = NULL );
857 
859  ssize_t addMatchReplacePair( String const & match, String const & replace );
860 
862  ssize_t addMatch( String const & match );
863 
865  String const & getMatchItem( ssize_t item ) const;
866 
868  void setMatchItem( ssize_t item, String const & match );
869 
871  String getReplaceItem( ssize_t item ) const;
872 
874  void setReplaceItem( ssize_t item, String const & replace );
875 
877  void setReplaceItems( StringArray const & replaces );
878 
880  ReplaceFuncType setReplaceFunc( ReplaceFuncType newReplaceFunc, void * extra = NULL );
881 
883  void clear();
884 
890  MatchResult search( String const & str, ssize_t offset = 0 ) const;
891 
897  MatchResult greedSearch( String const & str, ssize_t offset = 0 ) const;
898 
904  MatchResult commonSearch( String const & str, ssize_t offset = 0 ) const;
905 
911  String replace( String const & str, ssize_t offset = 0, SearchFuncType fnSearch = &MultiMatch::commonSearch ) const;
912 
913 private:
914  std::vector<KmpNextValueArray> _nextVals;
915  mutable MatchStates _states;
916  StringArray _matchItems;
917  StringArray _replaceItems;
918  ReplaceFuncType _replaceFunc;
919  void * _extra;
920 };
921 
924 {
925 public:
926  static void Set( char const * lc ) { _clsLc = lc; }
927  static char const * Get() { return _clsLc.c_str(); }
928  Locale( char const * lc = NULL );
929  ~Locale();
930 
931 private:
932  AnsiString _loc;
933  AnsiString _prevLoc;
934  static AnsiString _clsLc;
936 };
937 
938 
940 WINUX_FUNC_DECL(size_t) LocalCharsCount( AnsiString const & local );
942 WINUX_FUNC_DECL(size_t) UnicodeMinLength( UnicodeString const & unicode );
947 
956 
957 
958 WINUX_DLL AnsiString FormatExVA( size_t cch, char const * fmt, va_list args );
959 WINUX_DLL UnicodeString FormatExVW( size_t cch, wchar const * fmt, va_list args );
960 
961 WINUX_DLL AnsiString FormatExA( size_t cch, char const * fmt, ... );
962 WINUX_DLL UnicodeString FormatExW( size_t cch, wchar const * fmt, ... );
963 
964 WINUX_DLL AnsiString FormatA( char const * fmt, ... );
965 WINUX_DLL UnicodeString FormatW( wchar const * fmt, ... );
966 
967 #if defined(_UNICODE) || defined(UNICODE)
968 
969 inline UnicodeString FormatExV( size_t cch, wchar const * fmt, va_list args ) { return FormatExVW( cch, fmt, args ); }
971 WINUX_DLL UnicodeString FormatEx( size_t cch, wchar const * fmt, ... );
973 WINUX_DLL UnicodeString Format( wchar const * fmt, ... );
974 #else
975 
976 inline AnsiString FormatExV( size_t cch, char const * fmt, va_list args ) { return FormatExVA( cch, fmt, args ); }
978 WINUX_DLL AnsiString FormatEx( size_t cch, char const * fmt, ... );
980 WINUX_DLL AnsiString Format( char const * fmt, ... );
981 #endif
982 
985 {
986 public:
987  explicit SZInput( char * psz, size_t count ) : _psz(psz), _type(szCharInput), _count(count) { }
988  explicit SZInput( wchar_t * pwsz, size_t count ) : _pwsz(pwsz), _type(szWCharInput), _count(count) { }
989  SZInput & operator = ( char const * pstr );
990  SZInput & operator = ( wchar_t const * pwstr );
991 
992 private:
993  union
994  {
995  char * _psz;
996  wchar_t * _pwsz;
997  };
998  enum { szCharInput, szWCharInput } _type;
999  size_t _count;
1000 };
1001 
1002 #if defined(__GNUC__) || _MSC_VER >= 1600
1003 
1004 template < typename _CHAR, uint _Count >
1005 SZInput SZ( _CHAR (&sz)[_Count] )
1006 {
1007  return SZInput( sz, _Count );
1008 }
1009 
1010 #else
1011 
1012 #define SZ(sz) SZInput( sz, sizeof(sz) / sizeof(sz[0]) )
1013 
1014 #endif
1015 
1016 #define SZP SZInput
1017 
1018 // ----------------------------------------------------------------------------------
1019 
1022 {
1023 public:
1024  Conv( AnsiString const & fromCode, AnsiString const & toCode );
1025  ~Conv();
1026 
1033  size_t convert( char const * srcBuf, size_t srcSize, char * * destBuf );
1034 
1039  template < typename _RetString, typename _String >
1040  _RetString convert( _String const & str )
1041  {
1042  typename _RetString::pointer buf;
1043  size_t n = this->convert( (char *)str.c_str(), str.length() * sizeof(typename _String::value_type), (char **)&buf );
1044  _RetString s( (typename _RetString::pointer)buf, n / sizeof(typename _RetString::value_type) );
1045  Buffer::Free(buf);
1046  return s;
1047  }
1048 
1049 private:
1051 
1053 };
1054 
1056 template < typename _ToString >
1057 class ConvTo : public Conv
1058 {
1059 public:
1060  ConvTo( AnsiString const & toCode ) : Conv( "", toCode )
1061  {
1062  }
1063 
1064  _ToString convert( AnsiString const & str )
1065  {
1066  return this->Conv::convert<_ToString, AnsiString>(str);
1067  }
1068 
1069  _ToString operator () ( AnsiString const & str )
1070  {
1071  typename _ToString::value_type * buf;
1072  size_t n = Conv::convert( (char *)str.c_str(), str.length() * sizeof(typename AnsiString::value_type), (char **)&buf );
1073  _ToString s( buf, n / sizeof(typename _ToString::value_type) );
1074  Buffer::Free(buf);
1075  return s;
1076  }
1077 };
1078 
1080 template < typename _FromString >
1081 class ConvFrom : public Conv
1082 {
1083 public:
1084  ConvFrom( AnsiString const & fromCode ) : Conv( fromCode, "" )
1085  {
1086  }
1087 
1088  AnsiString convert( _FromString const & str )
1089  {
1090  return this->Conv::convert<AnsiString, _FromString>(str);
1091  }
1092 
1093  AnsiString operator () ( _FromString const & str )
1094  {
1095  AnsiString::value_type * buf;
1096  size_t n = Conv::convert( (char *)str.c_str(), str.length() * sizeof(typename _FromString::value_type), (char **)&buf );
1097  AnsiString s( buf, n / sizeof(AnsiString::value_type) );
1098  Buffer::Free(buf);
1099  return s;
1100  }
1101 };
1102 
1105 {
1106 public:
1107  UnicodeConverter( Utf8String const & utf8str );
1108  UnicodeConverter( UnicodeString const & wstr );
1109  UnicodeConverter( Utf16String const & utf16str );
1110  UnicodeConverter( Utf32String const & utf32str );
1111 
1112  Utf8String toUtf8( size_t newCap = 0 ) const;
1113  UnicodeString toUnicode( size_t newCap = 0 ) const;
1114  Utf16String toUtf16( size_t newCap = 0 ) const;
1115  Utf32String toUtf32( size_t newCap = 0 ) const;
1116 
1117  size_t calcUtf8Length() const;
1118  size_t calcUnicodeLength() const;
1119  size_t calcUtf16Length() const;
1120  size_t calcUtf32Length() const;
1121 
1122 private:
1123  template < typename _Ty >
1124  _Ty const * _q() const { return reinterpret_cast<_Ty const *>(_p); }
1125 
1126  void const * _p;
1127  enum {
1128  ucUtf8,
1129  ucUnicode,
1130  ucUtf16,
1131  ucUtf32
1132  } _type;
1133 };
1134 
1137 // 定义一些转换宏
1138 #define $u8(s) winux::UnicodeConverter(s).toUtf8()
1139 #define $L(s) winux::UnicodeConverter(s).toUnicode()
1140 #define $u(s) winux::UnicodeConverter(s).toUtf16()
1141 #define $U(s) winux::UnicodeConverter(s).toUtf32()
1142 
1143 // UTF-8编码转换
1144 // Windows平台默认local就不是utf8,因此不用设置LOCAL_ISNT_UTF8。若设置LOCAL_IS_UTF8,则认为local是utf8
1145 // Unix-like平台默认local就是utf8,因此不用设置LOCAL_IS_UTF8。若设置LOCAL_ISNT_UTF8,则认为local不是utf8
1146 #if defined(OS_WIN) && !defined(LOCAL_IS_UTF8) || defined(LOCAL_ISNT_UTF8)
1147 
1151 #define LOCAL_FROM_UTF8(s) winux::LocalFromUtf8(s)
1152 #define LOCAL_TO_UTF8(s) winux::LocalToUtf8(s)
1153 #else
1154 
1155 inline static AnsiString LocalFromUtf8( AnsiString const & str ) { return str; }
1157 inline static AnsiString LocalToUtf8( AnsiString const & str ) { return str; }
1158 #define LOCAL_FROM_UTF8(s) s
1159 #define LOCAL_TO_UTF8(s) s
1160 #endif
1161 
1162 
1163 } // namespace winux
1164 
1165 #endif // __STRINGS_HPP__
XString< char > AnsiString
Definition: utilities.hpp:257
不处理单词
Definition: strings.hpp:592
XStringWriter & operator=(XStringWriter &other)
Definition: strings.hpp:754
MultiMatch(String(&matches)[_Count], String(&replaces)[_Count])
构造函数3,要求匹配项和替换项
Definition: strings.hpp:840
void GetLineByPos(XString< _ChTy > const &content, ssize_t pos, ssize_t *lineHead, ssize_t *lineTail, XString< _ChTy > *line=nullptr)
获取指定位置的行内容
XString< _ChTy > StrTrim(XString< _ChTy > const &str, size_t *leftSpaceCount=nullptr, size_t *rightSpaceCount=nullptr)
__int64 int64
Definition: utilities.hpp:232
static std::vector< _IndexType > _Templ_KmpCalcNext(_ChTy const *substr, size_t sublen)
KMP匹配算法:求子串next值
Definition: strings.hpp:643
StrToXqFlags
字符串转换成数字Flags
Definition: strings.hpp:377
XString< _ChTy > StrRTrim(XString< _ChTy > const &str, size_t *rightSpaceCount=nullptr)
UnicodeString FormatExW(size_t cch, wchar const *fmt,...)
XString< wchar > UnicodeString
Definition: utilities.hpp:258
ssize_t pos
匹配到的位置
Definition: strings.hpp:795
intptr_t ssize_t
Definition: utilities.hpp:225
wchar_t * _pwsz
Definition: strings.hpp:996
AnsiString FormatA(char const *fmt,...)
char32_t char32
Definition: utilities.hpp:223
XString< _ChTy > StrJoinEx(XString< _ChTy > const &delim, XStringArray< _ChTy > const &arr, size_t start=0, size_t elemCount=-1)
MatchResult mr
匹配结果
Definition: strings.hpp:803
XString< _ChTy > CollateIdentifierToString(XString< _ChTy > const &identifier, XString< _ChTy > const &sep, winux::uint flags=wordFirstCharUpper)
XString< _ChTy > StrInsert(XString< _ChTy > const &str, size_t start, size_t end, XString< _ChTy > const &insert)
AnsiString UnicodeToLocal(UnicodeString const &unicode)
Unicode转换到本地Ansi.
AnsiString StringToLocal(String const &str)
兼容字符串与Unicode、Local字符串相互转换
#define WINUX_DLL
Definition: utilities.hpp:60
wchar_t wchar
Definition: utilities.hpp:229
XString< _ChTy > AddSlashes(XString< _ChTy > const &str, XString< _ChTy > const &charlist)
SZInput(char *psz, size_t count)
Definition: strings.hpp:987
size_t KmpMatchEx(_ChTy const *str, size_t len, _ChTy const *substr, size_t sublen, size_t pos, std::vector< int > const &next)
KMP字符串匹配算法:传入已经求好的next进行匹配
Definition: strings.hpp:710
用来使得String能够用operator<<来赋值
Definition: strings.hpp:724
XString< _ChTy > StrJoin(XString< _ChTy > const &delim, XStringArray< _ChTy > const &arr)
SZInput(wchar_t *pwsz, size_t count)
Definition: strings.hpp:988
SZInput SZ(_CHAR(&sz)[_Count])
VC2010以上支持模板取数组大小
Definition: strings.hpp:1005
XString< tchar > String
Definition: utilities.hpp:261
XString< _ChTy > StrLower(XString< _ChTy > str)
static size_t _Templ_KmpMatch(_ChTy const *str, size_t len, _ChTy const *substr, size_t sublen, size_t pos)
KMP匹配算法:匹配
Definition: strings.hpp:697
单词大写
Definition: strings.hpp:593
ConvFrom(AnsiString const &fromCode)
Definition: strings.hpp:1084
单词小写
Definition: strings.hpp:594
XString< _ChTy > StripCSlashes(XString< _ChTy > const &str)
Definition: strings.hpp:484
bool StrGetLine(XString< _ChTy > *line, XString< _ChTy > const &str, size_t *i, XString< _ChTy > *nl=nullptr)
std::vector< int > KmpCalcNext(_ChTy const *substr, size_t sublen)
KMP字符串匹配算法:求子串next值
Definition: strings.hpp:704
size_t UnicodeMinLength(UnicodeString const &unicode)
返回一个unicode字符串转换为多字节字符串最少需要多少字节(by local CodePage),用于wcstombs ...
static void Free(void *p)
帕斯卡命名 PascalCase
Definition: strings.hpp:599
AnsiString convert(_FromString const &str)
Definition: strings.hpp:1088
CollateIdentifierStringFlag
整理标识符串的标记
Definition: strings.hpp:590
std::vector< XString< _ChTy > > XStringArray
Definition: utilities.hpp:264
int64 StrToInt64(XString< _ChTy > const &numStr, int ibase)
_ToString convert(AnsiString const &str)
Definition: strings.hpp:1064
#define DISABLE_OBJECT_COPY(clsname)
Definition: utilities.hpp:85
有解析到负号
Definition: strings.hpp:380
uint64 StrToXq(_ChTy const *nptr, _ChTy const **endptr, int ibase, int flags)
static void Set(char const *lc)
Definition: strings.hpp:926
字符串编码转换
Definition: strings.hpp:1021
XStringWriter(XString< _ChTy > *str, bool isAppend=false)
构造函数1
Definition: strings.hpp:731
size_t KmpMatch(_ChTy const *str, size_t len, _ChTy const *substr, size_t sublen, size_t pos)
KMP字符串匹配算法:匹配
Definition: strings.hpp:716
UnicodeString FormatExVW(size_t cch, wchar const *fmt, va_list args)
无符号处理
Definition: strings.hpp:379
Unicode转换器。可以使UTF-8、UTF-16、UTF-32字符串相互自由转换,字节序为平台默认
Definition: strings.hpp:1104
XString< _ChTy > StrMultiple(XString< _ChTy > const &str, size_t multiple)
XString< char32 > Utf32String
Definition: utilities.hpp:260
填充based-zero字符串缓冲区包装类
Definition: strings.hpp:984
XString< _ChTy > StrUpper(XString< _ChTy > str)
static constexpr size_t const npos
非位置,值为-1。
Definition: utilities.hpp:285
std::basic_string< _ChTy, std::char_traits< _ChTy >, std::allocator< _ChTy > > XString
Definition: utilities.hpp:255
XStringArray< char > AnsiStringArray
Definition: utilities.hpp:266
std::vector< MatchState > MatchStates
匹配状态数组类型
Definition: strings.hpp:819
XString< _ChTy > & StrMakeLower(XString< _ChTy > *str)
size_t StrSplit2(XString< _ChTy > const &str, XString< _ChTy > const &delim, XStringArray< _ChTy > *arr, bool alwaysRetOneElem=false)
ssize_t markpos
标记位置,表示进行到这个位置了,该从这个位置开始
Definition: strings.hpp:802
XString< _ChTy > & StrMakeReplace(XString< _ChTy > *str, XString< _ChTy > const &findText, XString< _ChTy > const &replaceText, size_t offset=0)
XString< _ChTy > StrSubtract(XString< _ChTy > str1, XString< _ChTy > const &str2)
UnicodeString LocalToUnicode(AnsiString const &local)
本地Ansi转到Unicode
指定编码转到本地编码
Definition: strings.hpp:1081
XString< _ChTy > & StrMakeUpper(XString< _ChTy > *str)
XString< char > Utf8String
Definition: utilities.hpp:257
unsigned int uint
Definition: utilities.hpp:215
static XString< _ChTy > CharSeqToString(_ChTy const *str, size_t len=npos)
C字符串转到XString.
Definition: strings.hpp:16
本地编码转到指定编码
Definition: strings.hpp:1057
static AnsiString LocalToUtf8(AnsiString const &str)
从本地编码转到utf-8
Definition: strings.hpp:1157
ConvTo(AnsiString const &toCode)
Definition: strings.hpp:1060
static size_t _Templ_KmpMatchEx(_ChTy const *str, size_t len, _ChTy const *substr, size_t sublen, size_t pos, std::vector< _IndexType > const &next)
KMP匹配算法:传入已经求好的next进行匹配
Definition: strings.hpp:669
XString< _ChTy > AddQuotes(XString< _ChTy > const &str, _ChTy quote=Literal< _ChTy >::quoteChar)
std::basic_ostream< _ChTy > & operator<<(_AnyType &&t)
Definition: strings.hpp:770
#define WINUX_FUNC_DECL(ret)
Definition: utilities.hpp:64
size_t convert(char const *srcBuf, size_t srcSize, char **destBuf)
进行编码转换
size_t LocalCharsCount(AnsiString const &local)
返回一个本地字符串里有多少个实际的字符(by local CodePage),用于mbstowcs
MultiMatch(String(&matches)[_Count], ReplaceFuncType replaceFunc, void *extra=NULL)
构造函数4,要求匹配项和替换函数,若不进行替换,则replaceFunc可为NULL
Definition: strings.hpp:847
XString< _ChTy > AddCSlashes(XString< _ChTy > const &str)
Definition: strings.hpp:456
AnsiString FormatExV(size_t cch, char const *fmt, va_list args)
格式化字符串0
Definition: strings.hpp:976
XStringArray< _ChTy > CollateIdentifierToArray(XString< _ChTy > const &identifier, winux::uint flags=wordFirstCharUpper)
unsigned char byte
Definition: utilities.hpp:249
XString< _ChTy > StrLTrim(XString< _ChTy > const &str, size_t *leftSpaceCount=nullptr)
读到一个正确的数字字符
Definition: strings.hpp:382
AnsiString Format(char const *fmt,...)
格式化字符串2
String LocalToString(AnsiString const &local)
兼容字符串与Unicode、Local字符串相互转换
size_t StrSplit(XString< _ChTy > const &str, XString< _ChTy > const &delimList, XStringArray< _ChTy > *arr, bool alwaysRetOneElem=false)
SCREAMING_SNAKE_CASE.
Definition: strings.hpp:602
首字母大写
Definition: strings.hpp:595
大驼峰 CamelCase
Definition: strings.hpp:598
char16_t char16
Definition: utilities.hpp:222
_RetString convert(_String const &str)
进行编码转换
Definition: strings.hpp:1040
AnsiString FormatExVA(size_t cch, char const *fmt, va_list args)
XStringArray< wchar > UnicodeStringArray
Definition: utilities.hpp:267
std::vector< short > KmpNextValueArray
NEXT值数组类型
Definition: strings.hpp:816
XString< _ChTy > StripSlashes(XString< _ChTy > const &str, XString< _ChTy > const &charlist)
MatchResult commonSearch(String const &str, ssize_t offset=0) const
搜索任意一项匹配(贪婪模式,非KMP算法)
bool matched
是否完成匹配,完成匹配就不用再进行
Definition: strings.hpp:805
static AnsiString LocalFromUtf8(AnsiString const &str)
从utf-8转到本地编码
Definition: strings.hpp:1155
static XString< _RetChTy > CharToHexStr(_ChTy ch, bool padZero=false)
字符转成16进制串形式
Definition: strings.hpp:24
AnsiString FormatExA(size_t cch, char const *fmt,...)
UnicodeString StringToUnicode(String const &str)
兼容字符串与Unicode、Local字符串相互转换
ssize_t j
下一次从子串开始的位置
Definition: strings.hpp:801
bool prevCharMatch
上一个字符是否匹配
Definition: strings.hpp:804
unsigned __int64 uint64
Definition: utilities.hpp:230
小驼峰 camelCase
Definition: strings.hpp:597
static char const * Get()
Definition: strings.hpp:927
UnicodeString FormatW(wchar const *fmt,...)
XStringWriter(XStringWriter const &other)
Definition: strings.hpp:735
String UnicodeToString(UnicodeString const &unicode)
兼容字符串与Unicode、Local字符串相互转换
XStringArray< tchar > StringArray
Definition: utilities.hpp:272
设置locale信息
Definition: strings.hpp:923
发生溢出
Definition: strings.hpp:381
多项匹配/替换
Definition: strings.hpp:790
uint64 StrToUInt64(XString< _ChTy > const &numStr, int ibase)
XString< char16 > Utf16String
Definition: utilities.hpp:259
AnsiString FormatEx(size_t cch, char const *fmt,...)
格式化字符串1
跨平台基础功能库
Definition: archives.hpp:7
ssize_t item
匹配项的索引
Definition: strings.hpp:796