ClickHouse/src/IO/examples/read_escaped_string.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
819 B
C++
Raw Normal View History

#include <string>
#include <iostream>
#include <IO/ReadHelpers.h>
#include <IO/ReadBufferFromMemory.h>
#include <IO/ConcatReadBuffer.h>
2017-01-03 01:42:17 +00:00
using namespace DB;
2017-12-01 18:36:55 +00:00
int main(int, char **)
2017-01-03 01:42:17 +00:00
try
{
2017-01-03 01:42:17 +00:00
std::string s1 = "abc\\x\n";
std::string s2 = "\tdef";
2017-01-03 01:42:17 +00:00
ReadBufferFromMemory rb1(s1.data(), 3);
ReadBufferFromMemory rb2(s2.data(), s2.size());
2017-01-03 01:42:17 +00:00
ConcatReadBuffer rb3(rb1, rb2);
2017-01-03 01:42:17 +00:00
std::string read_s1;
std::string read_s2;
2017-01-03 01:42:17 +00:00
readEscapedString(read_s1, rb3);
assertChar('\t', rb3);
readEscapedString(read_s2, rb3);
2017-01-03 01:42:17 +00:00
std::cerr << read_s1 << ", " << read_s2 << std::endl;
std::cerr << ((read_s1 == "abc" && read_s2 == "def") ? "Ok." : "Fail.") << std::endl;
return 0;
}
2017-01-03 01:42:17 +00:00
catch (const Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << std::endl;
return 1;
}