aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/JSONString.cpp
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:45:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:01 +0300
commit2d37894b1b037cf24231090eda8589bbb44fb6fc (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Foundation/src/JSONString.cpp
parent718c552901d703c502ccbefdfc3c9028d608b947 (diff)
downloadydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/JSONString.cpp')
-rw-r--r--contrib/libs/poco/Foundation/src/JSONString.cpp202
1 files changed, 101 insertions, 101 deletions
diff --git a/contrib/libs/poco/Foundation/src/JSONString.cpp b/contrib/libs/poco/Foundation/src/JSONString.cpp
index 318d8c067c..16049765d5 100644
--- a/contrib/libs/poco/Foundation/src/JSONString.cpp
+++ b/contrib/libs/poco/Foundation/src/JSONString.cpp
@@ -1,101 +1,101 @@
-//
-// String.h
-//
-// Library: Foundation
-// Package: Core
-// Module: String
-//
-// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
-// and Contributors.
-//
-// SPDX-License-Identifier: BSL-1.0
-//
-
-#include "Poco/JSONString.h"
-#include "Poco/UTF8String.h"
-#include <ostream>
-
-
-namespace {
-
-
-template<typename T, typename S>
-struct WriteFunc
-{
- typedef T& (T::*Type)(const char* s, S n);
-};
-
-
-
-template<typename T, typename S>
-void writeString(const std::string &value, T& obj, typename WriteFunc<T, S>::Type write, int options)
-{
- bool wrap = ((options & Poco::JSON_WRAP_STRINGS) != 0);
- bool escapeAllUnicode = ((options & Poco::JSON_ESCAPE_UNICODE) != 0);
-
- if (value.size() == 0)
- {
- if(wrap) (obj.*write)("\"\"", 2);
- return;
- }
-
- if(wrap) (obj.*write)("\"", 1);
- if(escapeAllUnicode)
- {
- std::string str = Poco::UTF8::escape(value.begin(), value.end(), true);
- (obj.*write)(str.c_str(), str.size());
- }
- else
- {
- for(std::string::const_iterator it = value.begin(), end = value.end(); it != end; ++it)
- {
- // Forward slash isn't strictly required by JSON spec, but some parsers expect it
- if((*it >= 0 && *it <= 31) || (*it == '"') || (*it == '\\') || (*it == '/'))
- {
- std::string str = Poco::UTF8::escape(it, it + 1, true);
- (obj.*write)(str.c_str(), str.size());
- }else (obj.*write)(&(*it), 1);
- }
- }
- if(wrap) (obj.*write)("\"", 1);
-};
-
-
-}
-
-
-namespace Poco {
-
-
-void toJSON(const std::string& value, std::ostream& out, bool wrap)
-{
- int options = (wrap ? Poco::JSON_WRAP_STRINGS : 0);
- writeString<std::ostream, std::streamsize>(value, out, &std::ostream::write, options);
-}
-
-
-std::string toJSON(const std::string& value, bool wrap)
-{
- int options = (wrap ? Poco::JSON_WRAP_STRINGS : 0);
- std::string ret;
- writeString<std::string,
- std::string::size_type>(value, ret, &std::string::append, options);
- return ret;
-}
-
-
-void toJSON(const std::string& value, std::ostream& out, int options)
-{
- writeString<std::ostream, std::streamsize>(value, out, &std::ostream::write, options);
-}
-
-
-std::string toJSON(const std::string& value, int options)
-{
- std::string ret;
- writeString<std::string, std::string::size_type>(value, ret, &std::string::append, options);
- return ret;
-}
-
-
-} // namespace Poco
+//
+// String.h
+//
+// Library: Foundation
+// Package: Core
+// Module: String
+//
+// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+#include "Poco/JSONString.h"
+#include "Poco/UTF8String.h"
+#include <ostream>
+
+
+namespace {
+
+
+template<typename T, typename S>
+struct WriteFunc
+{
+ typedef T& (T::*Type)(const char* s, S n);
+};
+
+
+
+template<typename T, typename S>
+void writeString(const std::string &value, T& obj, typename WriteFunc<T, S>::Type write, int options)
+{
+ bool wrap = ((options & Poco::JSON_WRAP_STRINGS) != 0);
+ bool escapeAllUnicode = ((options & Poco::JSON_ESCAPE_UNICODE) != 0);
+
+ if (value.size() == 0)
+ {
+ if(wrap) (obj.*write)("\"\"", 2);
+ return;
+ }
+
+ if(wrap) (obj.*write)("\"", 1);
+ if(escapeAllUnicode)
+ {
+ std::string str = Poco::UTF8::escape(value.begin(), value.end(), true);
+ (obj.*write)(str.c_str(), str.size());
+ }
+ else
+ {
+ for(std::string::const_iterator it = value.begin(), end = value.end(); it != end; ++it)
+ {
+ // Forward slash isn't strictly required by JSON spec, but some parsers expect it
+ if((*it >= 0 && *it <= 31) || (*it == '"') || (*it == '\\') || (*it == '/'))
+ {
+ std::string str = Poco::UTF8::escape(it, it + 1, true);
+ (obj.*write)(str.c_str(), str.size());
+ }else (obj.*write)(&(*it), 1);
+ }
+ }
+ if(wrap) (obj.*write)("\"", 1);
+};
+
+
+}
+
+
+namespace Poco {
+
+
+void toJSON(const std::string& value, std::ostream& out, bool wrap)
+{
+ int options = (wrap ? Poco::JSON_WRAP_STRINGS : 0);
+ writeString<std::ostream, std::streamsize>(value, out, &std::ostream::write, options);
+}
+
+
+std::string toJSON(const std::string& value, bool wrap)
+{
+ int options = (wrap ? Poco::JSON_WRAP_STRINGS : 0);
+ std::string ret;
+ writeString<std::string,
+ std::string::size_type>(value, ret, &std::string::append, options);
+ return ret;
+}
+
+
+void toJSON(const std::string& value, std::ostream& out, int options)
+{
+ writeString<std::ostream, std::streamsize>(value, out, &std::ostream::write, options);
+}
+
+
+std::string toJSON(const std::string& value, int options)
+{
+ std::string ret;
+ writeString<std::string, std::string::size_type>(value, ret, &std::string::append, options);
+ return ret;
+}
+
+
+} // namespace Poco