foobar2000 SDK  2015-08-03
Public Member Functions | Protected Member Functions
pfc::string_baseabstract

#include <string_base.h>

+ Inheritance diagram for pfc::string_base:

Public Member Functions

string_base_formatter () const
 
void add_filename (const char *fn)
 
virtual void add_string (const char *p_string, t_size p_length=~0)=0
 
const char * c_str () const
 
void convert_to_lower_ascii (const char *src, char replace= '?')
 
void delimit (const char *c)
 
void end_with (char c)
 
void end_with_slash ()
 
bool ends_with (char c) const
 
t_size find_first (char p_char, t_size p_start=0) const
 
t_size find_first (const char *p_string, t_size p_start=0) const
 
t_size find_last (char p_char, t_size p_start=~0) const
 
t_size find_last (const char *p_string, t_size p_start=~0) const
 
void fix_dir_separator (char c= '\\')
 
bool fix_eol (const char *append=" (...)", t_size start=0)
 
virtual t_size get_length () const
 
virtual const char * get_ptr () const =0
 
bool has_prefix (const char *prefix) const
 
bool has_prefix_i (const char *prefix) const
 
bool has_suffix (const char *suffix) const
 
bool has_suffix_i (const char *suffix) const
 
bool is_empty () const
 
bool is_valid_utf8 () const
 
char last_char () const
 
t_size length () const
 
bool limit_length (t_size length_in_chars, const char *append=" (...)")
 
virtual char * lock_buffer (t_size p_requested_length)=0
 
 operator const char * () const
 
bool operator!= (const string_base &p_other) const
 
const string_baseoperator+= (const char *src)
 
const string_baseoperator+= (const string_base &src)
 
bool operator< (const string_base &p_other) const
 
bool operator<= (const string_base &p_other) const
 
const string_baseoperator= (const char *src)
 
const string_baseoperator= (const string_base &src)
 
bool operator== (const string_base &p_other) const
 
bool operator> (const string_base &p_other) const
 
bool operator>= (const string_base &p_other) const
 
t_size replace_string (const char *replace, const char *replaceWith, t_size start=0)
 
void reset ()
 
t_size scan_filename () const
 
virtual void set_string (const char *p_string, t_size p_length=~0)
 
void set_string_ (const char *str)
 
void skip_trailing_char (unsigned c= ' ')
 
const char * toString () const
 
virtual void truncate (t_size len)=0
 
bool truncate_eol (t_size start=0)
 
void truncate_filename ()
 
void truncate_last_char ()
 
void truncate_number_suffix ()
 
void truncate_to_parent_path ()
 
virtual void unlock_buffer ()=0
 
- Public Member Functions inherited from pfc::string_receiver
void add_byte (char c)
 
void add_char (t_uint32 c)
 
void add_chars (t_uint32 p_char, t_size p_count)
 
void add_string_ (const char *str)
 

Protected Member Functions

 string_base ()
 
 ~string_base ()
 
- Protected Member Functions inherited from pfc::string_receiver
 string_receiver ()
 
 ~string_receiver ()
 

Detailed Description

Definition at line 193 of file string_base.h.

Constructor & Destructor Documentation

pfc::string_base::string_base ( )
inlineprotected

Definition at line 268 of file string_base.h.

268 {}
pfc::string_base::~string_base ( )
inlineprotected

Definition at line 269 of file string_base.h.

269 {}

Member Function Documentation

string_base& pfc::string_base::_formatter ( ) const
inline

Definition at line 261 of file string_base.h.

261 {return const_cast<string_base&>(*this);}
void pfc::string_base::add_filename ( const char *  fn)
inline

Definition at line 257 of file string_base.h.

257 {end_with_slash(); *this += fn; }
virtual void pfc::string_base::add_string ( const char *  p_string,
t_size  p_length = ~0 
)
pure virtual
const char* pfc::string_base::c_str ( ) const
inline

Definition at line 196 of file string_base.h.

196 { return get_ptr(); }
virtual const char * get_ptr() const =0
void pfc::string_base::convert_to_lower_ascii ( const char *  src,
char  replace = '?' 
)

Definition at line 257 of file string_base.cpp.

258 {
259  reset();
260  PFC_ASSERT(replace>0);
261  while(*src)
262  {
263  unsigned c;
264  t_size delta = utf8_decode_char(src,c);
265  if (delta==0) {c = replace; delta = 1;}
266  else if (c>=0x80) c = replace;
267  add_byte((char)c);
268  src += delta;
269  }
270 }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
void add_byte(char c)
Definition: string_base.h:42
void pfc::string_base::delimit ( const char *  c)
inline

