-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescape_impl.cpp
31 lines (24 loc) · 1014 Bytes
/
escape_impl.cpp
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
#include <minjsoncpp.h>
#include <iostream>
using namespace std::string_view_literals;
void writeEscapedToStdout(std::string_view s) {
// a sink repeatedly receives parts of escaped string as 'std::string_view' instances
const auto stdOutSink = [](std::string_view s) { std::cout << s; };
// 'minjson::impl::escape()' can be called with any type of sink
// that is able to receive parts as 'std::string_view' instances
minjson::impl::escape(stdOutSink,
s,
minjson::Escape::Default,
minjson::Utf8Validation::IgnoreInvalidUtf8CodeUnits,
minjson::HexDigitsCase::Upper);
}
int main(int argc, const char *argv[]) {
if (argc > 1) {
writeEscapedToStdout(argv[1]);
return 0;
}
const auto string = "string containing special characters: \t \\ \" \n (new line)"sv;
std::cout << "escaping string:\n\n\'" << string << "\'\n\ngives:\n\n\'";
writeEscapedToStdout(string);
std::cout << "\'\n";
}