make add_color_inplace safer
This commit is contained in:
+3
-8
@@ -40,17 +40,18 @@ void replace_char_inplace(T* a, T f, T r) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t add_color_inplace(T* a) {
|
||||
size_t add_color_inplace(T* a, size_t max_chars) {
|
||||
T* d = a;
|
||||
T* orig_d = d;
|
||||
|
||||
while (*a) {
|
||||
for (size_t x = 0; (x < max_chars) && *a; x++) {
|
||||
if (*a == '$') {
|
||||
*(d++) = '\t';
|
||||
} else if (*a == '#') {
|
||||
*(d++) = '\n';
|
||||
} else if (*a == '%') {
|
||||
a++;
|
||||
x++;
|
||||
if (*a == 's') {
|
||||
*(d++) = '$';
|
||||
} else if (*a == '%') {
|
||||
@@ -69,9 +70,3 @@ size_t add_color_inplace(T* a) {
|
||||
|
||||
return d - orig_d;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_color_inplace(std::basic_string<T>& a, size_t header_bytes) {
|
||||
size_t count = add_color_inplace(a.data() + header_bytes);
|
||||
a.resize(count + header_bytes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user