summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/locale/src/util/encoding.cpp
diff options
context:
space:
mode:
authorthegeorg <[email protected]>2025-05-07 11:09:12 +0300
committerthegeorg <[email protected]>2025-05-07 11:25:22 +0300
commit4c98f14a2491da2bc1a9d40fed1d1682c7ec5dd6 (patch)
tree8142081775c27c8780fa0282a0273ee268e13b98 /contrib/restricted/boost/locale/src/util/encoding.cpp
parent40b86c68b431bb65d67bba51ef9159066a833b68 (diff)
Update contrib/restricted/boost/locale to 1.88.0
commit_hash:87b595328ea79c6ba38cb973580804486ca4a3ff
Diffstat (limited to 'contrib/restricted/boost/locale/src/util/encoding.cpp')
-rw-r--r--contrib/restricted/boost/locale/src/util/encoding.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/contrib/restricted/boost/locale/src/util/encoding.cpp b/contrib/restricted/boost/locale/src/util/encoding.cpp
new file mode 100644
index 00000000000..8b893f1c4a0
--- /dev/null
+++ b/contrib/restricted/boost/locale/src/util/encoding.cpp
@@ -0,0 +1,60 @@
+//
+// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
+// Copyright (c) 2022-2025 Alexander Grund
+//
+// Distributed under the Boost Software License, Version 1.0.
+// https://www.boost.org/LICENSE_1_0.txt
+
+#include "encoding.hpp"
+#include <boost/locale/util/string.hpp>
+#if BOOST_LOCALE_USE_WIN32_API
+# include "win_codepages.hpp"
+# ifndef NOMINMAX
+# define NOMINMAX
+# endif
+# include <windows.h>
+#endif
+#include <algorithm>
+#include <cstring>
+
+namespace boost { namespace locale { namespace util {
+ std::string normalize_encoding(const core::string_view encoding)
+ {
+ std::string result;
+ result.reserve(encoding.length());
+ for(char c : encoding) {
+ if(is_lower_ascii(c) || is_numeric_ascii(c))
+ result += c;
+ else if(is_upper_ascii(c))
+ result += char(c - 'A' + 'a');
+ }
+ return result;
+ }
+
+#if BOOST_LOCALE_USE_WIN32_API
+ static int normalized_encoding_to_windows_codepage(const std::string& encoding)
+ {
+ windows_encoding* end = std::end(all_windows_encodings);
+
+ windows_encoding* ptr = std::lower_bound(all_windows_encodings, end, encoding.c_str());
+ while(ptr != end && ptr->name == encoding) {
+ if(ptr->was_tested)
+ return ptr->codepage;
+ else if(IsValidCodePage(ptr->codepage)) {
+ // the thread safety is not an issue, maximum
+ // it would be checked more then once
+ ptr->was_tested = 1;
+ return ptr->codepage;
+ } else
+ ++ptr;
+ }
+ return -1;
+ }
+
+ int encoding_to_windows_codepage(const core::string_view encoding)
+ {
+ return normalized_encoding_to_windows_codepage(normalize_encoding(encoding));
+ }
+
+#endif
+}}} // namespace boost::locale::util