Skip to content

Commit aac6f0a

Browse files
committed
add replace and trim
1 parent 087c4a8 commit aac6f0a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/FixedString.h

+25
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,31 @@ class FixedStringBase
213213
return memcmp((char*)c_str(), other, otherLength) == 0;
214214
}
215215

216+
void replace(char toReplace, char replaceWith)
217+
{
218+
for(size_t i =0; i < length(); i++)
219+
{
220+
if(_str()[i] == toReplace)
221+
{
222+
_str()[i] = replaceWith;
223+
}
224+
}
225+
}
226+
void trimStart(char c)
227+
{
228+
size_t charactersToTrim = 0;
229+
while(charactersToTrim < length() && c_str()[charactersToTrim] == c)
230+
{
231+
charactersToTrim++;
232+
}
233+
for(size_t i =0; i < length(); i++)
234+
{
235+
_str()[i] = _str()[i+charactersToTrim];
236+
}
237+
_length -= charactersToTrim;
238+
_str()[length()] = 0;
239+
}
240+
216241
void appendFormat(const char *format, ...)
217242
{
218243
va_list argptr;

0 commit comments

Comments
 (0)