diff options
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/KBufferBuilder.cpp | 28 | ||||
-rw-r--r-- | Kernel/KBufferBuilder.h | 2 |
2 files changed, 30 insertions, 0 deletions
diff --git a/Kernel/KBufferBuilder.cpp b/Kernel/KBufferBuilder.cpp index 1c3129be4e..f3480b10a2 100644 --- a/Kernel/KBufferBuilder.cpp +++ b/Kernel/KBufferBuilder.cpp @@ -93,4 +93,32 @@ void KBufferBuilder::appendf(const char* fmt, ...) va_end(ap); } +void KBufferBuilder::append_escaped_for_json(const StringView& string) +{ + for (auto ch : string) { + switch (ch) { + case '\e': + append("\\u001B"); + break; + case '\b': + append("\\b"); + break; + case '\n': + append("\\n"); + break; + case '\t': + append("\\t"); + break; + case '\"': + append("\\\""); + break; + case '\\': + append("\\\\"); + break; + default: + append(ch); + } + } +} + } diff --git a/Kernel/KBufferBuilder.h b/Kernel/KBufferBuilder.h index affef2bbe8..9335620a02 100644 --- a/Kernel/KBufferBuilder.h +++ b/Kernel/KBufferBuilder.h @@ -45,6 +45,8 @@ public: void appendf(const char*, ...); void appendvf(const char*, va_list); + void append_escaped_for_json(const StringView&); + template<typename... Parameters> void appendff(StringView fmtstr, const Parameters&... parameters) { |