aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/protobuf_old/src/google/protobuf/json_util.cc
blob: 450ce1da570ba70483ea83c4bc18b7280c772094 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <google/protobuf/json_util.h>

namespace google {
namespace protobuf {
namespace io {

void PrintJSONString(IOutputStream& stream, const TProtoStringType& string) {
    stream << '"';
    for (const char c: string) {
        switch(c) {
            case '"' : stream << "\\\""; continue;
            case '\\': stream << "\\\\"; continue;
            case '\b': stream << "\\b"; continue;
            case '\f': stream << "\\f"; continue;
            case '\n': stream << "\\n"; continue;
            case '\r': stream << "\\r"; continue;
            case '\t': stream << "\\t"; continue;
        }
        if ((unsigned char)c < 0x20) {
            stream << "\\u00";
            static const char hexDigits[] = "0123456789ABCDEF";
            stream << hexDigits[(c & 0xf0) >> 4];
            stream << hexDigits[(c & 0x0f)];
            continue;
        }
        stream << c;
    }
    stream << '"';
}

}
}
}