Definition at line 246 of file string_base.h.

246 {if (length()>0) add_string(c);}
virtual void add_string(const char *p_string, t_size p_length=~0)=0
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
void pfc::string_base::end_with ( char  c)

Definition at line 780 of file string_base.cpp.

780  {
781  if (!ends_with(p_char)) add_byte(p_char);
782 }
bool ends_with(char c) const
void add_byte(char c)
Definition: string_base.h:42
void pfc::string_base::end_with_slash ( )

Definition at line 788 of file string_base.cpp.

788  {
790 }
void end_with(char c)
char getDefaultSeparator()
Definition: pathUtils.cpp:124
bool pfc::string_base::ends_with ( char  c) const

Definition at line 783 of file string_base.cpp.

783  {
785  return length > 0 && get_ptr()[length-1] == c;
786 }
virtual t_size get_length() const
Definition: string_base.h:200
size_t t_size
Definition: int_types.h:48
virtual const char * get_ptr() const =0
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
t_size pfc::string_base::find_first ( char  p_char,
t_size  p_start = 0 
) const
inline

Definition at line 237 of file string_base.h.

237 {return pfc::string_find_first(get_ptr(),p_char,p_start);}
virtual const char * get_ptr() const =0
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string_base::find_first ( const char *  p_string,
t_size  p_start = 0 
) const
inline

Definition at line 239 of file string_base.h.

239 {return pfc::string_find_first(get_ptr(),p_string,p_start);}
virtual const char * get_ptr() const =0
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string_base::find_last ( char  p_char,
t_size  p_start = ~0 
) const
inline

Definition at line 238 of file string_base.h.

238 {return pfc::string_find_last(get_ptr(),p_char,p_start);}
virtual const char * get_ptr() const =0
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string_base::find_last ( const char *  p_string,
t_size  p_start = ~0 
) const
inline

Definition at line 240 of file string_base.h.

240 {return pfc::string_find_last(get_ptr(),p_string,p_start);}
virtual const char * get_ptr() const =0
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
void pfc::string_base::fix_dir_separator ( char  c = '\\')

Definition at line 1167 of file string_base.cpp.

1167  {
1168 #ifdef _WIN32
1169  end_with(c);
1170 #else
1171  end_with_slash();
1172 #endif
1173 }
void end_with(char c)
bool pfc::string_base::fix_eol ( const char *  append = " (...)",
t_size  start = 0 
)

Definition at line 988 of file string_base.cpp.

989 {
990  const bool rv = truncate_eol(start);
991  if (rv) add_string(append);
992  return rv;
993 }
virtual void add_string(const char *p_string, t_size p_length=~0)=0
bool truncate_eol(t_size start=0)
virtual t_size pfc::string_base::get_length ( ) const
inlinevirtual
virtual const char* pfc::string_base::get_ptr ( ) const
pure virtual
bool pfc::string_base::has_prefix ( const char *  prefix) const
inline

Definition at line 263 of file string_base.h.

263 { return string_has_prefix( get_ptr(), prefix ); }
bool string_has_prefix(const char *string, const char *prefix)
virtual const char * get_ptr() const =0
bool pfc::string_base::has_prefix_i ( const char *  prefix) const
inline

Definition at line 264 of file string_base.h.

264 { return string_has_prefix_i( get_ptr(), prefix); }
bool string_has_prefix_i(const char *string, const char *prefix)
virtual const char * get_ptr() const =0
bool pfc::string_base::has_suffix ( const char *  suffix) const
inline

Definition at line 265 of file string_base.h.

265 { return string_has_suffix( get_ptr(), suffix); }
bool string_has_suffix(const char *string, const char *suffix)
virtual const char * get_ptr() const =0
bool pfc::string_base::has_suffix_i ( const char *  suffix) const
inline

Definition at line 266 of file string_base.h.

266 { return string_has_suffix_i( get_ptr(), suffix); }
bool string_has_suffix_i(const char *string, const char *suffix)
virtual const char * get_ptr() const =0
bool pfc::string_base::is_empty ( ) const
inline

Definition at line 213 of file string_base.h.

213 {return *get_ptr()==0;}
virtual const char * get_ptr() const =0
bool pfc::string_base::is_valid_utf8 ( ) const
inline

Definition at line 217 of file string_base.h.

217 {return pfc::is_valid_utf8(get_ptr());}
bool is_valid_utf8(const char *param, t_size max=~0)
Definition: utf8.cpp:264
virtual const char * get_ptr() const =0
char pfc::string_base::last_char ( ) const

