aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/TextConverter.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/TextConverter.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/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 bd63fd278b..59194ed77c 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