2014-06-25 13:02:39 +02:00
|
|
|
#include "StringBuilder.h"
|
|
|
|
|
|
|
|
|
2014-06-25 13:50:28 +02:00
|
|
|
void StringBuilder::append(const char* s)
|
2014-06-25 13:02:39 +02:00
|
|
|
{
|
|
|
|
char* tail = buffer + length;
|
|
|
|
|
2014-06-25 13:50:28 +02:00
|
|
|
strcpy(tail, s);
|
2014-06-25 13:02:39 +02:00
|
|
|
|
|
|
|
length += strlen(tail);
|
2014-06-25 13:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StringBuilder::appendEscaped(const char* s)
|
|
|
|
{
|
|
|
|
if (length > capacity - 3) return;
|
|
|
|
|
|
|
|
buffer[length++] = '"';
|
|
|
|
|
|
|
|
while (*s && length<capacity-2)
|
|
|
|
{
|
|
|
|
if (*s == '"')
|
|
|
|
buffer[length++] = '\\';
|
|
|
|
|
|
|
|
buffer[length++] = *s;
|
|
|
|
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[length++] = '"';
|
2014-06-25 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StringBuilder::appendFormatted(const char* format, ...)
|
|
|
|
{
|
|
|
|
char* tail = buffer + length;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vsnprintf(tail, capacity - length, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
length += strlen(tail);
|
2014-06-25 13:02:39 +02:00
|
|
|
}
|