Definition at line 792 of file string_base.cpp.

792  {
793  size_t l = this->length();
794  if (l == 0) return 0;
795  return this->get_ptr()[l-1];
796 }
virtual const char * get_ptr() const =0
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
t_size pfc::string_base::length ( ) const
inline

For compatibility with old conventions.

Definition at line 209 of file string_base.h.

209 {return get_length();}
virtual t_size get_length() const
Definition: string_base.h:200
bool pfc::string_base::limit_length ( t_size  length_in_chars,
const char *  append = " (...)" 
)

Definition at line 995 of file string_base.cpp.

996 {
997  bool rv = false;
998  const char * base = get_ptr(), * ptr = base;
999  while(length_in_chars && utf8_advance(ptr)) length_in_chars--;
1000  if (length_in_chars==0)
1001  {
1002  truncate(ptr-base);
1003  add_string(append);
1004  rv = true;
1005  }
1006  return rv;
1007 }
virtual void add_string(const char *p_string, t_size p_length=~0)=0
bool utf8_advance(const char *&var)
Definition: string_base.h:178
virtual const char * get_ptr() const =0
virtual void truncate(t_size len)=0
virtual char* pfc::string_base::lock_buffer ( t_size  p_requested_length)
pure virtual
pfc::string_base::operator const char * ( ) const
inline

Definition at line 233 of file string_base.h.

233 {return get_ptr();}
virtual const char * get_ptr() const =0
bool pfc::string_base::operator!= ( const string_base p_other) const
inline

Definition at line 227 of file string_base.h.

227 {return strcmp(*this,p_other) != 0;}
const string_base& pfc::string_base::operator+= ( const char *  src)
inline

Definition at line 222 of file string_base.h.

222 {add_string_(src);return *this;}
void add_string_(const char *str)
Definition: string_base.h:39
const string_base& pfc::string_base::operator+= ( const string_base src)
inline

Definition at line 224 of file string_base.h.

224 {add_string(src);return *this;}
virtual void add_string(const char *p_string, t_size p_length=~0)=0
bool pfc::string_base::operator< ( const string_base p_other) const
inline

Definition at line 229 of file string_base.h.

229 {return strcmp(*this,p_other) < 0;}
bool pfc::string_base::operator<= ( const string_base p_other) const
inline

Definition at line 231 of file string_base.h.

231 {return strcmp(*this,p_other) <= 0;}
const string_base& pfc::string_base::operator= ( const char *  src)
inline

Definition at line 221 of file string_base.h.

221 {set_string_(src);return *this;}
void set_string_(const char *str)
Definition: string_base.h:204
const string_base& pfc::string_base::operator= ( const string_base src)
inline

Definition at line 223 of file string_base.h.

223 {set_string(src);return *this;}
virtual void set_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:198
bool pfc::string_base::operator== ( const string_base p_other) const
inline

Definition at line 226 of file string_base.h.

226 {return strcmp(*this,p_other) == 0;}
bool pfc::string_base::operator> ( const string_base p_other) const
inline

Definition at line 228 of file string_base.h.

228 {return strcmp(*this,p_other) > 0;}
bool pfc::string_base::operator>= ( const string_base p_other) const
inline

Definition at line 230 of file string_base.h.

230 {return strcmp(*this,p_other) >= 0;}
t_size pfc::string_base::replace_string ( const char *  replace,
const char *  replaceWith,
t_size  start = 0 
)

Definition at line 1029 of file string_base.cpp.

1029  {
1030  string_formatter temp;
1031  size_t srcDone = 0, walk = start;
1032  size_t occurances = 0;
1033  const char * const source = this->get_ptr();
1034 
1035  const size_t replaceLen = strlen( replace );
1036  for(;;) {
1037  const char * ptr = strstr( source + walk, replace );
1038  if (ptr == NULL) {
1039  // end
1040  if (srcDone == 0) {
1041  return 0; // string not altered
1042  }
1043  temp.add_string( source + srcDone );
1044  break;
1045  }
1046  ++occurances;
1047  walk = ptr - source;
1048  temp.add_string( source + srcDone, walk - srcDone );
1049  temp.add_string( replaceWith );
1050  walk += replaceLen;
1051  srcDone = walk;
1052  }
1053  this->set_string( temp );
1054  return occurances;
1055 
1056 }
string8_fastalloc string_formatter
Definition: string_base.h:615
virtual void set_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:198
virtual const char * get_ptr() const =0
void pfc::string_base::reset ( )
inline

Definition at line 211 of file string_base.h.

