forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid_utf8.cpp
More file actions
45 lines (41 loc) · 1.25 KB
/
Copy pathvalid_utf8.cpp
File metadata and controls
45 lines (41 loc) · 1.25 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
#include <IO/WriteBufferValidUTF8.h>
#include <IO/WriteBufferFromString.h>
#include <IO/WriteHelpers.h>
#include <string>
#include <iostream>
int main(int, char **)
{
try
{
std::string test1 = R"(kjhsgdfkjhg2378rtzgvxkz877%^&^*%&^*&*)";
std::string test2 = R"({"asd" = "qw1","qwe24" = "3asd"})";
test2[test2.find('1')] = char(127 + 64);
test2[test2.find('2')] = char(127 + 64 + 32);
test2[test2.find('3')] = char(127 + 64 + 32 + 16);
test2[test2.find('4')] = char(127 + 64 + 32 + 16 + 8);
std::string str;
{
DB::WriteBufferFromString str_buf(str);
{
DB::WriteBufferValidUTF8 utf_buf(str_buf, true, "-");
DB::writeEscapedString(test1, utf_buf);
}
}
std::cout << str << std::endl;
str = "";
{
DB::WriteBufferFromString str_buf(str);
{
DB::WriteBufferValidUTF8 utf_buf(str_buf, true, "-");
DB::writeEscapedString(test2, utf_buf);
}
}
std::cout << str << std::endl;
}
catch (const DB::Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << std::endl;
return 1;
}
return 0;
}