foobar2000 SDK  2015-08-03
string_base.h
Go to the documentation of this file.
1 #ifndef _PFC_STRING_H_
2 #define _PFC_STRING_H_
3 
4 #include <string>
5 
6 namespace pfc {
7  inline t_size _strParamLen(const char * str) {
8  return strlen(str);
9  }
10 
11 
12  struct string_part_ref {
13  const char * m_ptr;
15 
16 
17  static string_part_ref make(const char * ptr, t_size len) {
18  string_part_ref val = {ptr, len}; return val;
19  }
20 
22  PFC_ASSERT( base <= m_len );
23  return make(m_ptr + base, m_len - base);
24  }
26  PFC_ASSERT( base <= m_len && base + len <= m_len );
27  return make(m_ptr + base, len);
28  }
29  };
30 
31  inline string_part_ref string_part(const char * ptr, t_size len) {
32  string_part_ref val = {ptr, len}; return val;
33  }
34 
35 
36  class NOVTABLE string_receiver {
37  public:
38  virtual void add_string(const char * p_string,t_size p_string_size = ~0) = 0;
39  inline void add_string_(const char * str) {add_string(str, _strParamLen(str));}
40 
41  void add_char(t_uint32 c);//adds unicode char to the string
42  void add_byte(char c) {add_string(&c,1);}
43  void add_chars(t_uint32 p_char,t_size p_count) {for(;p_count;p_count--) add_char(p_char);}
44  protected:
47  };
48 
49  t_size scan_filename(const char * ptr);
50 
51  bool is_path_separator(unsigned c);
52  bool is_path_bad_char(unsigned c);
53  bool is_valid_utf8(const char * param,t_size max = ~0);
54  bool is_lower_ascii(const char * param);
55  bool is_multiline(const char * p_string,t_size p_len = ~0);
56  bool has_path_bad_chars(const char * param);
57  void recover_invalid_utf8(const char * src,char * out,unsigned replace);//out must be enough to hold strlen(char) + 1, or appropiately bigger if replace needs multiple chars
58  void convert_to_lower_ascii(const char * src,t_size max,char * out,char replace = '?');//out should be at least strlen(src)+1 long
59 
60  template<typename char_t> inline char_t ascii_tolower(char_t c) {if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; return c;}
61  template<typename char_t> inline char_t ascii_toupper(char_t c) {if (c >= 'a' && c <= 'z') c += 'A' - 'a'; return c;}
62 
63  t_size string_find_first(const char * p_string,char p_tofind,t_size p_start = 0); //returns infinite if not found
64  t_size string_find_last(const char * p_string,char p_tofind,t_size p_start = ~0); //returns infinite if not found
65  t_size string_find_first(const char * p_string,const char * p_tofind,t_size p_start = 0); //returns infinite if not found
66  t_size string_find_last(const char * p_string,const char * p_tofind,t_size p_start = ~0); //returns infinite if not found
67 
68  t_size string_find_first_ex(const char * p_string,t_size p_string_length,char p_tofind,t_size p_start = 0); //returns infinite if not found
69  t_size string_find_last_ex(const char * p_string,t_size p_string_length,char p_tofind,t_size p_start = ~0); //returns infinite if not found
70  t_size string_find_first_ex(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start = 0); //returns infinite if not found
71  t_size string_find_last_ex(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start = ~0); //returns infinite if not found
72 
73 
74  t_size string_find_first_nc(const char * p_string,t_size p_string_length,char c,t_size p_start = 0); // lengths MUST be valid, no checks are performed (faster than the other flavour)
75  t_size string_find_first_nc(const char * p_string,t_size p_string_length,const char * p_tofind,t_size p_tofind_length,t_size p_start = 0); // lengths MUST be valid, no checks are performed (faster than the other falvour);
76 
77 
78  bool string_has_prefix( const char * string, const char * prefix );
79  bool string_has_prefix_i( const char * string, const char * prefix );
80  bool string_has_suffix( const char * string, const char * suffix );
81  bool string_has_suffix_i( const char * string, const char * suffix );
82 
83  template<typename t_char>
84  t_size strlen_max_t(const t_char * ptr,t_size max) {
85  PFC_ASSERT( ptr != NULL || max == 0 );
86  t_size n = 0;
87  while(n<max && ptr[n] != 0) n++;
88  return n;
89  }
90 
91  inline t_size strlen_max(const char * ptr,t_size max) throw() {return strlen_max_t(ptr,max);}
92  inline t_size wcslen_max(const wchar_t * ptr,t_size max) throw() {return strlen_max_t(ptr,max);}
93 
94 #ifdef _WINDOWS
95  inline t_size tcslen_max(const TCHAR * ptr,t_size max) {return strlen_max_t(ptr,max);}
96 #endif
97 
98  bool string_is_numeric(const char * p_string,t_size p_length = ~0) throw();
99  template<typename char_t> inline bool char_is_numeric(char_t p_char) throw() {return p_char >= '0' && p_char <= '9';}
100  inline bool char_is_hexnumeric(char p_char) throw() {return char_is_numeric(p_char) || (p_char >= 'a' && p_char <= 'f') || (p_char >= 'A' && p_char <= 'F');}
101  inline bool char_is_ascii_alpha_upper(char p_char) throw() {return p_char >= 'A' && p_char <= 'Z';}
102  inline bool char_is_ascii_alpha_lower(char p_char) throw() {return p_char >= 'a' && p_char <= 'z';}
103  inline bool char_is_ascii_alpha(char p_char) throw() {return char_is_ascii_alpha_lower(p_char) || char_is_ascii_alpha_upper(p_char);}
104  inline bool char_is_ascii_alphanumeric(char p_char) throw() {return char_is_ascii_alpha(p_char) || char_is_numeric(p_char);}
105 
106  unsigned atoui_ex(const char * ptr,t_size max);
107  t_int64 atoi64_ex(const char * ptr,t_size max);
108  t_uint64 atoui64_ex(const char * ptr,t_size max);
109 
110  //Throws exception_invalid_params on failure.
111  unsigned char_to_hex(char c);
112  unsigned char_to_dec(char c);
113 
114  //Throws exception_invalid_params or exception_overflow on failure.
115  template<typename t_uint> t_uint atohex(const char * in, t_size inLen) {
116  t_uint ret = 0;
117  const t_uint guard = (t_uint)0xF << (sizeof(t_uint) * 8 - 4);
118  for(t_size walk = 0; walk < inLen; ++walk) {
119  if (ret & guard) throw exception_overflow();
120  ret = (ret << 4) | char_to_hex(in[walk]);
121  }
122  return ret;
123  }
124  template<typename t_uint> t_uint atodec(const char * in, t_size inLen) {
125  t_uint ret = 0;
126  for(t_size walk = 0; walk < inLen; ++walk) {
127  const t_uint prev = ret;
128  ret = (ret * 10) + char_to_dec(in[walk]);
129  if ((ret / 10) != prev) throw exception_overflow();
130  }
131  return ret;
132  }
133 
134  t_size strlen_utf8(const char * s,t_size num = ~0) throw();//returns number of characters in utf8 string; num - no. of bytes (optional)
135  t_size utf8_char_len(const char * s,t_size max = ~0) throw();//returns size of utf8 character pointed by s, in bytes, 0 on error
136  t_size utf8_char_len_from_header(char c) throw();
137  t_size utf8_chars_to_bytes(const char * string,t_size count) throw();
138 
139  t_size strcpy_utf8_truncate(const char * src,char * out,t_size maxbytes);
140 
141  template<typename char_t> void strcpy_t( char_t * out, const char_t * in ) {
142  for(;;) { char_t c = *in++; *out++ = c; if (c == 0) break; }
143  }
144 
145  t_size utf8_decode_char(const char * src,unsigned & out,t_size src_bytes) throw();//returns length in bytes
146  t_size utf8_decode_char(const char * src,unsigned & out) throw();//returns length in bytes
147 
148  t_size utf8_encode_char(unsigned c,char * out) throw();//returns used length in bytes, max 6
149 
150 
151  t_size utf16_decode_char(const char16_t * p_source,unsigned * p_out,t_size p_source_length = ~0) throw();
152  t_size utf16_encode_char(unsigned c,char16_t * out) throw();
153 
154 #ifdef _MSC_VER
155  t_size utf16_decode_char(const wchar_t * p_source,unsigned * p_out,t_size p_source_length = ~0) throw();
156  t_size utf16_encode_char(unsigned c,wchar_t * out) throw();
157 #endif
158 
159  t_size wide_decode_char(const wchar_t * p_source,unsigned * p_out,t_size p_source_length = ~0) throw();
160  t_size wide_encode_char(unsigned c,wchar_t * out) throw();
161 
162 
163  t_size strstr_ex(const char * p_string,t_size p_string_len,const char * p_substring,t_size p_substring_len) throw();
164 
165 
166  t_size skip_utf8_chars(const char * ptr,t_size count) throw();
167  char * strdup_n(const char * src,t_size len);
168  int stricmp_ascii(const char * s1,const char * s2) throw();
169  int stricmp_ascii_ex(const char * s1,t_size len1,const char * s2,t_size len2) throw();
170  int naturalSortCompare( const char * s1, const char * s2) throw();
171  int naturalSortCompareI( const char * s1, const char * s2) throw();
172 
173  int strcmp_ex(const char* p1,t_size n1,const char* p2,t_size n2) throw();
174  int strcmp_nc(const char* p1, size_t n1, const char * p2, size_t n2) throw();
175 
176  unsigned utf8_get_char(const char * src);
177 
178  inline bool utf8_advance(const char * & var) throw() {
179  t_size delta = utf8_char_len(var);
180  var += delta;
181  return delta>0;
182  }
183 
184  inline bool utf8_advance(char * & var) throw() {
185  t_size delta = utf8_char_len(var);
186  var += delta;
187  return delta>0;
188  }
189 
190  inline const char * utf8_char_next(const char * src) throw() {return src + utf8_char_len(src);}
191  inline char * utf8_char_next(char * src) throw() {return src + utf8_char_len(src);}
192 
193  class NOVTABLE string_base : public pfc::string_receiver {
194  public:
195  virtual const char * get_ptr() const = 0;
196  const char * c_str() const { return get_ptr(); }
197  virtual void add_string(const char * p_string,t_size p_length = ~0) = 0;//same as string_receiver method
198  virtual void set_string(const char * p_string,t_size p_length = ~0) {reset();add_string(p_string,p_length);}
199  virtual void truncate(t_size len)=0;
200  virtual t_size get_length() const {return strlen(get_ptr());}
201  virtual char * lock_buffer(t_size p_requested_length) = 0;
202  virtual void unlock_buffer() = 0;
203 
204  void set_string_(const char * str) {set_string(str, _strParamLen(str));}
205 
206  inline const char * toString() const {return get_ptr();}
207 
209  inline t_size length() const {return get_length();}
210 
211  inline void reset() {truncate(0);}
212 
213  inline bool is_empty() const {return *get_ptr()==0;}
214 
215  void skip_trailing_char(unsigned c = ' ');
216 
217  bool is_valid_utf8() const {return pfc::is_valid_utf8(get_ptr());}
218 
219  void convert_to_lower_ascii(const char * src,char replace = '?');
220 
221  inline const string_base & operator= (const char * src) {set_string_(src);return *this;}
222  inline const string_base & operator+= (const char * src) {add_string_(src);return *this;}
223  inline const string_base & operator= (const string_base & src) {set_string(src);return *this;}
224  inline const string_base & operator+= (const string_base & src) {add_string(src);return *this;}
225 
226  bool operator==(const string_base & p_other) const {return strcmp(*this,p_other) == 0;}
227  bool operator!=(const string_base & p_other) const {return strcmp(*this,p_other) != 0;}
228  bool operator>(const string_base & p_other) const {return strcmp(*this,p_other) > 0;}
229  bool operator<(const string_base & p_other) const {return strcmp(*this,p_other) < 0;}
230  bool operator>=(const string_base & p_other) const {return strcmp(*this,p_other) >= 0;}
231  bool operator<=(const string_base & p_other) const {return strcmp(*this,p_other) <= 0;}
232 
233  inline operator const char * () const {return get_ptr();}
234 
235  t_size scan_filename() const {return pfc::scan_filename(get_ptr());}
236 
237  t_size find_first(char p_char,t_size p_start = 0) const {return pfc::string_find_first(get_ptr(),p_char,p_start);}
238  t_size find_last(char p_char,t_size p_start = ~0) const {return pfc::string_find_last(get_ptr(),p_char,p_start);}
239  t_size find_first(const char * p_string,t_size p_start = 0) const {return pfc::string_find_first(get_ptr(),p_string,p_start);}
240  t_size find_last(const char * p_string,t_size p_start = ~0) const {return pfc::string_find_last(get_ptr(),p_string,p_start);}
241 
242  void fix_dir_separator(char c = '\\'); // Backwards compat function, "do what I mean" applied on non Windows
243  void end_with(char c);
244  void end_with_slash();
245  bool ends_with(char c) const;
246  void delimit(const char* c) {if (length()>0) add_string(c);}
247  char last_char() const;
248  void truncate_last_char();
249  void truncate_number_suffix();
250 
251  bool truncate_eol(t_size start = 0);
252  bool fix_eol(const char * append = " (...)",t_size start = 0);
253  bool limit_length(t_size length_in_chars,const char * append = " (...)");
254 
255  void truncate_filename() {truncate(scan_filename());}
256  void truncate_to_parent_path();
257  void add_filename( const char * fn ) {end_with_slash(); *this += fn; }
258 
259  t_size replace_string ( const char * replace, const char * replaceWith, t_size start = 0);
260 
261  string_base & _formatter() const {return const_cast<string_base&>(*this);}
262 
263  bool has_prefix( const char * prefix) const { return string_has_prefix( get_ptr(), prefix ); }
264  bool has_prefix_i( const char * prefix ) const { return string_has_prefix_i( get_ptr(), prefix); }
265  bool has_suffix( const char * suffix ) const { return string_has_suffix( get_ptr(), suffix); }
266  bool has_suffix_i( const char * suffix ) const { return string_has_suffix_i( get_ptr(), suffix); }
267  protected:
270  };
271 
272  template<t_size max_length>
274  public:
275  inline string_fixed_t() {init();}
276  inline string_fixed_t(const string_fixed_t<max_length> & p_source) {init(); *this = p_source;}
277  inline string_fixed_t(const char * p_source) {init(); set_string(p_source);}
278 
279  inline const string_fixed_t<max_length> & operator=(const string_fixed_t<max_length> & p_source) {set_string(p_source);return *this;}
280  inline const string_fixed_t<max_length> & operator=(const char * p_source) {set_string(p_source);return *this;}
281 
282  char * lock_buffer(t_size p_requested_length) {
283  if (p_requested_length >= max_length) return NULL;
284  memset(m_data,0,sizeof(m_data));
285  return m_data;
286  }
287  void unlock_buffer() {
288  m_length = strlen(m_data);
289  }
290 
291  inline operator const char * () const {return m_data;}
292 
293  const char * get_ptr() const {return m_data;}
294 
295  void add_string(const char * ptr,t_size len) {
296  len = strlen_max(ptr,len);
297  if (m_length + len < m_length || m_length + len > max_length) throw pfc::exception_overflow();
298  for(t_size n=0;n<len;n++) {
299  m_data[m_length++] = ptr[n];
300  }
301  m_data[m_length] = 0;
302  }
303  void truncate(t_size len) {
304  if (len > max_length) len = max_length;
305  if (m_length > len) {
306  m_length = len;
307  m_data[len] = 0;
308  }
309  }
310  t_size get_length() const {return m_length;}
311  private:
312  inline void init() {
313  PFC_STATIC_ASSERT(max_length>1);
314  m_length = 0; m_data[0] = 0;
315  }
317  char m_data[max_length+1];
318  };
319 
320  template<template<typename> class t_alloc>
321  class string8_t : public pfc::string_base {
322  private:
324  protected:
327 
328  inline void makespace(t_size s) {
329  if (t_alloc<char>::alloc_prioritizes_speed) {
330  m_data.set_size(s);
331  } else {
332  const t_size old_size = m_data.get_size();
333  if (old_size < s)
334  m_data.set_size(s + 16);
335  else if (old_size > s + 32)
336  m_data.set_size(s);
337  }
338  }
339 
340  inline const char * _get_ptr() const throw() {return used > 0 ? m_data.get_ptr() : "";}
341 
342  public:
343  inline void set_string_(const char * str) {set_string_nc(str, strlen(str));}
344  inline void add_string_(const char * str) {add_string_nc(str, strlen(str));}
345  void set_string_nc(const char * ptr, t_size len) {
346  PFC_ASSERT(! m_data.is_owned(ptr) );
347  PFC_ASSERT( strlen_max(ptr, len) == len );
348  makespace(len+1);
349  pfc::memcpy_t(m_data.get_ptr(),ptr,len);
350  used=len;
351  m_data[used]=0;
352  }
353  void add_string_nc(const char * ptr, t_size len) {
354  PFC_ASSERT(! m_data.is_owned(ptr) );
355  PFC_ASSERT( strlen_max(ptr, len) == len );
356  makespace(used+len+1);
357  pfc::memcpy_t(m_data.get_ptr() + used,ptr,len);
358  used+=len;
359  m_data[used]=0;
360  }
361  inline const t_self & operator= (const char * src) {set_string_(src);return *this;}
362  inline const t_self & operator+= (const char * src) {add_string_(src);return *this;}
363  inline const t_self & operator= (const string_base & src) {set_string(src);return *this;}
364  inline const t_self & operator+= (const string_base & src) {add_string(src);return *this;}
365  inline const t_self & operator= (const t_self & src) {set_string(src);return *this;}
366  inline const t_self & operator+= (const t_self & src) {add_string(src);return *this;}
367 
368  inline const t_self & operator= (string_part_ref src) {set_string(src);return *this;}
369  inline const t_self & operator+= (string_part_ref src) {add_string(src);return *this;}
370 
371  inline operator const char * () const throw() {return _get_ptr();}
372 
373  string8_t() : used(0) {}
374  string8_t(const char * p_string) : used(0) {set_string_(p_string);}
375  string8_t(const char * p_string,t_size p_length) : used(0) {set_string(p_string,p_length);}
376  string8_t(const t_self & p_string) : used(0) {set_string(p_string);}
377  string8_t(const string_base & p_string) : used(0) {set_string(p_string);}
378  string8_t(string_part_ref ref) : used(0) {set_string(ref);}
379 
380  void prealloc(t_size p_size) {m_data.prealloc(p_size+1);}
381 
382  const char * get_ptr() const throw() {return _get_ptr();}
383 
384  void add_string(const char * p_string,t_size p_length = ~0);
385  void set_string(const char * p_string,t_size p_length = ~0);
386 
387  void set_string(string_part_ref ref) {set_string_nc(ref.m_ptr, ref.m_len);}
388  void add_string(string_part_ref ref) {add_string_nc(ref.m_ptr, ref.m_len);}
389 
390  void truncate(t_size len)
391  {
392  if (used>len) {used=len;m_data[len]=0;makespace(used+1);}
393  }
394 
395  t_size get_length() const throw() {return used;}
396 
397 
398  void set_char(unsigned offset,char c);
399 
400  t_size replace_nontext_chars(char p_replace = '_');
401  t_size replace_char(unsigned c1,unsigned c2,t_size start = 0);
402  t_size replace_byte(char c1,char c2,t_size start = 0);
403  void fix_filename_chars(char def = '_',char leave=0);//replace "bad" characters, leave parameter can be used to keep eg. path separators
404  void remove_chars(t_size first,t_size count); //slow
405  void insert_chars(t_size first,const char * src, t_size count);//slow
406  void insert_chars(t_size first,const char * src);
407 
408  //for string_buffer class
409  char * lock_buffer(t_size n)
410  {
411  if (n + 1 == 0) throw exception_overflow();
412  makespace(n+1);
413  pfc::memset_t(m_data,(char)0);
414  return m_data.get_ptr();;
415  }
416 
417  void unlock_buffer() {
418  if (m_data.get_size() > 0) {
419  used=strlen(m_data.get_ptr());
420  makespace(used+1);
421  }
422  }
423 
424  void force_reset() {used=0;m_data.force_reset();}
425 
426  inline static void g_swap(t_self & p_item1,t_self & p_item2) {
427  pfc::swap_t(p_item1.m_data,p_item2.m_data);
428  pfc::swap_t(p_item1.used,p_item2.used);
429  }
430  };
431 
435  //for backwards compatibility
437 
438 
439  template<template<typename> class t_alloc> class traits_t<string8_t<t_alloc> > : public pfc::combine_traits<pfc::traits_vtable,pfc::traits_t<pfc::array_t<char,t_alloc> > > {
440  public:
441  enum {
442  needs_constructor = true,
443  };
444  };
445 }
446 
447 
448 
449 #include "string8_impl.h"
450 
451 #define PFC_DEPRECATE_PRINTF PFC_DEPRECATE("Use string8/string_fixed_t with operator<< overloads instead.")
452 
453 namespace pfc {
454 
456  private:
458  char * m_buffer;
459  public:
460  explicit string_buffer(string_base & p_string,t_size p_requested_length) : m_owner(p_string) {m_buffer = m_owner.lock_buffer(p_requested_length);}
462  char * get_ptr() {return m_buffer;}
463  operator char* () {return m_buffer;}
464  };
465 
466  class PFC_DEPRECATE_PRINTF string_printf : public string8_fastalloc {
467  public:
468  static void g_run(string_base & out,const char * fmt,va_list list);
469  void run(const char * fmt,va_list list);
470 
471  explicit string_printf(const char * fmt,...);
472  };
473 
474  class PFC_DEPRECATE_PRINTF string_printf_va : public string8_fastalloc {
475  public:
476  string_printf_va(const char * fmt,va_list list);
477  };
478 
479  class format_time {
480  public:
481  format_time(t_uint64 p_seconds);
482  const char * get_ptr() const {return m_buffer;}
483  operator const char * () const {return m_buffer;}
484  protected:
486  };
487 
488 
490  public:
491  format_time_ex(double p_seconds,unsigned p_extra = 3);
492  const char * get_ptr() const {return m_buffer;}
493  operator const char * () const {return m_buffer;}
494  private:
496  };
497 
498 
499  double parse_timecode( const char * tc );
500 
501  class string_filename : public string8 {
502  public:
503  explicit string_filename(const char * fn);
504  };
505 
506  class string_filename_ext : public string8 {
507  public:
508  explicit string_filename_ext(const char * fn);
509  };
510 
512  {
513  char buffer[32];
514  public:
515  inline const char * get_ptr() const {return buffer;}
516  inline t_size length() const {return strlen(buffer);}
517  inline operator const char * () const {return buffer;}
518  inline const char * toString() const {return buffer;}
519  explicit string_extension(const char * src);
520  };
521 
522 
524  {
525  public:
526  string_replace_extension(const char * p_path,const char * p_ext);
527  inline operator const char*() const {return m_data;}
528  private:
530  };
531 
533  {
534  public:
535  string_directory(const char * p_path);
536  inline operator const char*() const {return m_data;}
537  private:
539  };
540 
541  void float_to_string(char * out,t_size out_max,double val,unsigned precision,bool force_sign = false);//doesnt add E+X etc, has internal range limits, useful for storing float numbers as strings without having to bother with international coma/dot settings BS
542  double string_to_float(const char * src,t_size len = ~0);
543 
544  template<>
545  inline void swap_t(string8 & p_item1,string8 & p_item2)
546  {
547  string8::g_swap(p_item1,p_item2);
548  }
549 
551  {
552  public:
553  format_float(double p_val,unsigned p_width = 0,unsigned p_prec = 7);
554  format_float(const format_float & p_source) {*this = p_source;}
555 
556  inline const char * get_ptr() const {return m_buffer.get_ptr();}
557  inline const char * toString() const {return m_buffer.get_ptr();}
558  inline operator const char*() const {return m_buffer.get_ptr();}
559  private:
561  };
562 
564  {
565  public:
566  format_int(t_int64 p_val,unsigned p_width = 0,unsigned p_base = 10);
567  format_int(const format_int & p_source) {*this = p_source;}
568  inline const char * get_ptr() const {return m_buffer;}
569  inline const char * toString() const {return m_buffer;}
570  inline operator const char*() const {return m_buffer;}
571  private:
572  char m_buffer[64];
573  };
574 
575 
576  class format_uint {
577  public:
578  format_uint(t_uint64 p_val,unsigned p_width = 0,unsigned p_base = 10);
579  format_uint(const format_uint & p_source) {*this = p_source;}
580  inline const char * get_ptr() const {return m_buffer;}
581  inline const char * toString() const {return m_buffer;}
582  inline operator const char*() const {return m_buffer;}
583  private:
584  char m_buffer[64];
585  };
586 
588  {
589  public:
590  format_hex(t_uint64 p_val,unsigned p_width = 0);
591  format_hex(const format_hex & p_source) {*this = p_source;}
592  inline const char * get_ptr() const {return m_buffer;}
593  inline const char * toString() const {return m_buffer;}
594  inline operator const char*() const {return m_buffer;}
595  private:
596  char m_buffer[17];
597  };
598 
600  {
601  public:
602  format_hex_lowercase(t_uint64 p_val,unsigned p_width = 0);
603  format_hex_lowercase(const format_hex_lowercase & p_source) {*this = p_source;}
604  inline const char * get_ptr() const {return m_buffer;}
605  inline operator const char*() const {return m_buffer;}
606  inline const char * toString() const {return m_buffer;}
607  private:
608  char m_buffer[17];
609  };
610 
611  char format_hex_char_lowercase(unsigned p_val);
612  char format_hex_char(unsigned p_val);
613 
614 
616 #define PFC_string_formatter() ::pfc::string_formatter()._formatter()
617 
619  {
620  public:
621  format_hexdump(const void * p_buffer,t_size p_bytes,const char * p_spacing = " ");
622 
623  inline const char * get_ptr() const {return m_formatter;}
624  inline operator const char * () const {return m_formatter;}
625  inline const char * toString() const {return m_formatter;}
626  private:
627  string_formatter m_formatter;
628  };
629 
631  {
632  public:
633  format_hexdump_lowercase(const void * p_buffer,t_size p_bytes,const char * p_spacing = " ");
634 
635  inline const char * get_ptr() const {return m_formatter;}
636  inline operator const char * () const {return m_formatter;}
637  inline const char * toString() const {return m_formatter;}
638 
639  private:
640  string_formatter m_formatter;
641  };
642 
644  {
645  public:
646  format_fixedpoint(t_int64 p_val,unsigned p_point);
647  inline const char * get_ptr() const {return m_buffer;}
648  inline operator const char*() const {return m_buffer;}
649  inline const char * toString() const {return m_buffer;}
650  private:
651  string_formatter m_buffer;
652  };
653 
654  class format_char {
655  public:
656  format_char(char p_char) {m_buffer[0] = p_char; m_buffer[1] = 0;}
657  inline const char * get_ptr() const {return m_buffer;}
658  inline operator const char*() const {return m_buffer;}
659  inline const char * toString() const {return m_buffer;}
660  private:
661  char m_buffer[2];
662  };
663 
664  template<typename t_stringbuffer = pfc::string8_fastalloc>
666  public:
667  format_pad_left(t_size p_chars,t_uint32 p_padding /* = ' ' */,const char * p_string,t_size p_string_length = ~0) {
668  t_size source_len = 0, source_walk = 0;
669 
670  while(source_walk < p_string_length && source_len < p_chars) {
671  unsigned dummy;
672  t_size delta = pfc::utf8_decode_char(p_string + source_walk, dummy, p_string_length - source_walk);
673  if (delta == 0) break;
674  source_len++;
675  source_walk += delta;
676  }
677 
678  m_buffer.add_string(p_string,source_walk);
679  m_buffer.add_chars(p_padding,p_chars - source_len);
680  }
681  inline const char * get_ptr() const {return m_buffer;}
682  inline operator const char*() const {return m_buffer;}
683  inline const char * toString() const {return m_buffer;}
684  private:
685  t_stringbuffer m_buffer;
686  };
687 
688  template<typename t_stringbuffer = pfc::string8_fastalloc>
690  public:
691  format_pad_right(t_size p_chars,t_uint32 p_padding /* = ' ' */,const char * p_string,t_size p_string_length = ~0) {
692  t_size source_len = 0, source_walk = 0;
693 
694  while(source_walk < p_string_length && source_len < p_chars) {
695  unsigned dummy;
696  t_size delta = pfc::utf8_decode_char(p_string + source_walk, dummy, p_string_length - source_walk);
697  if (delta == 0) break;
698  source_len++;
699  source_walk += delta;
700  }
701 
702  m_buffer.add_chars(p_padding,p_chars - source_len);
703  m_buffer.add_string(p_string,source_walk);
704  }
705  inline const char * get_ptr() const {return m_buffer;}
706  inline operator const char*() const {return m_buffer;}
707  inline const char * toString() const {return m_buffer;}
708  private:
709  t_stringbuffer m_buffer;
710  };
711 
712 
713 
714  class format_file_size_short : public string_formatter {
715  public:
717  t_uint64 get_used_scale() const {return m_scale;}
718  private:
720  };
721 
722 }
723 
724 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,const char * p_source) {p_fmt.add_string_(p_source); return p_fmt;}
725 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,pfc::string_part_ref source) {p_fmt.add_string(source.m_ptr, source.m_len); return p_fmt;}
726 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,short p_val) {p_fmt.add_string(pfc::format_int(p_val)); return p_fmt;}
727 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,unsigned short p_val) {p_fmt.add_string(pfc::format_uint(p_val)); return p_fmt;}
728 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,int p_val) {p_fmt.add_string(pfc::format_int(p_val)); return p_fmt;}
729 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,unsigned p_val) {p_fmt.add_string(pfc::format_uint(p_val)); return p_fmt;}
730 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,long p_val) {p_fmt.add_string(pfc::format_int(p_val)); return p_fmt;}
731 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,unsigned long p_val) {p_fmt.add_string(pfc::format_uint(p_val)); return p_fmt;}
732 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,long long p_val) {p_fmt.add_string(pfc::format_int(p_val)); return p_fmt;}
733 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,unsigned long long p_val) {p_fmt.add_string(pfc::format_uint(p_val)); return p_fmt;}
734 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,double p_val) {p_fmt.add_string(pfc::format_float(p_val)); return p_fmt;}
735 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,std::exception const & p_exception) {p_fmt.add_string(p_exception.what()); return p_fmt;}
736 
737 template<template<typename> class t_alloc> inline pfc::string8_t<t_alloc> & operator<< (pfc::string8_t<t_alloc> & str, const char * src) {str.add_string_(src); return str;}
738 template<template<typename> class t_alloc> inline pfc::string8_t<t_alloc> & operator<< (pfc::string8_t<t_alloc> & str, pfc::string_base const & src) {str.add_string(src); return str;}
739 template<template<typename> class t_alloc> inline pfc::string8_t<t_alloc> & operator<< (pfc::string8_t<t_alloc> & str, pfc::string_part_ref src) {str.add_string(src); return str;}
740 
741 
742 namespace pfc {
743 
745  public:
746  template<typename t_source> format_array(t_source const & source, const char * separator = ", ") {
747  const t_size count = array_size_t(source);
748  if (count > 0) {
749  *this << source[0];
750  for(t_size walk = 1; walk < count; ++walk) *this << separator << source[walk];
751  }
752  }
753  };
754 
755 
757  public:
758  template<typename TWord> format_hexdump_ex(const TWord * buffer, t_size bufLen, const char * spacing = " ") {
759  for(t_size n = 0; n < bufLen; n++) {
760  if (n > 0 && spacing != NULL) m_formatter << spacing;
761  m_formatter << format_hex(buffer[n],sizeof(TWord) * 2);
762  }
763  }
764  inline const char * get_ptr() const {return m_formatter;}
765  inline operator const char * () const {return m_formatter;}
766  inline const char * toString() const {return m_formatter;}
767  private:
769  };
770 
771 
772 
773 
774 
775  template<typename t_char>
777  private:
779  public:
780  t_size length() const {
781  t_size s = m_buffer.get_size();
782  if (s == 0) return 0; else return s-1;
783  }
784  bool is_empty() const {return m_buffer.get_size() == 0;}
785 
786  void set_string_nc(const t_char * p_source, t_size p_length) {
787  if (p_length == 0) {
788  m_buffer.set_size(0);
789  } else {
790  m_buffer.set_size(p_length + 1);
791  pfc::memcpy_t(m_buffer.get_ptr(),p_source,p_length);
792  m_buffer[p_length] = 0;
793  }
794  }
795  void set_string(const t_char * p_source) {
796  set_string_nc(p_source, pfc::strlen_t(p_source));
797  }
798  void set_string(const t_char * p_source, t_size p_length) {
799  set_string_nc(p_source, strlen_max_t(p_source, p_length));
800  }
801  void add_string(const t_char * p_source, t_size p_length) {
802  add_string_nc(p_source, strlen_max_t(p_source, p_length));
803  }
804  void add_string(const t_char * p_source) {
805  add_string_nc(p_source, strlen_t(p_source));
806  }
807  void add_string_nc(const t_char * p_source, t_size p_length) {
808  if (p_length > 0) {
809  t_size base = length();
810  m_buffer.set_size( base + p_length + 1 );
811  memcpy_t(m_buffer.get_ptr() + base, p_source, p_length);
812  m_buffer[base + p_length] = 0;
813  }
814  }
816  string_simple_t(const t_char * p_source) {set_string(p_source);}
817  string_simple_t(const t_char * p_source, t_size p_length) {set_string(p_source, p_length);}
818  const t_self & operator=(const t_char * p_source) {set_string(p_source);return *this;}
819  operator const t_char* () const {return get_ptr();}
820  const t_char * get_ptr() const {return m_buffer.get_size() > 0 ? m_buffer.get_ptr() : pfc::empty_string_t<t_char>();}
821  const t_char * c_str() const { return get_ptr(); }
822  private:
824  };
825 
827 
828  template<typename t_char> class traits_t<string_simple_t<t_char> > : public traits_t<array_t<t_char> > {};
829 }
830 
831 
832 namespace pfc {
834  public:
835  inline static int compare(const char * p_item1,const char * p_item2) {return strcmp(p_item1,p_item2);}
836  inline static int compare(const wchar_t * item1, const wchar_t * item2) {return wcscmp(item1, item2);}
837 
838  static int compare(const char * p_item1, string_part_ref p_item2) {
839  return strcmp_ex(p_item1, ~0, p_item2.m_ptr, p_item2.m_len);
840  }
841  static int compare(string_part_ref p_item1, string_part_ref p_item2) {
842  return strcmp_ex(p_item1.m_ptr, p_item1.m_len, p_item2.m_ptr, p_item2.m_len);
843  }
844  static int compare(string_part_ref p_item1, const char * p_item2) {
845  return strcmp_ex(p_item1.m_ptr, p_item1.m_len, p_item2, ~0);
846  }
847  };
848 
850  public:
851  inline static int compare(const char * p_item1,const char * p_item2) {return stricmp_ascii(p_item1,p_item2);}
852  };
853 
854 
856  public:
857  inline static int compare( const char * i1, const char * i2 ) throw() {return naturalSortCompare(i1, i2); }
858  };
859 
860  template<typename t_source> static void stringCombine(pfc::string_base & out, t_source const & in, const char * separator, const char * separatorLast) {
861  out.reset();
862  for(typename t_source::const_iterator walk = in.first(); walk.is_valid(); ++walk) {
863  if (!out.is_empty()) {
864  if (walk == in.last()) out << separatorLast;
865  else out << separator;
866  }
867  out << stringToPtr(*walk);
868  }
869  }
870 
871  template<typename t_output, typename t_splitCheck>
872  void splitStringEx(t_output & p_output, const t_splitCheck & p_check, const char * p_string, t_size p_stringLen = ~0) {
873  t_size walk = 0, splitBase = 0;
874  const t_size max = strlen_max(p_string,p_stringLen);
875  for(;walk < max;) {
876  t_size delta = p_check(p_string + walk,max - walk);
877  if (delta > 0) {
878  if (walk > splitBase) p_output(p_string + splitBase, walk - splitBase);
879  splitBase = walk + delta;
880  } else {
881  delta = utf8_char_len(p_string + walk, max - walk);
882  if (delta == 0) break;
883  }
884  walk += delta;
885  }
886  if (walk > splitBase) p_output(p_string + splitBase, walk - splitBase);
887  }
888 
890  public:
892  void operator() (const char *, t_size) {++m_count;}
893  t_size get() const {return m_count;}
894  private:
896  };
897 
898  template<typename t_param> class _splitStringSimple_check;
899 
900  template<> class _splitStringSimple_check<const char*> {
901  public:
902  _splitStringSimple_check(const char * p_chars) {
903  m_chars.set_size(strlen_utf8(p_chars));
904  for(t_size walk = 0, ptr = 0; walk < m_chars.get_size(); ++walk) {
905  ptr += utf8_decode_char(p_chars + ptr,m_chars[walk]);
906  }
907  }
908  t_size operator()(const char * p_string, t_size p_stringLen) const {
909  t_uint32 c;
910  t_size delta = utf8_decode_char(p_string, c, p_stringLen);
911  if (delta > 0) {
912  for(t_size walk = 0; walk < m_chars.get_size(); ++walk) {
913  if (m_chars[walk] == c) return delta;
914  }
915  }
916  return 0;
917  }
918  private:
920  };
921  template<> class _splitStringSimple_check<char> {
922  public:
923  _splitStringSimple_check(char c) : m_char(c) {}
924  t_size operator()(const char * str, t_size len) const {
925  PFC_ASSERT( len > 0 );
926  if (*str == m_char) return 1;
927  else return 0;
928  }
929  private:
930  const char m_char;
931  };
932  template<typename t_array>
934  public:
935  __splitStringSimple_arrayWrapper(t_array & p_array) : m_walk(), m_array(p_array) {}
936  void operator()(const char * p_string, t_size p_stringLen) {
937  m_array[m_walk++] = string_part(p_string,p_stringLen);
938  }
939  private:
941  t_array & m_array;
942  };
943  template<typename t_list>
945  public:
946  __splitStringSimple_listWrapper(t_list & p_list) : m_list(p_list) {}
947  void operator()(const char * p_string, t_size p_stringLen) {
948  m_list += string_part(p_string, p_stringLen);
949  }
950  private:
951  t_list & m_list;
952  };
953 
954  template<typename t_array, typename t_split>
955  void splitStringSimple_toArray(t_array & p_output, t_split p_split, const char * p_string, t_size p_stringLen = ~0) {
956  _splitStringSimple_check<t_split> strCheck(p_split);
957 
958  {
960  splitStringEx(wrapper,strCheck,p_string,p_stringLen);
961  p_output.set_size(wrapper.get());
962  }
963 
964  {
966  splitStringEx(wrapper,strCheck,p_string,p_stringLen);
967  }
968  }
969  template<typename t_list, typename t_split>
970  void splitStringSimple_toList(t_list & p_output, t_split p_split, const char * p_string, t_size p_stringLen = ~0) {
971  _splitStringSimple_check<t_split> strCheck(p_split);
972 
973  __splitStringSimple_listWrapper<t_list> wrapper(p_output);
974  splitStringEx(wrapper,strCheck,p_string,p_stringLen);
975  }
976 
977  template<typename t_out> void splitStringByLines(t_out & out, const char * str) {
978  for(;;) {
979  const char * next = strchr(str, '\n');
980  if (next == NULL) {
981  out += string_part(str, strlen(str)); break;
982  }
983  const char * walk = next;
984  while(walk > str && walk[-1] == '\r') --walk;
985  out += string_part(str, walk - str);
986  str = next + 1;
987  }
988  }
989  template<typename t_out> void splitStringByChar(t_out & out, const char * str, char c) {
990  for(;;) {
991  const char * next = strchr(str, c);
992  if (next == NULL) {
993  out += string_part(str, strlen(str)); break;
994  }
995  out += string_part(str, next - str);
996  str = next + 1;
997  }
998  }
999  template<typename t_out> void splitStringBySubstring(t_out & out, const char * str, const char * split) {
1000  for(;;) {
1001  const char * next = strstr(str, split);
1002  if (next == NULL) {
1003  out += string_part(str, strlen(str)); break;
1004  }
1005  out += string_part(str, next - str);
1006  str = next + strlen(split);
1007  }
1008  }
1009 
1010  void stringToUpperAppend(string_base & p_out, const char * p_source, t_size p_sourceLen);
1011  void stringToLowerAppend(string_base & p_out, const char * p_source, t_size p_sourceLen);
1012  int stringCompareCaseInsensitive(const char * s1, const char * s2);
1014  t_uint32 charLower(t_uint32 param);
1015  t_uint32 charUpper(t_uint32 param);
1016  bool stringEqualsI_utf8(const char * p1,const char * p2) throw();
1017  bool stringEqualsI_ascii(const char * p1,const char * p2) throw();
1018  char ascii_tolower_lookup(char c);
1019 
1020  template<typename T> inline const char * stringToPtr(T const& val) {return val.c_str();}
1021  inline const char * stringToPtr(const char* val) {return val;}
1022 
1023  template<typename T> static string_part_ref stringToRef(T const & val) {return string_part(stringToPtr(val), val.length());}
1024  inline string_part_ref stringToRef(string_part_ref val) {return val;}
1025  inline string_part_ref stringToRef(const char * val) {return string_part(val, strlen(val));}
1026 
1027 
1028 
1029 
1030  class string_base_ref : public string_base {
1031  public:
1032  string_base_ref(const char * ptr) : m_ptr(ptr), m_len(strlen(ptr)) {}
1033  const char * get_ptr() const {return m_ptr;}
1034  t_size get_length() const {return m_len;}
1035  private:
1036  void add_string(const char * p_string,t_size p_length = ~0) {throw pfc::exception_not_implemented();}
1037  void set_string(const char * p_string,t_size p_length = ~0) {throw pfc::exception_not_implemented();}
1038  void truncate(t_size len) {throw pfc::exception_not_implemented();}
1039  char * lock_buffer(t_size p_requested_length) {throw pfc::exception_not_implemented();}
1040  void unlock_buffer() {throw pfc::exception_not_implemented();}
1041  private:
1042  const char * const m_ptr;
1043  t_size const m_len;
1044  };
1045 
1047  template<typename TChar, t_size len, typename TSource>
1048  void stringToBuffer(TChar (&buffer)[len], const TSource & source) {
1049  PFC_STATIC_ASSERT(len>0);
1050  t_size walk;
1051  for(walk = 0; walk < len - 1 && source[walk] != 0; ++walk) {
1052  buffer[walk] = source[walk];
1053  }
1054  buffer[walk] = 0;
1055  }
1056 
1058  template<typename TChar, t_size len, typename TSource>
1059  void stringToBufferGuarded(TChar (&buffer)[len], const TSource & source) {
1060  t_size walk;
1061  for(walk = 0; source[walk] != 0; ++walk) {
1062  if (walk >= len) throw exception_overflow();
1063  buffer[walk] = source[walk];
1064  }
1065  if (walk >= len) throw exception_overflow();
1066  buffer[walk] = 0;
1067  }
1068 
1069 
1070  template<typename t_char> int _strcmp_partial_ex(const t_char * p_string,t_size p_string_length,const t_char * p_substring,t_size p_substring_length) throw() {
1071  for(t_size walk=0;walk<p_substring_length;walk++) {
1072  t_char stringchar = (walk>=p_string_length ? 0 : p_string[walk]);
1073  t_char substringchar = p_substring[walk];
1074  int result = compare_t(stringchar,substringchar);
1075  if (result != 0) return result;
1076  }
1077  return 0;
1078  }
1079 
1080  template<typename t_char> int strcmp_partial_ex_t(const t_char * p_string,t_size p_string_length,const t_char * p_substring,t_size p_substring_length) throw() {
1081  p_string_length = strlen_max_t(p_string,p_string_length); p_substring_length = strlen_max_t(p_substring,p_substring_length);
1082  return _strcmp_partial_ex(p_string,p_string_length,p_substring,p_substring_length);
1083  }
1084 
1085  template<typename t_char>
1086  int strcmp_partial_t(const t_char * p_string,const t_char * p_substring) throw() {return strcmp_partial_ex_t(p_string,~0,p_substring,~0);}
1087 
1088  inline int strcmp_partial_ex(const char * str, t_size strLen, const char * substr, t_size substrLen) throw() {return strcmp_partial_ex(str, strLen, substr, substrLen); }
1089  inline int strcmp_partial(const char * str, const char * substr) throw() {return strcmp_partial_t(str, substr); }
1090 
1091  int stricmp_ascii_partial( const char * str, const char * substr) throw();
1092 
1093  void urlEncodeAppendRaw(pfc::string_base & out, const char * in, t_size inSize);
1094  void urlEncodeAppend(pfc::string_base & out, const char * in);
1095  void urlEncode(pfc::string_base & out, const char * in);
1096 
1097 
1098  char * strDup(const char * src); // POSIX strdup() clone, prevent MSVC complaining
1099 }
1100 
1101 #endif //_PFC_STRING_H_
char * lock_buffer(t_size p_requested_length)
Definition: string_base.h:282
void set_string_nc(const t_char *p_source, t_size p_length)
Definition: string_base.h:786
t_size utf16_encode_char(unsigned c, char16_t *out)
Definition: utf8.cpp:165
string_part_ref substring(t_size base) const
Definition: string_base.h:21
char ascii_tolower_lookup(char c)
t_size skip_utf8_chars(const char *ptr, t_size count)
Definition: utf8.cpp:252
const char * toString() const
Definition: string_base.h:557
bool stringEqualsI_ascii(const char *p1, const char *p2)
char format_hex_char_lowercase(unsigned p_val)
void set_string_nc(const char *ptr, t_size len)
Definition: string_base.h:345
void set_string(const t_char *p_source, t_size p_length)
Definition: string_base.h:798
virtual t_size get_length() const
Definition: string_base.h:200
bool operator==(const string_base &p_other) const
Definition: string_base.h:226
bool string_has_suffix(const char *string, const char *suffix)
char * strDup(const char *src)
const t_item * get_ptr() const
Definition: array.h:213
t_size get_length() const
Definition: string_base.h:310
string_base & m_owner
Definition: string_base.h:457
const char * stringToPtr(T const &val)
Definition: string_base.h:1020
t_size find_last(char p_char, t_size p_start=~0) const
Definition: string_base.h:238
t_size strstr_ex(const char *p_string, t_size p_string_len, const char *p_substring, t_size p_substring_len)
bool has_prefix(const char *prefix) const
Definition: string_base.h:263
string_part_ref substring(t_size base, t_size len) const
Definition: string_base.h:25
string_fixed_t(const char *p_source)
Definition: string_base.h:277
format_int(const format_int &p_source)
Definition: string_base.h:567
virtual void unlock_buffer()=0
void add_chars(t_uint32 p_char, t_size p_count)
Definition: string_base.h:43
unsigned char_to_hex(char c)
void splitStringByLines(t_out &out, const char *str)
Definition: string_base.h:977
void set_string(string_part_ref ref)
Definition: string_base.h:387
t_stringbuffer m_buffer
Definition: string_base.h:685
const char * get_ptr() const
Definition: string_base.h:635
int strcmp_partial_ex_t(const t_char *p_string, t_size p_string_length, const t_char *p_substring, t_size p_substring_length)
Definition: string_base.h:1080
const t_self & operator=(const t_char *p_source)
Definition: string_base.h:818
bool stringEqualsI_utf8(const char *p1, const char *p2)
t_size strcpy_utf8_truncate(const char *src, char *out, t_size maxbytes)
bool is_path_separator(unsigned c)
Definition: string_base.cpp:59
virtual void add_string(const char *p_string, t_size p_length=~0)=0
void splitStringByChar(t_out &out, const char *str, char c)
Definition: string_base.h:989
uint64_t t_uint64
Definition: int_types.h:3
void recover_invalid_utf8(const char *src, char *out, unsigned replace)
void truncate(t_size len)
Definition: string_base.h:390
static int compare(const char *p_item1, const char *p_item2)
Definition: string_base.h:851
format_array(t_source const &source, const char *separator=", ")
Definition: string_base.h:746
pfc::array_t< char, t_alloc > m_data
Definition: string_base.h:325
void splitStringSimple_toArray(t_array &p_output, t_split p_split, const char *p_string, t_size p_stringLen=~0)
Definition: string_base.h:955
string_simple_t(const t_char *p_source)
Definition: string_base.h:816
double string_to_float(const char *src, t_size max)
void truncate(t_size len)
Definition: string_base.h:303
bool operator>=(const string_base &p_other) const
Definition: string_base.h:230
format_char(char p_char)
Definition: string_base.h:656
t_uint atohex(const char *in, t_size inLen)
Definition: string_base.h:115
bool string_is_numeric(const char *p_string, t_size p_length)
pfc::string_base & operator<<(pfc::string_base &p_fmt, const char *p_source)
Definition: string_base.h:724
const char * get_ptr() const
Definition: string_base.h:623
string_simple_t(const t_char *p_source, t_size p_length)
Definition: string_base.h:817
void add_string_(const char *str)
Definition: string_base.h:344
const char * toString() const
Definition: string_base.h:569
void add_string_nc(const char *ptr, t_size len)
Definition: string_base.h:353
void delimit(const char *c)
Definition: string_base.h:246
const char * c_str() const
Definition: string_base.h:196
bool char_is_ascii_alpha(char p_char)
Definition: string_base.h:103
const char * get_ptr() const
Definition: string_base.h:705
const char * get_ptr() const
Definition: string_base.h:580
t_size utf8_encode_char(unsigned c, char *out)
Definition: utf8.cpp:113
const char * m_ptr
Definition: string_base.h:13
const char * utf8_char_next(const char *src)
Definition: string_base.h:190
void unlock_buffer()
Definition: string_base.h:417
const char * get_ptr() const
Definition: string_base.h:492
void splitStringEx(t_output &p_output, const t_splitCheck &p_check, const char *p_string, t_size p_stringLen=~0)
Definition: string_base.h:872
int _strcmp_partial_ex(const t_char *p_string, t_size p_string_length, const t_char *p_substring, t_size p_substring_length)
Definition: string_base.h:1070
int stricmp_ascii_ex(const char *const s1, t_size const len1, const char *const s2, t_size const len2)
t_size get_length() const
Definition: string_base.h:395
bool operator!=(const string_base &p_other) const
Definition: string_base.h:227
string_formatter m_formatter
Definition: string_base.h:627
bool is_multiline(const char *p_string, t_size p_len)
string_base_ref(const char *ptr)
Definition: string_base.h:1032
t_size wide_decode_char(const wchar_t *p_source, unsigned *p_out, t_size p_source_length=~0)
Definition: utf8.cpp:217
static int compare(string_part_ref p_item1, const char *p_item2)
Definition: string_base.h:844
const char * get_ptr() const
Definition: string_base.h:592
const char * get_ptr() const
Definition: string_base.h:568
bool string_has_suffix_i(const char *string, const char *suffix)
int strcmp_partial_ex(const char *str, t_size strLen, const char *substr, t_size substrLen)
Definition: string_base.h:1088
t_size scan_filename() const
Definition: string_base.h:235
format_pad_right(t_size p_chars, t_uint32 p_padding, const char *p_string, t_size p_string_length=~0)
Definition: string_base.h:691
void strcpy_t(char_t *out, const char_t *in)
Definition: string_base.h:141
void makespace(t_size s)
Definition: string_base.h:328
char_t ascii_toupper(char_t c)
Definition: string_base.h:61
unsigned int t_uint
Definition: int_types.h:12
t_size operator()(const char *p_string, t_size p_stringLen) const
Definition: string_base.h:908
int stringCompareCaseInsensitiveEx(string_part_ref s1, string_part_ref s2)
t_stringbuffer m_buffer
Definition: string_base.h:709
string_buffer(string_base &p_string, t_size p_requested_length)
Definition: string_base.h:460
string8_t< pfc::alloc_standard > string8
Definition: string_base.h:432
int naturalSortCompare(const char *s1, const char *s2)
void add_string(string_part_ref ref)
Definition: string_base.h:388
void prealloc(t_size p_size)
Definition: string_base.h:380
bool has_suffix_i(const char *suffix) const
Definition: string_base.h:266
format_hex_lowercase(const format_hex_lowercase &p_source)
Definition: string_base.h:603
static void g_swap(t_self &p_item1, t_self &p_item2)
Definition: string_base.h:426
t_size find_first(const char *p_string, t_size p_start=0) const
Definition: string_base.h:239
unsigned utf8_get_char(const char *src)
Definition: utf8.cpp:238
char_t ascii_tolower(char_t c)
Definition: string_base.h:60
const char * get_ptr() const
Definition: string_base.h:764
t_size operator()(const char *str, t_size len) const
Definition: string_base.h:924
const char * _get_ptr() const
Definition: string_base.h:340
static int compare(const char *i1, const char *i2)
Definition: string_base.h:857
string_fixed_t< 127 > m_buffer
Definition: string_base.h:495
t_uint atodec(const char *in, t_size inLen)
Definition: string_base.h:124
t_size utf8_char_len_from_header(char c)
Definition: utf8.cpp:10
bool char_is_hexnumeric(char p_char)
Definition: string_base.h:100
const t_char * c_str() const
Definition: string_base.h:821
bool has_prefix_i(const char *prefix) const
Definition: string_base.h:264
void urlEncode(pfc::string_base &out, const char *in)
bool utf8_advance(const char *&var)
Definition: string_base.h:178
int strcmp_ex(const char *p1, t_size n1, const char *p2, t_size n2)
pfc::array_t< t_char > m_buffer
Definition: string_base.h:823
void truncate(t_size len)
Definition: string_base.h:1038
t_size string_find_first_ex(const char *p_string, t_size p_string_length, char p_tofind, t_size p_start)
int stricmp_ascii_partial(const char *str, const char *substr)
const char *const m_ptr
Definition: string_base.h:1042
const char * get_ptr() const
Definition: string_base.h:382
const char * get_ptr() const
Definition: string_base.h:657
bool is_valid_utf8() const
Definition: string_base.h:217
t_size string_find_first_nc(const char *p_string, t_size p_string_length, char c, t_size p_start)
t_size strlen_utf8(const char *s, t_size num=~0)
Definition: utf8.cpp:316
void add_string(const char *ptr, t_size len)
Definition: string_base.h:295
void stringToLowerAppend(string_base &out, const char *src, t_size len)
string_simple_t< char > string_simple
Definition: string_base.h:826
bool operator<=(const string_base &p_other) const
Definition: string_base.h:231
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
string8_t(const char *p_string, t_size p_length)
Definition: string_base.h:375
t_size strlen_t(const t_char *p_string, t_size p_length=~0)
Definition: primitives.h:771
size_t t_size
Definition: int_types.h:48
string8_fastalloc string_formatter
Definition: string_base.h:615
void stringToBufferGuarded(TChar(&buffer)[len], const TSource &source)
Same as stringToBuffer() but throws exception_overflow() if the string could not be fully written...
Definition: string_base.h:1059
static void stringCombine(pfc::string_base &out, t_source const &in, const char *separator, const char *separatorLast)
Definition: string_base.h:860
double parse_timecode(const char *in)
t_uint64 get_used_scale() const
Definition: string_base.h:717
void set_size(t_size p_size)
Definition: array.h:104
const char * toString() const
Definition: string_base.h:659
format_hexdump_ex(const TWord *buffer, t_size bufLen, const char *spacing=" ")
Definition: string_base.h:758
string_base & _formatter() const
Definition: string_base.h:261
__splitStringSimple_arrayWrapper(t_array &p_array)
Definition: string_base.h:935
const char * toString() const
Definition: string_base.h:606
const char * toString() const
Definition: string_base.h:625
int strcmp_partial_t(const t_char *p_string, const t_char *p_substring)
Definition: string_base.h:1086
int strcmp_nc(const char *p1, size_t n1, const char *p2, size_t n2)
string_fixed_t(const string_fixed_t< max_length > &p_source)
Definition: string_base.h:276
t_uint64 atoui64_ex(const char *src, t_size len)
virtual char * lock_buffer(t_size p_requested_length)=0
const char * get_ptr() const
Definition: string_base.h:647
const char * toString() const
Definition: string_base.h:683
const char * toString() const
Definition: string_base.h:649
void prealloc(t_size p_size)
Definition: array.h:216
void urlEncodeAppendRaw(pfc::string_base &out, const char *in, t_size inSize)
static string_part_ref make(const char *ptr, t_size len)
Definition: string_base.h:17
void set_string_(const char *str)
Definition: string_base.h:343
t_size scan_filename(const char *ptr)
void set_string_(const char *str)
Definition: string_base.h:204
int compare_t(const hasher_md5_result &p_item1, const hasher_md5_result &p_item2)
Definition: hasher_md5.h:20
char * strdup_n(const char *src, t_size len)
Definition: string_base.cpp:75
virtual void set_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:198
void stringToUpperAppend(string_base &out, const char *src, t_size len)
string_fixed_t< 127 > m_buffer
Definition: string_base.h:485
t_size length() const
Definition: string_base.h:780
t_size strlen_max_t(const t_char *ptr, t_size max)
Definition: string_base.h:84
void set_string(const t_char *p_source)
Definition: string_base.h:795
void operator()(const char *p_string, t_size p_stringLen)
Definition: string_base.h:947
string8_t< t_alloc > t_self
Definition: string_base.h:323
void splitStringBySubstring(t_out &out, const char *str, const char *split)
Definition: string_base.h:999
bool is_empty() const
Definition: string_base.h:213
const char * get_ptr() const
Definition: string_base.h:556
const char * get_ptr() const
Definition: string_base.h:293
unsigned atoui_ex(const char *p_string, t_size p_string_len)
const string_fixed_t< max_length > & operator=(const char *p_source)
Definition: string_base.h:280
string8_t(const string_base &p_string)
Definition: string_base.h:377
static int compare(const wchar_t *item1, const wchar_t *item2)
Definition: string_base.h:836
t_int64 atoi64_ex(const char *src, t_size len)
const char * toString() const
Definition: string_base.h:593
string_formatter m_formatter
Definition: string_base.h:768
string8_t(const t_self &p_string)
Definition: string_base.h:376
string_formatter m_buffer
Definition: string_base.h:651
bool string_has_prefix_i(const char *string, const char *prefix)
t_size utf16_decode_char(const char16_t *p_source, unsigned *p_out, t_size p_source_length=~0)
Definition: utf8.cpp:181
t_size string_find_last_ex(const char *p_string, t_size p_string_length, char p_tofind, t_size p_start)
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
char * lock_buffer(t_size n)
Definition: string_base.h:409
bool string_has_prefix(const char *string, const char *prefix)
void urlEncodeAppend(pfc::string_base &out, const char *in)
uint32_t charLower(uint32_t param)
const char * toString() const
Definition: string_base.h:707
void add_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:1036
static int compare(const char *p_item1, string_part_ref p_item2)
Definition: string_base.h:838
void add_string_nc(const t_char *p_source, t_size p_length)
Definition: string_base.h:807
int naturalSortCompareI(const char *s1, const char *s2)
string_formatter m_formatter
Definition: string_base.h:640
bool operator>(const string_base &p_other) const
Definition: string_base.h:228
string8_t(string_part_ref ref)
Definition: string_base.h:378
std::exception exception
Definition: primitives.h:193
void float_to_string(char *out, t_size out_max, double val, unsigned precision, bool b_sign)
bool is_valid_utf8(const char *param, t_size max=~0)
Definition: utf8.cpp:264
char * lock_buffer(t_size p_requested_length)
Definition: string_base.h:1039
void stringToBuffer(TChar(&buffer)[len], const TSource &source)
Writes a string to a fixed-size buffer. Truncates the string if necessary. Always writes a null termi...
Definition: string_base.h:1048
const char * toString() const
Definition: string_base.h:206
t_size _strParamLen(const char *str)
Definition: string_base.h:7
uint32_t charUpper(uint32_t param)
void set_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:1037
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
bool has_suffix(const char *suffix) const
Definition: string_base.h:265
int strcmp_partial(const char *str, const char *substr)
Definition: string_base.h:1089
t_size array_size_t(const t_array &p_array)
Definition: primitives.h:309
t_size wide_encode_char(unsigned c, wchar_t *out)
Definition: utf8.cpp:227
int stringCompareCaseInsensitive(const char *s1, const char *s2)
string8_t< pfc::alloc_fast > string8_fast
Definition: string_base.h:433
string_part_ref string_part(const char *ptr, t_size len)
Definition: string_base.h:31
const char * toString() const
Definition: string_base.h:581
unsigned char_to_dec(char c)
void splitStringSimple_toList(t_list &p_output, t_split p_split, const char *p_string, t_size p_stringLen=~0)
Definition: string_base.h:970
int stricmp_ascii(const char *s1, const char *s2)
void add_byte(char c)
Definition: string_base.h:42
void add_string(const t_char *p_source)
Definition: string_base.h:804
static int compare(string_part_ref p_item1, string_part_ref p_item2)
Definition: string_base.h:841
bool char_is_numeric(char_t p_char)
Definition: string_base.h:99
format_uint(const format_uint &p_source)
Definition: string_base.h:579
bool char_is_ascii_alpha_lower(char p_char)
Definition: string_base.h:102
const string_fixed_t< max_length > & operator=(const string_fixed_t< max_length > &p_source)
Definition: string_base.h:279
bool char_is_ascii_alpha_upper(char p_char)
Definition: string_base.h:101
const char * get_ptr() const
Definition: string_base.h:515
t_size utf8_chars_to_bytes(const char *string, t_size count)
Definition: utf8.cpp:332
bool is_path_bad_char(unsigned c)
Definition: string_base.cpp:64
t_size const m_len
Definition: string_base.h:1043
void memcpy_t(t_dst *p_dst, const t_src *p_src, t_size p_count)
Definition: primitives.h:611
bool operator<(const string_base &p_other) const
Definition: string_base.h:229
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
void operator()(const char *p_string, t_size p_stringLen)
Definition: string_base.h:936
char format_hex_char(unsigned p_val)
format_pad_left(t_size p_chars, t_uint32 p_padding, const char *p_string, t_size p_string_length=~0)
Definition: string_base.h:667
const char * get_ptr() const
Definition: string_base.h:681
void force_reset()
Definition: array.h:132
void swap_t(T &p_item1, T &p_item2)
Definition: primitives.h:285
bool char_is_ascii_alphanumeric(char p_char)
Definition: string_base.h:104
format_hex(const format_hex &p_source)
Definition: string_base.h:591
void add_string_(const char *str)
Definition: string_base.h:39
__splitStringSimple_listWrapper(t_list &p_list)
Definition: string_base.h:946
format_float(const format_float &p_source)
Definition: string_base.h:554
const char * toString() const
Definition: string_base.h:766
t_size get_size() const
Definition: array.h:130
void truncate_filename()
Definition: string_base.h:255
void memset_t(T *p_buffer, const t_val &p_val, t_size p_count)
Definition: primitives.h:627
void add_string(const t_char *p_source, t_size p_length)
Definition: string_base.h:801
bool has_path_bad_chars(const char *param)
t_size utf8_char_len(const char *s, t_size max=~0)
Definition: utf8.cpp:246
static int compare(const char *p_item1, const char *p_item2)
Definition: string_base.h:835
bool is_lower_ascii(const char *param)
Definition: utf8.cpp:280
string8_t(const char *p_string)
Definition: string_base.h:374
void convert_to_lower_ascii(const char *src, t_size max, char *out, char replace)
t_size find_last(const char *p_string, t_size p_start=~0) const
Definition: string_base.h:240
t_size find_first(char p_char, t_size p_start=0) const
Definition: string_base.h:237
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
t_size length() const
Definition: string_base.h:516
const char * get_ptr() const
Definition: string_base.h:1033
void force_reset()
Definition: string_base.h:424
t_size tcslen_max(const TCHAR *ptr, t_size max)
Definition: string_base.h:95
static string_part_ref stringToRef(T const &val)
Definition: string_base.h:1023
const t_char * get_ptr() const
Definition: string_base.h:820
uint32_t t_uint32
Definition: int_types.h:5
void add_filename(const char *fn)
Definition: string_base.h:257
bool is_empty() const
Definition: string_base.h:784
t_size wcslen_max(const wchar_t *ptr, t_size max)
Definition: string_base.h:92
const char * get_ptr() const
Definition: string_base.h:482
int64_t t_int64
Definition: int_types.h:2
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
const char * toString() const
Definition: string_base.h:518
const char * get_ptr() const
Definition: string_base.h:604
t_size get_length() const
Definition: string_base.h:1034
const char * toString() const
Definition: string_base.h:637
string_simple_t< t_char > t_self
Definition: string_base.h:778
string8_t< pfc::alloc_fast_aggressive > string8_fast_aggressive
Definition: string_base.h:434
bool is_owned(const t_source &p_item)
Definition: array.h:230