25 #ifndef String_class_h
26 #define String_class_h
37 class StringSumHelper;
45 typedef void (String::*StringIfHelperType)()
const;
46 void StringIfHelper()
const {}
54 String(
const char *cstr =
"");
55 String(
const String &str);
56 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
57 String(String &&rval);
58 String(StringSumHelper &&rval);
60 explicit String(
char c);
61 explicit String(
unsigned char,
unsigned char base=10);
62 explicit String(
int,
unsigned char base=10);
63 explicit String(
unsigned int,
unsigned char base=10);
64 explicit String(
long,
unsigned char base=10);
65 explicit String(
unsigned long,
unsigned char base=10);
66 explicit String(
float,
unsigned char decimalPlaces=2);
67 explicit String(
double,
unsigned char decimalPlaces=2);
74 unsigned char reserve(
unsigned int size);
75 inline unsigned int length(
void)
const {
return len;}
80 String & operator = (
const String &rhs);
81 String & operator = (
const char *cstr);
82 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
83 String & operator = (String &&rval);
84 String & operator = (StringSumHelper &&rval);
92 unsigned char concat(
const String &str);
93 unsigned char concat(
const char *cstr);
94 unsigned char concat(
char c);
95 unsigned char concat(
unsigned char c);
96 unsigned char concat(
int num);
97 unsigned char concat(
unsigned int num);
98 unsigned char concat(
long num);
99 unsigned char concat(
unsigned long num);
100 unsigned char concat(
float num);
101 unsigned char concat(
double num);
105 String & operator += (
const String &rhs) {concat(rhs);
return (*
this);}
106 String & operator += (
const char *cstr) {concat(cstr);
return (*
this);}
107 String & operator += (
char c) {concat(c);
return (*
this);}
108 String & operator += (
unsigned char num) {concat(num);
return (*
this);}
109 String & operator += (
int num) {concat(num);
return (*
this);}
110 String & operator += (
unsigned int num) {concat(num);
return (*
this);}
111 String & operator += (
long num) {concat(num);
return (*
this);}
112 String & operator += (
unsigned long num) {concat(num);
return (*
this);}
113 String & operator += (
float num) {concat(num);
return (*
this);}
114 String & operator += (
double num) {concat(num);
return (*
this);}
116 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
const String &rhs);
117 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
const char *cstr);
118 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
char c);
119 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
unsigned char num);
120 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
int num);
121 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
unsigned int num);
122 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
long num);
123 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
unsigned long num);
124 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
float num);
125 friend StringSumHelper &
operator + (
const StringSumHelper &lhs,
double num);
128 operator StringIfHelperType()
const {
return buffer ? &String::StringIfHelper : 0; }
129 int compareTo(
const String &s)
const;
130 unsigned char equals(
const String &s)
const;
131 unsigned char equals(
const char *cstr)
const;
132 unsigned char operator == (
const String &rhs)
const {
return equals(rhs);}
133 unsigned char operator == (
const char *cstr)
const {
return equals(cstr);}
134 unsigned char operator != (
const String &rhs)
const {
return !equals(rhs);}
135 unsigned char operator != (
const char *cstr)
const {
return !equals(cstr);}
136 unsigned char operator < (
const String &rhs)
const;
137 unsigned char operator > (
const String &rhs)
const;
138 unsigned char operator <= (
const String &rhs)
const;
139 unsigned char operator >= (
const String &rhs)
const;
140 unsigned char equalsIgnoreCase(
const String &s)
const;
141 unsigned char startsWith(
const String &prefix)
const;
142 unsigned char startsWith(
const String &prefix,
unsigned int offset)
const;
143 unsigned char endsWith(
const String &suffix)
const;
146 char charAt(
unsigned int index)
const;
147 void setCharAt(
unsigned int index,
char c);
148 char operator [] (
unsigned int index)
const;
149 char& operator [] (
unsigned int index);
150 void getBytes(
unsigned char *buf,
unsigned int bufsize,
unsigned int index=0)
const;
151 void toCharArray(
char *buf,
unsigned int bufsize,
unsigned int index=0)
const
152 { getBytes((
unsigned char *)buf, bufsize, index); }
153 const char* c_str()
const {
return buffer; }
154 char* begin() {
return buffer; }
155 char* end() {
return buffer + length(); }
156 const char* begin()
const {
return c_str(); }
157 const char* end()
const {
return c_str() + length(); }
160 int indexOf(
char ch )
const;
161 int indexOf(
char ch,
unsigned int fromIndex )
const;
162 int indexOf(
const String &str )
const;
163 int indexOf(
const String &str,
unsigned int fromIndex )
const;
164 int lastIndexOf(
char ch )
const;
165 int lastIndexOf(
char ch,
unsigned int fromIndex )
const;
166 int lastIndexOf(
const String &str )
const;
167 int lastIndexOf(
const String &str,
unsigned int fromIndex )
const;
168 String substring(
unsigned int beginIndex )
const {
return substring(beginIndex, len); };
169 String substring(
unsigned int beginIndex,
unsigned int endIndex )
const;
172 void replace(
char find,
char replace);
173 void replace(
const String& find,
const String& replace);
174 void remove(
unsigned int index);
175 void remove(
unsigned int index,
unsigned int count);
176 void toLowerCase(
void);
177 void toUpperCase(
void);
181 long toInt(
void)
const;
182 float toFloat(
void)
const;
183 double toDouble(
void)
const;
187 unsigned int capacity;
191 void invalidate(
void);
192 unsigned char changeBuffer(
unsigned int maxStrLen);
193 unsigned char concat(
const char *cstr,
unsigned int length);
196 String & copy(
const char *cstr,
unsigned int length);
197 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
198 void move(String &rhs);
202 class StringSumHelper :
public String
205 StringSumHelper(
const String &s) : String(s) {}
206 StringSumHelper(
const char *p) : String(p) {}
207 StringSumHelper(
char c) : String(c) {}
208 StringSumHelper(
unsigned char num) : String(num) {}
209 StringSumHelper(
int num) : String(num) {}
210 StringSumHelper(
unsigned int num) : String(num) {}
211 StringSumHelper(
long num) : String(num) {}
212 StringSumHelper(
unsigned long num) : String(num) {}
213 StringSumHelper(
float num) : String(num) {}
214 StringSumHelper(
double num) : String(num) {}
217 #endif // __cplusplus
218 #endif // String_class_h