14 DString::DString(const char *str
)
19 DString::DString(const char *str
, int length
)
24 DString::DString(DString
&other
)
26 SetTo(other
.String(), other
.Length());
30 void c------------------------------() {}
33 void DString::SetTo(const char *str
, int length
)
35 fBuffer
.SetTo((uint8_t *)str
, length
);
38 void DString::SetTo(const char *str
)
40 fBuffer
.SetTo((uint8_t *)str
, strlen(str
));
43 void DString::SetTo(DString
*other
)
45 fBuffer
.SetTo(other
->fBuffer
.Data(), other
->fBuffer
.Length());
48 void DString::SetTo(DString
&other
)
50 fBuffer
.SetTo(other
.fBuffer
.Data(), other
.fBuffer
.Length());
54 void c------------------------------() {}
57 void DString::AppendString(const char *str
)
59 fBuffer
.AppendData((uint8_t *)str
, strlen(str
));
62 void DString::AppendString(const char *str
, int length
)
64 fBuffer
.AppendData((uint8_t *)str
, length
);
67 void DString::AppendChar(uchar ch
)
69 fBuffer
.AppendData((uint8_t *)&ch
, 1);
73 void c------------------------------() {}
76 void DString::ReplaceString(const char *repstr_old
, const char *repstr_new
)
81 int oldLength
, newLength
;
86 hit
= strstr(ptr
, repstr_old
);
89 // first time around the loop? if so then we don't need
90 // to do any copying as we won't modify ourselves anyway.
94 newString
.AppendString(ptr
);
98 // defer calling the strlens until we're sure we need them
99 // (by now we know there is an occurance of repstr_old within the original string).
102 oldLength
= strlen(repstr_old
);
103 if (oldLength
== 0) return;
105 newLength
= strlen(repstr_new
);
108 // add substring up to the hit
109 newString
.AppendString(ptr
, (hit
- ptr
));
110 newString
.AppendString(repstr_new
, newLength
);
112 ptr
= (hit
+ oldLength
);
119 char *str = String();
120 char *hit = strstr(str, oldstring);
121 if (!hit) return; // avoid strlens in common case of no hits
123 int oldlen = strlen(oldstring);
124 int newlen = strlen(newstring);
128 DString temp(str, (hit - str));
129 temp.AppendString(newstring);
130 temp.AppendString(hit + oldlen);
132 SetTo(temp.String());
134 int index = (hit - str) + newlen;
135 str = String() + index;
137 hit = strstr(str, oldstring);
143 void c------------------------------() {}
146 void DString::EnsureAlloc(int min_required
)
148 fBuffer
.EnsureAlloc(min_required
);
151 void DString::ReplaceUnprintableChars()
153 fBuffer
.ReplaceUnprintableChars();
157 void c------------------------------() {}
160 void DString::Clear()
165 int DString::Length()
167 return fBuffer
.Length();
170 char *DString::String()
172 return fBuffer
.String();