foobar2000 SDK  2015-08-03
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
pfc::string

#include <stringNew.h>

Data Structures

class  _comparatorCommon
 
class  comparatorCaseInsensitive
 
class  comparatorCaseInsensitiveASCII
 
class  comparatorCaseSensitive
 

Public Types

typedef rcptr_t< string_base const > t_data
 
typedef rcptr_t< string8t_dataImpl
 

Public Member Functions

 string ()
 
 string (const char *p_source)
 
 string (const char *p_source, t_size p_sourceLen)
 
 string (char *p_source)
 
 string (char *p_source, t_size p_sourceLen)
 
 string (t_data const &p_source)
 
 string (string_part_ref source)
 
template<typename TSource >
 string (const TSource &p_source)
 
 string (const string &other)
 
 string (string &&other)
 
t_data _content () const
 
const char * c_str () const
 
string clone () const
 
bool contains (char c) const
 
bool contains (stringp s) const
 
bool containsAnyChar (stringp s) const
 
bool endsWith (char c) const
 
bool endsWith (string s) const
 
char firstChar () const
 
t_size get_length () const
 
const char * get_ptr () const
 
t_size indexOf (char c, t_size base=0) const
 
t_size indexOf (stringp s, t_size base=0) const
 
t_size indexOfAnyChar (stringp s, t_size base=0) const
 
bool isEmpty () const
 
char lastChar () const
 
t_size lastIndexOf (char c, t_size base=~0) const
 
t_size lastIndexOf (stringp s, t_size base=~0) const
 
t_size lastIndexOfAnyChar (stringp s, t_size base=~0) const
 
t_size length () const
 
bool operator!= (const string &p_other) const
 
string operator+ (const string &p_item2) const
 
string operator+ (const char *p_item2) const
 
template<typename TSource >
string operator+ (const TSource &p_item2) const
 
template<typename TSource >
const stringoperator+= (const TSource &p_item)
 
bool operator< (const string &p_other) const
 
bool operator<= (const string &p_other) const
 
const stringoperator= (const string &other)
 
const stringoperator= (string &&other)
 
bool operator== (const string &p_other) const
 
bool operator> (const string &p_other) const
 
bool operator>= (const string &p_other) const
 
char operator[] (t_size p_index) const
 
const char * ptr () const
 
string replace (stringp strOld, stringp strNew) const
 
void set_string (const char *ptr, t_size len=~0)
 
bool startsWith (char c) const
 
bool startsWith (string s) const
 
string subString (t_size base) const
 
string subString (t_size base, t_size count) const
 
string toLower () const
 
string const & toString () const
 
string toUpper () const
 

Static Public Member Functions

static int g_compare (const string &p_item1, const string &p_item2)
 
static string g_concatenateRaw (const char *item1, t_size len1, const char *item2, t_size len2)
 
static bool g_equals (const string &p_item1, const string &p_item2)
 
static bool g_equalsCaseInsensitive (const string &p_item1, const string &p_item2)
 
static bool isNonTextChar (char c)
 

Private Attributes

t_data m_content
 

Detailed Description

New EXPERIMENTAL string class, allowing efficient copies and returning from functions.
Does not implement the string_base interface so you still need string8 in many cases.
Safe to pass between DLLs, but since a reference is used, objects possibly created by other DLLs must be released before owning DLLs are unloaded.

Definition at line 19 of file stringNew.h.

Member Typedef Documentation

Definition at line 21 of file stringNew.h.

Definition at line 22 of file stringNew.h.

Constructor & Destructor Documentation

pfc::string::string ( )
inline

Definition at line 24 of file stringNew.h.

24 : m_content(rcnew_t<__stringEmpty>()) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( const char *  p_source)
inline

Definition at line 25 of file stringNew.h.

25 : m_content(rcnew_t<string8>(p_source)) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( const char *  p_source,
t_size  p_sourceLen 
)
inline

Definition at line 26 of file stringNew.h.

26 : m_content(rcnew_t<string8>(p_source,p_sourceLen)) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( char *  p_source)
inline

Definition at line 27 of file stringNew.h.

27 : m_content(rcnew_t<string8>(p_source)) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( char *  p_source,
t_size  p_sourceLen 
)
inline

Definition at line 28 of file stringNew.h.

28 : m_content(rcnew_t<string8>(p_source,p_sourceLen)) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( t_data const &  p_source)
inline

Definition at line 29 of file stringNew.h.

29 : m_content(p_source) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( string_part_ref  source)
inline

Definition at line 30 of file stringNew.h.

30 : m_content(rcnew_t<string8>(source)) {}
t_data m_content
Definition: stringNew.h:201
template<typename TSource >
pfc::string::string ( const TSource &  p_source)

Definition at line 216 of file stringNew.h.

216  {
217  *this = pfc::toString(p_source);
218  }
string toString(T const &val)
Definition: stringNew.h:204
pfc::string::string ( const string other)
inline

Definition at line 33 of file stringNew.h.

33 : m_content(other.m_content) {}
t_data m_content
Definition: stringNew.h:201
pfc::string::string ( string &&  other)
inline

Definition at line 34 of file stringNew.h.

34 : m_content(std::move(other.m_content)) {}
t_data m_content
Definition: stringNew.h:201

Member Function Documentation

t_data pfc::string::_content ( ) const
inline

Definition at line 199 of file stringNew.h.

199 {return m_content;}
t_data m_content
Definition: stringNew.h:201
const char* pfc::string::c_str ( ) const
inline

Definition at line 126 of file stringNew.h.

126 { return get_ptr(); }
const char * get_ptr() const
Definition: stringNew.h:125
string pfc::string::clone ( ) const
inline

Definition at line 86 of file stringNew.h.

86 {return string(ptr());}
const char * ptr() const
Definition: stringNew.h:124
bool pfc::string::contains ( char  c) const

Definition at line 79 of file stringNew.cpp.

79 {return indexOf(c) != ~0;}
t_size indexOf(char c, t_size base=0) const
Definition: stringNew.cpp:5
bool pfc::string::contains ( stringp  s) const

Definition at line 80 of file stringNew.cpp.

80 {return indexOf(s) != ~0;}
t_size indexOf(char c, t_size base=0) const
Definition: stringNew.cpp:5
bool pfc::string::containsAnyChar ( stringp  s) const

Definition at line 81 of file stringNew.cpp.

81 {return indexOfAnyChar(s) != ~0;}
t_size indexOfAnyChar(stringp s, t_size base=0) const
Definition: stringNew.cpp:17
bool pfc::string::endsWith ( char  c) const

Definition at line 47 of file stringNew.cpp.

47  {
48  const t_size len = length();
49  if (len == 0) return false;
50  return ptr()[len-1] == c;
51 }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
size_t t_size
Definition: int_types.h:48
bool pfc::string::endsWith ( string  s) const

Definition at line 52 of file stringNew.cpp.

52  {
53  const t_size len = length(), subLen = s.length();
54  if (subLen > len) return false;
55  return subString(len - subLen) == s;
56 }
t_size length() const
Definition: stringNew.h:127
string subString(t_size base) const
Definition: stringNew.h:67
size_t t_size
Definition: int_types.h:48
char pfc::string::firstChar ( ) const

Definition at line 58 of file stringNew.cpp.

58  {
59  return (*this)[0];
60 }
static int pfc::string::g_compare ( const string p_item1,
const string p_item2 
)
inlinestatic

Definition at line 116 of file stringNew.h.

116 {return strcmp(p_item1.ptr(),p_item2.ptr());}
static string pfc::string::g_concatenateRaw ( const char *  item1,
t_size  len1,
const char *  item2,
t_size  len2 
)
inlinestatic

Definition at line 43 of file stringNew.h.

43  {
44  t_dataImpl impl; impl.new_t();
45  char * buffer = impl->lock_buffer(len1+len2);
46  memcpy_t(buffer,item1,len1);
47  memcpy_t(buffer+len1,item2,len2);
48  impl->unlock_buffer();
49  return string(t_data(impl));
50  }
rcptr_t< string8 > t_dataImpl
Definition: stringNew.h:22
rcptr_t< string_base const > t_data
Definition: stringNew.h:21
void memcpy_t(t_dst *p_dst, const t_src *p_src, t_size p_count)
Definition: primitives.h:611
static bool pfc::string::g_equals ( const string p_item1,
const string p_item2 
)
inlinestatic

Definition at line 196 of file stringNew.h.

196 {return p_item1 == p_item2;}
static bool pfc::string::g_equalsCaseInsensitive ( const string p_item1,
const string p_item2 
)
inlinestatic

Definition at line 197 of file stringNew.h.

197 {return comparatorCaseInsensitive::compare(p_item1,p_item2) == 0;}
static int compare(T1 const &v1, T2 const &v2)
Definition: stringNew.h:170
t_size pfc::string::get_length ( ) const
inline

Definition at line 128 of file stringNew.h.

128 {return m_content->get_length();}
virtual t_size get_length() const
Definition: string_base.h:200
t_data m_content
Definition: stringNew.h:201
const char* pfc::string::get_ptr ( ) const
inline

Definition at line 125 of file stringNew.h.

125 {return m_content->get_ptr();}
t_data m_content
Definition: stringNew.h:201
virtual const char * get_ptr() const =0
t_size pfc::string::indexOf ( char  c,
t_size  base = 0 
) const
Returns
~0 if not found.

Definition at line 5 of file stringNew.cpp.

5  {
6  return pfc::string_find_first(ptr(),c,base);
7 }
const char * ptr() const
Definition: stringNew.h:124
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string::indexOf ( stringp  s,
t_size  base = 0 
) const
Returns
~0 if not found.

Definition at line 11 of file stringNew.cpp.

11  {
12  return pfc::string_find_first(ptr(),s.ptr(),base);
13 }
const char * ptr() const
Definition: stringNew.h:124
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string::indexOfAnyChar ( stringp  s,
t_size  base = 0 
) const
Returns
~0 if not found.

Definition at line 17 of file stringNew.cpp.

17  {
18  string s ( _s );
19  const t_size len = length();
20  const char* content = ptr();
21  for(t_size walk = 0; walk < len; ++walk) {
22  if (s.contains(content[walk])) return walk;
23  }
24  return ~0;
25 }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
size_t t_size
Definition: int_types.h:48
bool pfc::string::isEmpty ( ) const
inline

Definition at line 140 of file stringNew.h.

140 {return length() == 0;}
t_size length() const
Definition: stringNew.h:127
static bool pfc::string::isNonTextChar ( char  c)
inlinestatic

Definition at line 134 of file stringNew.h.

134 {return c >= 0 && c < 32;}
char pfc::string::lastChar ( ) const

Definition at line 61 of file stringNew.cpp.

61  {
62  const t_size len = length();
63  return len > 0 ? (*this)[len-1] : (char)0;
64 }
t_size length() const
Definition: stringNew.h:127
size_t t_size
Definition: int_types.h:48
t_size pfc::string::lastIndexOf ( char  c,
t_size  base = ~0 
) const
Returns
~0 if not found.

Definition at line 8 of file stringNew.cpp.

8  {
9  return pfc::string_find_last(ptr(),c,base);
10 }
const char * ptr() const
Definition: stringNew.h:124
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string::lastIndexOf ( stringp  s,
t_size  base = ~0 
) const
Returns
~0 if not found.

Definition at line 14 of file stringNew.cpp.

14  {
15  return pfc::string_find_last(ptr(),s.ptr(),base);
16 }
const char * ptr() const
Definition: stringNew.h:124
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
t_size pfc::string::lastIndexOfAnyChar ( stringp  s,
t_size  base = ~0 
) const
Returns
~0 if not found.

Definition at line 26 of file stringNew.cpp.

26  {
27  string s ( _s );
28  const char* content = ptr();
29  for(t_size _walk = length(); _walk > 0; --_walk) {
30  const t_size walk = _walk-1;
31  if (s.contains(content[walk])) return walk;
32  }
33  return ~0;
34 }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
size_t t_size
Definition: int_types.h:48
t_size pfc::string::length ( ) const
inline

Definition at line 127 of file stringNew.h.

127 {return m_content->get_length();}
virtual t_size get_length() const
Definition: string_base.h:200
t_data m_content
Definition: stringNew.h:201
bool pfc::string::operator!= ( const string p_other) const
inline

Definition at line 118 of file stringNew.h.

118 {return g_compare(*this,p_other) != 0;}
static int g_compare(const string &p_item1, const string &p_item2)
Definition: stringNew.h:116
string pfc::string::operator+ ( const string p_item2) const
inline

Definition at line 52 of file stringNew.h.

52  {
53  return g_concatenateRaw(ptr(),length(),p_item2.ptr(),p_item2.length());
54  }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
static string g_concatenateRaw(const char *item1, t_size len1, const char *item2, t_size len2)
Definition: stringNew.h:43
string pfc::string::operator+ ( const char *  p_item2) const
inline

Definition at line 55 of file stringNew.h.

55  {
56  return g_concatenateRaw(ptr(),length(),p_item2,strlen(p_item2));
57  }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
static string g_concatenateRaw(const char *item1, t_size len1, const char *item2, t_size len2)
Definition: stringNew.h:43
template<typename TSource >
string pfc::string::operator+ ( const TSource &  p_item2) const

Definition at line 219 of file stringNew.h.

219  {
220  return *this + pfc::toString(p_item2);
221  }
string toString(T const &val)
Definition: stringNew.h:204
template<typename TSource >
const string& pfc::string::operator+= ( const TSource &  p_item)
inline

Definition at line 62 of file stringNew.h.

62  {
63  *this = *this + p_item;
64  return *this;
65  }
bool pfc::string::operator< ( const string p_other) const
inline

Definition at line 119 of file stringNew.h.

119 {return g_compare(*this,p_other) < 0;}
static int g_compare(const string &p_item1, const string &p_item2)
Definition: stringNew.h:116
bool pfc::string::operator<= ( const string p_other) const
inline

Definition at line 121 of file stringNew.h.

121 {return g_compare(*this,p_other) <= 0;}
static int g_compare(const string &p_item1, const string &p_item2)
Definition: stringNew.h:116
const string& pfc::string::operator= ( const string other)
inline

Definition at line 36 of file stringNew.h.

36 {m_content = other.m_content; return *this;}
t_data m_content
Definition: stringNew.h:201
const string& pfc::string::operator= ( string &&  other)
inline

Definition at line 37 of file stringNew.h.

37 {m_content = std::move(other.m_content); return *this;}
t_data m_content
Definition: stringNew.h:201
bool pfc::string::operator== ( const string p_other) const
inline

Definition at line 117 of file stringNew.h.

117 {return g_compare(*this,p_other) == 0;}
static int g_compare(const string &p_item1, const string &p_item2)
Definition: stringNew.h:116
bool pfc::string::operator> ( const string p_other) const
inline

Definition at line 120 of file stringNew.h.

120 {return g_compare(*this,p_other) > 0;}
static int g_compare(const string &p_item1, const string &p_item2)
Definition: stringNew.h:116
bool pfc::string::operator>= ( const string p_other) const
inline

Definition at line 122 of file stringNew.h.

122 {return g_compare(*this,p_other) >= 0;}
static int g_compare(const string &p_item1, const string &p_item2)
Definition: stringNew.h:116
char pfc::string::operator[] ( t_size  p_index) const
inline

Definition at line 136 of file stringNew.h.

136  {
137  PFC_ASSERT(p_index <= length());
138  return ptr()[p_index];
139  }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
const char* pfc::string::ptr ( ) const
inline

Definition at line 124 of file stringNew.h.

124 {return m_content->get_ptr();}
t_data m_content
Definition: stringNew.h:201
virtual const char * get_ptr() const =0
string pfc::string::replace ( stringp  strOld,
stringp  strNew 
) const

Definition at line 66 of file stringNew.cpp.

66  {
67  t_size walk = 0;
68  string ret;
69  for(;;) {
70  t_size next = indexOf(strOld, walk);
71  if (next == ~0) {
72  ret += subString(walk); break;
73  }
74  ret += subString(walk,next-walk) + strNew;
75  walk = next + strOld.length();
76  }
77  return ret;
78 }
t_size length() const
Definition: stringNew.h:127
string subString(t_size base) const
Definition: stringNew.h:67
size_t t_size
Definition: int_types.h:48
t_size indexOf(char c, t_size base=0) const
Definition: stringNew.cpp:5
void pfc::string::set_string ( const char *  ptr,
t_size  len = ~0 
)
inline

Definition at line 130 of file stringNew.h.

130  {
131  *this = string(ptr, len);
132  }
const char * ptr() const
Definition: stringNew.h:124
bool pfc::string::startsWith ( char  c) const

Definition at line 35 of file stringNew.cpp.

35  {
36  return (*this)[0] == c;
37 }
bool pfc::string::startsWith ( string  s) const

Definition at line 38 of file stringNew.cpp.

38  {
39  const char * walk = ptr();
40  const char * subWalk = s.ptr();
41  for(;;) {
42  if (*subWalk == 0) return true;
43  if (*walk != *subWalk) return false;
44  walk++; subWalk++;
45  }
46 }
const char * ptr() const
Definition: stringNew.h:124
string pfc::string::subString ( t_size  base) const
inline

Definition at line 67 of file stringNew.h.

67  {
68  if (base > length()) throw exception_overflow();
69  return string(ptr() + base);
70  }
t_size length() const
Definition: stringNew.h:127
const char * ptr() const
Definition: stringNew.h:124
string pfc::string::subString ( t_size  base,
t_size  count 
) const
inline

Definition at line 71 of file stringNew.h.

71  {
72  return string(ptr() + base,count);
73  }
const char * ptr() const
Definition: stringNew.h:124
string pfc::string::toLower ( ) const
inline

Definition at line 75 of file stringNew.h.

75  {
76  string8_fastalloc temp; temp.prealloc(128);
77  stringToLowerAppend(temp,ptr(),~0);
78  return string(temp.get_ptr());
79  }
const char * ptr() const
Definition: stringNew.h:124
void stringToLowerAppend(string_base &out, const char *src, t_size len)
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
string const& pfc::string::toString ( ) const
inline

Definition at line 40 of file stringNew.h.

40 {return *this;}
string pfc::string::toUpper ( ) const
inline

Definition at line 80 of file stringNew.h.

80  {
81  string8_fastalloc temp; temp.prealloc(128);
82  stringToUpperAppend(temp,ptr(),~0);
83  return string(temp.get_ptr());
84  }
const char * ptr() const
Definition: stringNew.h:124
void stringToUpperAppend(string_base &out, const char *src, t_size len)
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436

Field Documentation

t_data pfc::string::m_content
private

Definition at line 201 of file stringNew.h.


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