aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/TextConverter.cpp
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/poco/Foundation/src/TextConverter.cpp
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
downloadydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/TextConverter.cpp')
-rw-r--r--contrib/libs/poco/Foundation/src/TextConverter.cpp256
1 files changed, 128 insertions, 128 deletions
diff --git a/contrib/libs/poco/Foundation/src/TextConverter.cpp b/contrib/libs/poco/Foundation/src/TextConverter.cpp
index 59194ed77c..bd63fd278b 100644
--- a/contrib/libs/poco/Foundation/src/TextConverter.cpp
+++ b/contrib/libs/poco/Foundation/src/TextConverter.cpp
@@ -1,128 +1,128 @@
-//
-// TextConverter.cpp
-//
-// Library: Foundation
-// Package: Text
-// Module: TextConverter
-//
-// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
-// and Contributors.
-//
-// SPDX-License-Identifier: BSL-1.0
-//
-
-
-#include "Poco/TextConverter.h"
-#include "Poco/TextIterator.h"
-#include "Poco/TextEncoding.h"
-
-
-namespace {
- int nullTransform(int ch)
- {
- return ch;
- }
-}
-
-
-namespace Poco {
-
-
-TextConverter::TextConverter(const TextEncoding& inEncoding, const TextEncoding& outEncoding, int defaultChar):
- _inEncoding(inEncoding),
- _outEncoding(outEncoding),
- _defaultChar(defaultChar)
-{
-}
-
-
-TextConverter::~TextConverter()
-{
-}
-
-
-int TextConverter::convert(const std::string& source, std::string& destination, Transform trans)
-{
- int errors = 0;
- TextIterator it(source, _inEncoding);
- TextIterator end(source);
- unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
-
- while (it != end)
- {
- int c = *it;
- if (c == -1) { ++errors; c = _defaultChar; }
- c = trans(c);
- int n = _outEncoding.convert(c, buffer, sizeof(buffer));
- if (n == 0) n = _outEncoding.convert(_defaultChar, buffer, sizeof(buffer));
- poco_assert (n <= sizeof(buffer));
- destination.append((const char*) buffer, n);
- ++it;
- }
- return errors;
-}
-
-
-int TextConverter::convert(const void* source, int length, std::string& destination, Transform trans)
-{
- poco_check_ptr (source);
-
- int errors = 0;
- const unsigned char* it = (const unsigned char*) source;
- const unsigned char* end = (const unsigned char*) source + length;
- unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
-
- while (it < end)
- {
- int n = _inEncoding.queryConvert(it, 1);
- int uc;
- int read = 1;
-
- while (-1 > n && (end - it) >= -n)
- {
- read = -n;
- n = _inEncoding.queryConvert(it, read);
- }
-
- if (-1 > n)
- {
- it = end;
- }
- else
- {
- it += read;
- }
-
- if (-1 >= n)
- {
- uc = _defaultChar;
- ++errors;
- }
- else
- {
- uc = n;
- }
-
- uc = trans(uc);
- n = _outEncoding.convert(uc, buffer, sizeof(buffer));
- if (n == 0) n = _outEncoding.convert(_defaultChar, buffer, sizeof(buffer));
- poco_assert (n <= sizeof(buffer));
- destination.append((const char*) buffer, n);
- }
- return errors;
-}
-
-
-int TextConverter::convert(const std::string& source, std::string& destination)
-{
- return convert(source, destination, nullTransform);
-}
-
-
-int TextConverter::convert(const void* source, int length, std::string& destination)
-{
- return convert(source, length, destination, nullTransform);
-}
-
-
-} // namespace Poco
+//
+// TextConverter.cpp
+//
+// Library: Foundation
+// Package: Text
+// Module: TextConverter
+//
+// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/TextConverter.h"
+#include "Poco/TextIterator.h"
+#include "Poco/TextEncoding.h"
+
+
+namespace {
+ int nullTransform(int ch)
+ {
+ return ch;
+ }
+}
+
+
+namespace Poco {
+
+
+TextConverter::TextConverter(const TextEncoding& inEncoding, const TextEncoding& outEncoding, int defaultChar):
+ _inEncoding(inEncoding),
+ _outEncoding(outEncoding),
+ _defaultChar(defaultChar)
+{
+}
+
+
+TextConverter::~TextConverter()
+{
+}
+
+
+int TextConverter::convert(const std::string& source, std::string& destination, Transform trans)
+{
+ int errors = 0;
+ TextIterator it(source, _inEncoding);
+ TextIterator end(source);
+ unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
+
+ while (it != end)
+ {
+ int c = *it;
+ if (c == -1) { ++errors; c = _defaultChar; }
+ c = trans(c);
+ int n = _outEncoding.convert(c, buffer, sizeof(buffer));
+ if (n == 0) n = _outEncoding.convert(_defaultChar, buffer, sizeof(buffer));
+ poco_assert (n <= sizeof(buffer));
+ destination.append((const char*) buffer, n);
+ ++it;
+ }
+ return errors;
+}
+
+
+int TextConverter::convert(const void* source, int length, std::string& destination, Transform trans)
+{
+ poco_check_ptr (source);
+
+ int errors = 0;
+ const unsigned char* it = (const unsigned char*) source;
+ const unsigned char* end = (const unsigned char*) source + length;
+ unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
+
+ while (it < end)
+ {
+ int n = _inEncoding.queryConvert(it, 1);
+ int uc;
+ int read = 1;
+
+ while (-1 > n && (end - it) >= -n)
+ {
+ read = -n;
+ n = _inEncoding.queryConvert(it, read);
+ }
+
+ if (-1 > n)
+ {
+ it = end;
+ }
+ else
+ {
+ it += read;
+ }
+
+ if (-1 >= n)
+ {
+ uc = _defaultChar;
+ ++errors;
+ }
+ else
+ {
+ uc = n;
+ }
+
+ uc = trans(uc);
+ n = _outEncoding.convert(uc, buffer, sizeof(buffer));
+ if (n == 0) n = _outEncoding.convert(_defaultChar, buffer, sizeof(buffer));
+ poco_assert (n <= sizeof(buffer));
+ destination.append((const char*) buffer, n);
+ }
+ return errors;
+}
+
+
+int TextConverter::convert(const std::string& source, std::string& destination)
+{
+ return convert(source, destination, nullTransform);
+}
+
+
+int TextConverter::convert(const void* source, int length, std::string& destination)
+{
+ return convert(source, length, destination, nullTransform);
+}
+
+
+} // namespace Poco