From f855ff1803a5ceee26069d22d696a13e3ec3c554 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 8 May 2014 23:03:22 +0400 Subject: [PATCH] zkutil_test: fixed error [#METR-10687]. --- libs/libzkutil/src/tests/zkutil_test.cpp | 40 ++++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/libs/libzkutil/src/tests/zkutil_test.cpp b/libs/libzkutil/src/tests/zkutil_test.cpp index 276ca752a7b..80cef7b4178 100644 --- a/libs/libzkutil/src/tests/zkutil_test.cpp +++ b/libs/libzkutil/src/tests/zkutil_test.cpp @@ -34,6 +34,27 @@ void waitForWatch(zkutil::WatchFuture & future) } +void readUntilSpace(std::string & s, DB::ReadBuffer & buf) +{ + s = ""; + while (!buf.eof()) + { + if (isspace(*buf.position())) + return; + s.push_back(*buf.position()); + ++buf.position(); + } +} + +void readMaybeQuoted(std::string & s, DB::ReadBuffer & buf) +{ + if (!buf.eof() && *buf.position() == '\'') + DB::readQuotedString(s, buf); + else + readUntilSpace(s, buf); +} + + int main(int argc, char ** argv) { try @@ -85,19 +106,17 @@ int main(int argc, char ** argv) { DB::ReadBufferFromString in(line); + std::string path; std::string data; std::string mode; DB::assertString("create", in); DB::skipWhitespaceIfAny(in); - - if (!in.eof() && *in.position() == '\'') - DB::readQuotedString(data, in); - else - DB::readString(data, in); - + readMaybeQuoted(path, in); DB::skipWhitespaceIfAny(in); - DB::readString(mode, in); + readMaybeQuoted(data, in); + DB::skipWhitespaceIfAny(in); + readUntilSpace(mode, in); zkutil::CreateMode::type m; if (mode == "p") @@ -156,12 +175,7 @@ int main(int argc, char ** argv) DB::assertString("set", in); DB::skipWhitespaceIfAny(in); - - if (!in.eof() && *in.position() == '\'') - DB::readQuotedString(data, in); - else - DB::readString(data, in); - + readMaybeQuoted(data, in); DB::skipWhitespaceIfAny(in); if (!in.eof())