211 {truncate(0);}
virtual void truncate(t_size len)=0
t_size pfc::string_base::scan_filename ( ) const
inline

Definition at line 235 of file string_base.h.

235 {return pfc::scan_filename(get_ptr());}
t_size scan_filename(const char *ptr)
virtual const char * get_ptr() const =0
virtual void pfc::string_base::set_string ( const char *  p_string,
t_size  p_length = ~0 
)
inlinevirtual

Reimplemented in pfc::string_base_ref, pfc::string8_t< t_alloc >, pfc::string8_t< pfc::alloc_standard >, string_formatter_tf, and pfc::__stringEmpty.

Definition at line 198 of file string_base.h.

198 {reset();add_string(p_string,p_length);}
virtual void add_string(const char *p_string, t_size p_length=~0)=0
void pfc::string_base::set_string_ ( const char *  str)
inline

Definition at line 204 of file string_base.h.

204 {set_string(str, _strParamLen(str));}
virtual void set_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:198
t_size _strParamLen(const char *str)
Definition: string_base.h:7
void pfc::string_base::skip_trailing_char ( unsigned  c = ' ')

Definition at line 12 of file string_base.cpp.

13 {
14  const char * str = get_ptr();
15  t_size ptr,trunc = 0;
16  bool need_trunc = false;
17  for(ptr=0;str[ptr];)
18  {
19  unsigned c;
20  t_size delta = utf8_decode_char(str+ptr,c);
21  if (delta==0) break;
22  if (c==skip)
23  {
24  need_trunc = true;
25  trunc = ptr;
26  }
27  else
28  {
29  need_trunc = false;
30  }
31  ptr += delta;
32  }
33  if (need_trunc) truncate(trunc);
34 }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
virtual const char * get_ptr() const =0
virtual void truncate(t_size len)=0
const char* pfc::string_base::toString ( ) const
inline

Definition at line 206 of file string_base.h.

206 {return get_ptr();}
virtual const char * get_ptr() const =0
virtual void pfc::string_base::truncate ( t_size  len)
pure virtual
bool pfc::string_base::truncate_eol ( t_size  start = 0)

Definition at line 973 of file string_base.cpp.

974 {
975  const char * ptr = get_ptr() + start;
976  for(t_size n=start;*ptr;n++)
977  {
978  if (*ptr==10 || *ptr==13)
979  {
980  truncate(n);
981  return true;
982  }
983  ptr++;
984  }
985  return false;
986 }
size_t t_size
Definition: int_types.h:48
virtual const char * get_ptr() const =0
virtual void truncate(t_size len)=0
void pfc::string_base::truncate_filename ( )
inline

Definition at line 255 of file string_base.h.

t_size scan_filename() const
Definition: string_base.h:235
virtual void truncate(t_size len)=0
void pfc::string_base::truncate_last_char ( )

Definition at line 797 of file string_base.cpp.

797  {
798  size_t l = this->length();
799  if (l > 0) this->truncate( l - 1 );
800 }
virtual void truncate(t_size len)=0
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
void pfc::string_base::truncate_number_suffix ( )

Definition at line 802 of file string_base.cpp.

802  {
803  size_t l = this->length();
804  const char * const p = this->get_ptr();
805  while( l > 0 && char_is_numeric( p[l-1] ) ) --l;
806  truncate( l );
807 }
virtual const char * get_ptr() const =0
bool char_is_numeric(char_t p_char)
Definition: string_base.h:99
virtual void truncate(t_size len)=0
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
void pfc::string_base::truncate_to_parent_path ( )

Definition at line 1009 of file string_base.cpp.

1009  {
1010  size_t at = scan_filename();
1011 #ifdef _WIN32
1012  while(at > 0 && (*this)[at-1] == '\\') --at;
1013  if (at > 0 && (*this)[at-1] == ':' && (*this)[at] == '\\') ++at;
1014 #else
1015  // Strip trailing /
1016  while(at > 0 && (*this)[at-1] == '/') --at;
1017 
1018  // Hit empty? Bring root / back to life
1019  if (at == 0 && (*this)[0] == '/') ++at;
1020 
1021  // Deal with proto://
1022  if (at > 0 && (*this)[at-1] == ':') {
1023  while((*this)[at] == '/') ++at;
1024  }
1025 #endif
1026  this->truncate( at );
1027 }
t_size scan_filename() const
Definition: string_base.h:235
virtual void truncate(t_size len)=0
virtual void pfc::string_base::unlock_buffer ( )
pure virtual

The documentation for this class was generated from the following files: