foobar2000 SDK  2015-08-03
stringNew.cpp
Go to the documentation of this file.
1 #include "pfc.h"
2 
3 namespace pfc {
4 
5 t_size string::indexOf(char c,t_size base) const {
6  return pfc::string_find_first(ptr(),c,base);
7 }
8 t_size string::lastIndexOf(char c,t_size base) const {
9  return pfc::string_find_last(ptr(),c,base);
10 }
12  return pfc::string_find_first(ptr(),s.ptr(),base);
13 }
15  return pfc::string_find_last(ptr(),s.ptr(),base);
16 }
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 }
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 }
35 bool string::startsWith(char c) const {
36  return (*this)[0] == c;
37 }
38 bool string::startsWith(string s) const {
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 }
47 bool string::endsWith(char c) const {
48  const t_size len = length();
49  if (len == 0) return false;
50  return ptr()[len-1] == c;
51 }
52 bool string::endsWith(string s) const {
53  const t_size len = length(), subLen = s.length();
54  if (subLen > len) return false;
55  return subString(len - subLen) == s;
56 }
57 
58 char string::firstChar() const {
59  return (*this)[0];
60 }
61 char string::lastChar() const {
62  const t_size len = length();
63  return len > 0 ? (*this)[len-1] : (char)0;
64 }
65 
66 string string::replace(stringp strOld, stringp strNew) const {
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 }
79 bool string::contains(char c) const {return indexOf(c) != ~0;}
80 bool string::contains(stringp s) const {return indexOf(s) != ~0;}
81 bool string::containsAnyChar(stringp s) const {return indexOfAnyChar(s) != ~0;}
82 }
bool startsWith(char c) const
Definition: stringNew.cpp:35
t_size length() const
Definition: stringNew.h:127
t_size indexOfAnyChar(stringp s, t_size base=0) const
Definition: stringNew.cpp:17
string replace(stringp strOld, stringp strNew) const
Definition: stringNew.cpp:66
char lastChar() const
Definition: stringNew.cpp:61
string subString(t_size base) const
Definition: stringNew.h:67
t_size lastIndexOfAnyChar(stringp s, t_size base=~0) const
Definition: stringNew.cpp:26
bool endsWith(char c) const
Definition: stringNew.cpp:47
const char * ptr() const
Definition: stringNew.h:124
"String parameter" helper class, to use in function parameters, allowing functions to take any type o...
Definition: stringNew.h:224
bool containsAnyChar(stringp s) const
Definition: stringNew.cpp:81
size_t t_size
Definition: int_types.h:48
t_size lastIndexOf(char c, t_size base=~0) const
Definition: stringNew.cpp:8
char firstChar() const
Definition: stringNew.cpp:58
const char * ptr() const
Definition: stringNew.h:232
t_size length() const
Definition: stringNew.h:237
bool contains(char c) const
Definition: stringNew.cpp:79
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
t_size indexOf(char c, t_size base=0) const
Definition: stringNew.cpp:5