diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2023-04-29 08:56:13 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2023-04-29 08:56:13 +0300 |
commit | 8721a3c0d16b7c607eb00bf95c6d0a676e6f15ca (patch) | |
tree | 92d034e91464b0c9a01cc29c8f528828da6bd771 /contrib | |
parent | 9b611a5dbbc1d348fbaf973636730d4e71d8c6a9 (diff) | |
download | ydb-8721a3c0d16b7c607eb00bf95c6d0a676e6f15ca.tar.gz |
Update contrib/restricted/boost/locale to 1.82.0
Diffstat (limited to 'contrib')
67 files changed, 774 insertions, 620 deletions
diff --git a/contrib/restricted/boost/core/include/boost/core/exchange.hpp b/contrib/restricted/boost/core/include/boost/core/exchange.hpp new file mode 100644 index 0000000000..bc8a9fcd70 --- /dev/null +++ b/contrib/restricted/boost/core/include/boost/core/exchange.hpp @@ -0,0 +1,49 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef BOOST_CORE_EXCHANGE_HPP +#define BOOST_CORE_EXCHANGE_HPP + +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#include <boost/config/workaround.hpp> +#include <utility> +#endif + +namespace boost { + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +template<class T, class U> +inline T exchange(T& t, const U& u) +{ + T v = t; + t = u; + return v; +} +#else +#if BOOST_WORKAROUND(BOOST_MSVC, < 1800) +template<class T, class U> +inline T exchange(T& t, U&& u) +{ + T v = std::move(t); + t = std::forward<U>(u); + return v; +} +#else +template<class T, class U = T> +BOOST_CXX14_CONSTEXPR inline T exchange(T& t, U&& u) +{ + T v = std::move(t); + t = std::forward<U>(u); + return v; +} +#endif +#endif + +} /* boost */ + +#endif diff --git a/contrib/restricted/boost/locale/CMakeLists.darwin-x86_64.txt b/contrib/restricted/boost/locale/CMakeLists.darwin-x86_64.txt index 8e8b149e50..c712fd71a3 100644 --- a/contrib/restricted/boost/locale/CMakeLists.darwin-x86_64.txt +++ b/contrib/restricted/boost/locale/CMakeLists.darwin-x86_64.txt @@ -50,6 +50,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp @@ -61,6 +62,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp diff --git a/contrib/restricted/boost/locale/CMakeLists.linux-aarch64.txt b/contrib/restricted/boost/locale/CMakeLists.linux-aarch64.txt index 831330fafc..49c58834ef 100644 --- a/contrib/restricted/boost/locale/CMakeLists.linux-aarch64.txt +++ b/contrib/restricted/boost/locale/CMakeLists.linux-aarch64.txt @@ -51,6 +51,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp @@ -62,6 +63,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp diff --git a/contrib/restricted/boost/locale/CMakeLists.linux-x86_64.txt b/contrib/restricted/boost/locale/CMakeLists.linux-x86_64.txt index 831330fafc..49c58834ef 100644 --- a/contrib/restricted/boost/locale/CMakeLists.linux-x86_64.txt +++ b/contrib/restricted/boost/locale/CMakeLists.linux-x86_64.txt @@ -51,6 +51,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp @@ -62,6 +63,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp diff --git a/contrib/restricted/boost/locale/CMakeLists.windows-x86_64.txt b/contrib/restricted/boost/locale/CMakeLists.windows-x86_64.txt index 946baa474e..76b190df2c 100644 --- a/contrib/restricted/boost/locale/CMakeLists.windows-x86_64.txt +++ b/contrib/restricted/boost/locale/CMakeLists.windows-x86_64.txt @@ -50,6 +50,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp @@ -61,6 +62,7 @@ target_sources(restricted-boost-locale PRIVATE ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp diff --git a/contrib/restricted/boost/locale/include/boost/locale/boundary/index.hpp b/contrib/restricted/boost/locale/include/boost/locale/boundary/index.hpp index 7d2eb66071..6143ac4616 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/boundary/index.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/boundary/index.hpp @@ -40,6 +40,14 @@ namespace boost { namespace locale { namespace boundary { /// \cond INTERNAL namespace detail { + template<typename Char> + const boundary_indexing<Char>& get_boundary_indexing(const std::locale& l) + { + using facet_type = boundary_indexing<Char>; + if(!std::has_facet<facet_type>(l)) + throw std::runtime_error("Locale was generated without segmentation support!"); + return std::use_facet<facet_type>(l); + } template<typename IteratorType, typename CategoryType = typename std::iterator_traits<IteratorType>::iterator_category> @@ -48,7 +56,7 @@ namespace boost { namespace locale { namespace boundary { static index_type map(boundary_type t, IteratorType b, IteratorType e, const std::locale& l) { std::basic_string<char_type> str(b, e); - return std::use_facet<boundary_indexing<char_type>>(l).map(t, str.c_str(), str.c_str() + str.size()); + return get_boundary_indexing<char_type>(l).map(t, str.c_str(), str.c_str() + str.size()); } }; @@ -78,12 +86,11 @@ namespace boost { namespace locale { namespace boundary { if(linear_iterator_traits<char_type, IteratorType>::is_linear && b != e) { const char_type* begin = &*b; const char_type* end = begin + (e - b); - index_type tmp = std::use_facet<boundary_indexing<char_type>>(l).map(t, begin, end); + index_type tmp = get_boundary_indexing<char_type>(l).map(t, begin, end); result.swap(tmp); } else { std::basic_string<char_type> str(b, e); - index_type tmp = - std::use_facet<boundary_indexing<char_type>>(l).map(t, str.c_str(), str.c_str() + str.size()); + index_type tmp = get_boundary_indexing<char_type>(l).map(t, str.c_str(), str.c_str() + str.size()); result.swap(tmp); } return result; diff --git a/contrib/restricted/boost/locale/include/boost/locale/boundary/segment.hpp b/contrib/restricted/boost/locale/include/boost/locale/boundary/segment.hpp index 68146b3df9..796fc19956 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/boundary/segment.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/boundary/segment.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED #define BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED -#include <boost/locale/config.hpp> #include <boost/locale/util/string.hpp> #include <iosfwd> #include <iterator> diff --git a/contrib/restricted/boost/locale/include/boost/locale/config.hpp b/contrib/restricted/boost/locale/include/boost/locale/config.hpp index f75a4801f9..821ba7fe7d 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/config.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/config.hpp @@ -65,4 +65,13 @@ # define BOOST_LOCALE_END_CONST_CONDITION #endif +/// \cond INTERNAL +#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) +// Internal define to check if we have access to the Win32 API +# define BOOST_LOCALE_USE_WIN32_API 1 +#else +# define BOOST_LOCALE_USE_WIN32_API 0 +#endif +/// \endcond + #endif // boost/locale/config.hpp diff --git a/contrib/restricted/boost/locale/include/boost/locale/conversion.hpp b/contrib/restricted/boost/locale/include/boost/locale/conversion.hpp index 5917e05d79..09fa75faf7 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/conversion.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/conversion.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_LOCALE_CONVERTER_HPP_INCLUDED #define BOOST_LOCALE_CONVERTER_HPP_INCLUDED -#include <boost/locale/config.hpp> #include <boost/locale/util/string.hpp> #include <locale> diff --git a/contrib/restricted/boost/locale/include/boost/locale/date_time.hpp b/contrib/restricted/boost/locale/include/boost/locale/date_time.hpp index 8895628163..8006c60e89 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/date_time.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/date_time.hpp @@ -568,7 +568,7 @@ namespace boost { namespace locale { /// Copy a date_time date_time(const date_time& other); // Move construct a new date_time - date_time(date_time&& other) = default; + date_time(date_time&&) = default; /// copy date_time and change some fields according to the \a set date_time(const date_time& other, const date_time_period_set& set); @@ -576,7 +576,7 @@ namespace boost { namespace locale { /// assign the date_time date_time& operator=(const date_time& other); // Move assign a date_time - date_time& operator=(date_time&& other) = default; + date_time& operator=(date_time&&) = default; /// Create a date_time object using POSIX time \a time and default calendar /// diff --git a/contrib/restricted/boost/locale/include/boost/locale/format.hpp b/contrib/restricted/boost/locale/include/boost/locale/format.hpp index 12f9d6bd30..67a925da2d 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/format.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/format.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_LOCALE_FORMAT_HPP_INCLUDED #define BOOST_LOCALE_FORMAT_HPP_INCLUDED -#include <boost/locale/config.hpp> #include <boost/locale/formatting.hpp> #include <boost/locale/hold_ptr.hpp> #include <boost/locale/message.hpp> @@ -38,10 +37,10 @@ namespace boost { namespace locale { formattible() : pointer_(0), writer_(&formattible::void_write) {} - formattible(const formattible& other) = default; - formattible(formattible&& other) = default; - formattible& operator=(const formattible& other) = default; - formattible& operator=(formattible&& other) = default; + formattible(const formattible&) = default; + formattible(formattible&&) = default; + formattible& operator=(const formattible&) = default; + formattible& operator=(formattible&&) = default; template<typename Type> explicit formattible(const Type& value) diff --git a/contrib/restricted/boost/locale/include/boost/locale/formatting.hpp b/contrib/restricted/boost/locale/include/boost/locale/formatting.hpp index 8348f7f826..70397eed89 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/formatting.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/formatting.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_LOCALE_FORMATTING_HPP_INCLUDED #define BOOST_LOCALE_FORMATTING_HPP_INCLUDED -#include <boost/locale/config.hpp> #include <boost/locale/time_zone.hpp> #include <boost/locale/util/string.hpp> #include <boost/assert.hpp> diff --git a/contrib/restricted/boost/locale/include/boost/locale/generator.hpp b/contrib/restricted/boost/locale/include/boost/locale/generator.hpp index 726817c57e..bfbd528071 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/generator.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/generator.hpp @@ -6,7 +6,7 @@ #ifndef BOOST_LOCALE_GENERATOR_HPP #define BOOST_LOCALE_GENERATOR_HPP -#include <boost/locale/config.hpp> + #include <boost/locale/hold_ptr.hpp> #include <boost/cstdint.hpp> #include <locale> diff --git a/contrib/restricted/boost/locale/include/boost/locale/generic_codecvt.hpp b/contrib/restricted/boost/locale/include/boost/locale/generic_codecvt.hpp index 0ad94bad6a..428a9f0914 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/generic_codecvt.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/generic_codecvt.hpp @@ -161,26 +161,14 @@ namespace boost { namespace locale { std::codecvt_base::result do_unshift(std::mbstate_t& s, char* from, char* /*to*/, char*& next) const override { boost::uint16_t& state = *reinterpret_cast<boost::uint16_t*>(&s); -#ifdef DEBUG_CODECVT - std::cout << "Entering unshift " << std::hex << state << std::dec << std::endl; -#endif if(state != 0) return std::codecvt_base::error; next = from; return std::codecvt_base::ok; } - int do_encoding() const noexcept override - { - return 0; - } - int do_max_length() const noexcept override - { - return implementation().max_encoding_length(); - } - bool do_always_noconv() const noexcept override - { - return false; - } + int do_encoding() const noexcept override { return 0; } + int do_max_length() const noexcept override { return implementation().max_encoding_length(); } + bool do_always_noconv() const noexcept override { return false; } int do_length( #ifdef BOOST_LOCALE_DO_LENGTH_MBSTATE_CONST @@ -195,7 +183,7 @@ namespace boost { namespace locale { const char* save_from = from; boost::uint16_t& state = *reinterpret_cast<boost::uint16_t*>(&std_state); #else - size_t save_max = max; + const size_t start_max = max; boost::uint16_t state = *reinterpret_cast<const boost::uint16_t*>(&std_state); #endif @@ -221,7 +209,7 @@ namespace boost { namespace locale { #ifndef BOOST_LOCALE_DO_LENGTH_MBSTATE_CONST return static_cast<int>(from - save_from); #else - return static_cast<int>(save_max - max); + return static_cast<int>(start_max - max); #endif } @@ -244,11 +232,6 @@ namespace boost { namespace locale { typename CodecvtImpl::state_type cvt_state = implementation().initial_state(generic_codecvt_base::to_unicode_state); while(to < to_end && from < from_end) { -#ifdef DEBUG_CODECVT - std::cout << "Entering IN--------------\n"; - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif const char* from_saved = from; uint32_t ch = implementation().to_unicode(cvt_state, from, from_end); @@ -263,11 +246,11 @@ namespace boost { namespace locale { r = std::codecvt_base::partial; break; } - // Normal codepoints go direcly to stream + // Normal codepoints go directly to stream if(ch <= 0xFFFF) { *to++ = static_cast<uchar>(ch); } else { - // for other codepoints we do following + // For other codepoints we do the following // // 1. We can't consume our input as we may find ourselves // in state where all input consumed but not all output written,i.e. only @@ -293,17 +276,6 @@ namespace boost { namespace locale { to_next = to; if(r == std::codecvt_base::ok && (from != from_end || state != 0)) r = std::codecvt_base::partial; -#ifdef DEBUG_CODECVT - std::cout << "Returning "; - switch(r) { - case std::codecvt_base::ok: std::cout << "ok\n"; break; - case std::codecvt_base::partial: std::cout << "partial\n"; break; - case std::codecvt_base::error: std::cout << "error\n"; break; - default: std::cout << "other\n"; break; - } - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif return r; } @@ -326,11 +298,6 @@ namespace boost { namespace locale { typename CodecvtImpl::state_type cvt_state = implementation().initial_state(generic_codecvt_base::from_unicode_state); while(to < to_end && from < from_end) { -#ifdef DEBUG_CODECVT - std::cout << "Entering OUT --------------\n"; - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif boost::uint32_t ch = 0; if(state != 0) { // if the state indicates that 1st surrogate pair was written @@ -385,19 +352,8 @@ namespace boost { namespace locale { } from_next = from; to_next = to; - if(r == std::codecvt_base::ok && from != from_end) + if(r == std::codecvt_base::ok && (from != from_end || state != 0)) r = std::codecvt_base::partial; -#ifdef DEBUG_CODECVT - std::cout << "Returning "; - switch(r) { - case std::codecvt_base::ok: std::cout << "ok\n"; break; - case std::codecvt_base::partial: std::cout << "partial\n"; break; - case std::codecvt_base::error: std::cout << "error\n"; break; - default: std::cout << "other\n"; break; - } - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif return r; } }; @@ -439,7 +395,7 @@ namespace boost { namespace locale { #ifndef BOOST_LOCALE_DO_LENGTH_MBSTATE_CONST const char* start_from = from; #else - size_t save_max = max; + const size_t start_max = max; #endif typename CodecvtImpl::state_type cvt_state = implementation().initial_state(generic_codecvt_base::to_unicode_state); @@ -452,10 +408,11 @@ namespace boost { namespace locale { } max--; } + #ifndef BOOST_LOCALE_DO_LENGTH_MBSTATE_CONST - return from - start_from; + return static_cast<int>(from - start_from); #else - return save_max - max; + return static_cast<int>(start_max - max); #endif } @@ -476,11 +433,6 @@ namespace boost { namespace locale { // and first pair is written, but no input consumed auto cvt_state = implementation().initial_state(generic_codecvt_base::to_unicode_state); while(to < to_end && from < from_end) { -#ifdef DEBUG_CODECVT - std::cout << "Entering IN--------------\n"; - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif const char* from_saved = from; uint32_t ch = implementation().to_unicode(cvt_state, from, from_end); @@ -501,17 +453,6 @@ namespace boost { namespace locale { to_next = to; if(r == std::codecvt_base::ok && from != from_end) r = std::codecvt_base::partial; -#ifdef DEBUG_CODECVT - std::cout << "Returning "; - switch(r) { - case std::codecvt_base::ok: std::cout << "ok\n"; break; - case std::codecvt_base::partial: std::cout << "partial\n"; break; - case std::codecvt_base::error: std::cout << "error\n"; break; - default: std::cout << "other\n"; break; - } - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif return r; } @@ -526,11 +467,6 @@ namespace boost { namespace locale { std::codecvt_base::result r = std::codecvt_base::ok; auto cvt_state = implementation().initial_state(generic_codecvt_base::from_unicode_state); while(to < to_end && from < from_end) { -#ifdef DEBUG_CODECVT - std::cout << "Entering OUT --------------\n"; - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif boost::uint32_t ch = 0; ch = *from; if(!boost::locale::utf::is_valid_codepoint(ch)) { @@ -552,17 +488,6 @@ namespace boost { namespace locale { to_next = to; if(r == std::codecvt_base::ok && from != from_end) r = std::codecvt_base::partial; -#ifdef DEBUG_CODECVT - std::cout << "Returning "; - switch(r) { - case std::codecvt_base::ok: std::cout << "ok\n"; break; - case std::codecvt_base::partial: std::cout << "partial\n"; break; - case std::codecvt_base::error: std::cout << "error\n"; break; - default: std::cout << "other\n"; break; - } - std::cout << "State " << std::hex << state << std::endl; - std::cout << "Left in " << std::dec << from_end - from << " out " << to_end - to << std::endl; -#endif return r; } }; diff --git a/contrib/restricted/boost/locale/include/boost/locale/localization_backend.hpp b/contrib/restricted/boost/locale/include/boost/locale/localization_backend.hpp index a4b79bf4c5..37df24e283 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/localization_backend.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/localization_backend.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_LOCALE_LOCALIZATION_BACKEND_HPP #define BOOST_LOCALE_LOCALIZATION_BACKEND_HPP -#include <boost/locale/config.hpp> #include <boost/locale/generator.hpp> #include <boost/locale/hold_ptr.hpp> #include <locale> diff --git a/contrib/restricted/boost/locale/include/boost/locale/message.hpp b/contrib/restricted/boost/locale/include/boost/locale/message.hpp index 690c224d7d..3aacc5801a 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/message.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/message.hpp @@ -202,12 +202,12 @@ namespace boost { namespace locale { {} /// Copy an object - basic_message(const basic_message& other) = default; - basic_message(basic_message&& other) = default; + basic_message(const basic_message&) = default; + basic_message(basic_message&&) = default; /// Assign other message object to this one - basic_message& operator=(const basic_message& other) = default; - basic_message& operator=(basic_message&& other) = default; + basic_message& operator=(const basic_message&) = default; + basic_message& operator=(basic_message&&) = default; /// Swap two message objects void swap(basic_message& other) diff --git a/contrib/restricted/boost/locale/include/boost/locale/util.hpp b/contrib/restricted/boost/locale/include/boost/locale/util.hpp index 0ef67ef7de..d5bf8ddcca 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/util.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/util.hpp @@ -22,19 +22,18 @@ namespace boost { namespace locale { /// \brief Return default system locale name in POSIX format. /// - /// This function tries to detect the locale using, LC_CTYPE, LC_ALL and LANG environment - /// variables in this order and if all of them unset, in POSIX platforms it returns "C" - /// - /// On Windows additionally to check the above environment variables, this function - /// tries to creates locale name from ISO-339 and ISO-3199 country codes defined - /// for user default locale. - /// If \a use_utf8_on_windows is true it sets the encoding to UTF-8, otherwise, if system - /// locale supports ANSI code-page it defines the ANSI encoding like windows-1252, otherwise it fall-backs - /// to UTF-8 encoding if ANSI code-page is not available. + /// This function tries to detect the locale using LC_ALL, LC_CTYPE and LANG environment + /// variables in this order and if all of them are unset, on POSIX platforms it returns "C". + /// On Windows additionally to the above environment variables, this function + /// tries to create the locale name from ISO-639 and ISO-3166 country codes defined + /// for the users default locale. + /// If \a use_utf8_on_windows is true it sets the encoding to UTF-8, + /// otherwise, if the system locale supports ANSI codepages it defines the ANSI encoding, e.g. windows-1252, + /// otherwise (if ANSI codepage is not available) it uses UTF-8 encoding. BOOST_LOCALE_DECL std::string get_system_locale(bool use_utf8_on_windows = false); - /// \brief Installs information facet to locale in based on locale name \a name + /// \brief Installs information facet to locale \a in based on locale name \a name /// /// This function installs boost::locale::info facet into the locale \a in and returns /// newly created locale. @@ -43,7 +42,7 @@ namespace boost { namespace locale { /// /// The name has following format: language[_COUNTRY][.encoding][\@variant] /// Where language is ISO-639 language code like "en" or "ru", COUNTRY is ISO-3166 - /// country identifier like "US" or "RU". the Encoding is a charracter set name + /// country identifier like "US" or "RU". the Encoding is a character set name /// like UTF-8 or ISO-8859-1. Variant is backend specific variant like \c euro or /// calendar=hebrew. /// diff --git a/contrib/restricted/boost/locale/include/boost/locale/util/locale_data.hpp b/contrib/restricted/boost/locale/include/boost/locale/util/locale_data.hpp new file mode 100644 index 0000000000..2a04bdcba9 --- /dev/null +++ b/contrib/restricted/boost/locale/include/boost/locale/util/locale_data.hpp @@ -0,0 +1,76 @@ +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2023 Alexander Grund +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_LOCALE_UTIL_LOCALE_DATA_HPP +#define BOOST_LOCALE_UTIL_LOCALE_DATA_HPP + +#include <boost/locale/config.hpp> +#include <string> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable : 4251) +#endif + +namespace boost { namespace locale { namespace util { + + /// Holder and parser for locale names/identifiers + class BOOST_LOCALE_DECL locale_data { + std::string language_; + std::string country_; + std::string encoding_; + std::string variant_; + bool utf8_; + + public: + // Default to C locale with US-ASCII encoding + locale_data(); + // Construct from the parsed locale \see \ref parse + // Throws `std::invalid_argument` if parsing fails + explicit locale_data(const std::string& locale_name); + + /// Return language (usually 2 lowercase letters, i.e. ISO-639 or 'C') + const std::string& language() const { return language_; } + /// Return country (usually 2 uppercase letters, i.e. ISO-3166) + const std::string& country() const { return country_; } + /// Return encoding/codeset, e.g. ISO8859-1 or UTF-8 + const std::string& encoding() const { return encoding_; } + /// Return variant/modifier, e.g. euro or stroke + const std::string& variant() const { return variant_; } + /// Return iff the encoding is UTF-8 + bool is_utf8() const { return utf8_; } + + /// <summary> + /// Parse a locale identifier of the form [language[_territory][.codeset][@modifier]] + /// Allows a dash as the delimiter: [language-territory] + /// + /// Return true if the identifier is valid: + /// - `language` is given and consists of ASCII letters + /// - `territory`, if given, consists of ASCII letters + /// - Any field started by a delimiter (`_`, `-`, `.`, `@`) is not empty + /// Otherwise parsing is aborted. Valid values already parsed stay set, other are defaulted. + /// </summary> + bool parse(const std::string& locale_name); + + /// Get a representation in the form [language[_territory][.codeset][@modifier]] + /// codeset is omitted if it is US-ASCII + std::string to_string() const; + + private: + void reset(); + bool parse_from_lang(const std::string& input); + bool parse_from_country(const std::string& input); + bool parse_from_encoding(const std::string& input); + bool parse_from_variant(const std::string& input); + }; + +}}} // namespace boost::locale::util + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif +#endif diff --git a/contrib/restricted/boost/locale/include/boost/locale/util/string.hpp b/contrib/restricted/boost/locale/include/boost/locale/util/string.hpp index 3dc465f157..14e52e65af 100644 --- a/contrib/restricted/boost/locale/include/boost/locale/util/string.hpp +++ b/contrib/restricted/boost/locale/include/boost/locale/util/string.hpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2022 Alexander Grund +// Copyright (c) 2022-2023 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt @@ -18,6 +18,22 @@ namespace boost { namespace locale { namespace util { ++str; return str; } + + inline bool is_upper_ascii(const char c) + { + return 'A' <= c && c <= 'Z'; + } + + inline bool is_lower_ascii(const char c) + { + return 'a' <= c && c <= 'z'; + } + + inline bool is_numeric_ascii(const char c) + { + return '0' <= c && c <= '9'; + } + }}} // namespace boost::locale::util #endif
\ No newline at end of file diff --git a/contrib/restricted/boost/locale/src/boost/locale/encoding/codepage.cpp b/contrib/restricted/boost/locale/src/boost/locale/encoding/codepage.cpp index 744e0452cd..631b526161 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/encoding/codepage.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/encoding/codepage.cpp @@ -4,16 +4,13 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE -#include <boost/locale/config.hpp> #include <boost/locale/encoding.hpp> #include <boost/locale/hold_ptr.hpp> -#include <cstring> #include <memory> #include <string> #include "boost/locale/encoding/conv.hpp" -#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) +#if BOOST_LOCALE_USE_WIN32_API # define BOOST_LOCALE_WITH_WCONV #endif #ifdef BOOST_LOCALE_WITH_ICONV @@ -98,22 +95,6 @@ namespace boost { namespace locale { namespace conv { throw invalid_charset_error(charset); } - std::string normalize_encoding(const char* ccharset) - { - std::string charset; - charset.reserve(std::strlen(ccharset)); - while(*ccharset != 0) { - char c = *ccharset++; - if('0' <= c && c <= '9') - charset += c; - else if('a' <= c && c <= 'z') - charset += c; - else if('A' <= c && c <= 'Z') - charset += char(c - 'A' + 'a'); - } - return charset; - } - } // namespace impl using namespace impl; diff --git a/contrib/restricted/boost/locale/src/boost/locale/encoding/conv.hpp b/contrib/restricted/boost/locale/src/boost/locale/encoding/conv.hpp index bbb287e566..6d2ab68cac 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/encoding/conv.hpp +++ b/contrib/restricted/boost/locale/src/boost/locale/encoding/conv.hpp @@ -31,17 +31,6 @@ namespace boost { namespace locale { namespace conv { namespace impl { return "Unknown Character Encoding"; } - BOOST_LOCALE_DECL std::string normalize_encoding(const char* encoding); - - inline int compare_encodings(const char* l, const char* r) - { - return normalize_encoding(l).compare(normalize_encoding(r)); - } - -#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) - int encoding_to_windows_codepage(const char* ccharset); -#endif - class converter_between { public: typedef char char_type; diff --git a/contrib/restricted/boost/locale/src/boost/locale/encoding/wconv_codepage.ipp b/contrib/restricted/boost/locale/src/boost/locale/encoding/wconv_codepage.ipp index a099bc6857..bf97fd5070 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/encoding/wconv_codepage.ipp +++ b/contrib/restricted/boost/locale/src/boost/locale/encoding/wconv_codepage.ipp @@ -7,18 +7,18 @@ #ifndef BOOST_LOCALE_IMPL_WCONV_CODEPAGE_HPP #define BOOST_LOCALE_IMPL_WCONV_CODEPAGE_HPP +#ifndef NOMINMAX +# define NOMINMAX +#endif #include <boost/locale/encoding.hpp> +#include "boost/locale/encoding/conv.hpp" +#include "boost/locale/util/encoding.hpp" #include <algorithm> #include <cstddef> #include <cstring> #include <limits> #include <string> #include <vector> -#ifndef NOMINMAX -# define NOMINMAX -#endif -#include "boost/locale/encoding/conv.hpp" -#include "boost/locale/encoding/win_codepages.hpp" #include <windows.h> namespace boost { namespace locale { namespace conv { namespace impl { @@ -146,28 +146,6 @@ namespace boost { namespace locale { namespace conv { namespace impl { } } - int encoding_to_windows_codepage(const char* ccharset) - { - constexpr size_t n = sizeof(all_windows_encodings) / sizeof(all_windows_encodings[0]); - windows_encoding* begin = all_windows_encodings; - windows_encoding* end = all_windows_encodings + n; - - const std::string charset = normalize_encoding(ccharset); - windows_encoding* ptr = std::lower_bound(begin, end, charset.c_str()); - while(ptr != end && strcmp(ptr->name, charset.c_str()) == 0) { - 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; - } - template<typename CharType> bool validate_utf16(const CharType* str, size_t len) { @@ -210,8 +188,8 @@ namespace boost { namespace locale { namespace conv { namespace impl { bool open(const char* to_charset, const char* from_charset, method_type how) override { how_ = how; - to_code_page_ = encoding_to_windows_codepage(to_charset); - from_code_page_ = encoding_to_windows_codepage(from_charset); + to_code_page_ = util::encoding_to_windows_codepage(to_charset); + from_code_page_ = util::encoding_to_windows_codepage(from_charset); if(to_code_page_ == -1 || from_code_page_ == -1) return false; return true; @@ -298,7 +276,7 @@ namespace boost { namespace locale { namespace conv { namespace impl { bool open(const char* charset, method_type how) override { how_ = how; - code_page_ = encoding_to_windows_codepage(charset); + code_page_ = util::encoding_to_windows_codepage(charset); return code_page_ != -1; } @@ -332,7 +310,7 @@ namespace boost { namespace locale { namespace conv { namespace impl { bool open(const char* charset, method_type how) override { how_ = how; - code_page_ = encoding_to_windows_codepage(charset); + code_page_ = util::encoding_to_windows_codepage(charset); return code_page_ != -1; } @@ -388,7 +366,7 @@ namespace boost { namespace locale { namespace conv { namespace impl { bool open(const char* charset, method_type how) override { how_ = how; - code_page_ = encoding_to_windows_codepage(charset); + code_page_ = util::encoding_to_windows_codepage(charset); return code_page_ != -1; } @@ -423,7 +401,7 @@ namespace boost { namespace locale { namespace conv { namespace impl { bool open(const char* charset, method_type how) override { how_ = how; - code_page_ = encoding_to_windows_codepage(charset); + code_page_ = util::encoding_to_windows_codepage(charset); return code_page_ != -1; } diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/all_generator.hpp b/contrib/restricted/boost/locale/src/boost/locale/icu/all_generator.hpp index d1e2279b86..9c429a4b37 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/all_generator.hpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/all_generator.hpp @@ -11,13 +11,13 @@ namespace boost { namespace locale { namespace impl_icu { struct cdata; - std::locale create_convert(const std::locale&, const cdata&, char_facet_t); // ok - std::locale create_collate(const std::locale&, const cdata&, char_facet_t); // ok - std::locale create_formatting(const std::locale&, const cdata&, char_facet_t); // ok - std::locale create_parsing(const std::locale&, const cdata&, char_facet_t); // ok - std::locale create_codecvt(const std::locale&, const std::string& encoding, char_facet_t); // ok - std::locale create_boundary(const std::locale&, const cdata&, char_facet_t); // ok - std::locale create_calendar(const std::locale&, const cdata&); // ok + std::locale create_convert(const std::locale&, const cdata&, char_facet_t); + std::locale create_collate(const std::locale&, const cdata&, char_facet_t); + std::locale create_formatting(const std::locale&, const cdata&, char_facet_t); + std::locale create_parsing(const std::locale&, const cdata&, char_facet_t); + std::locale create_codecvt(const std::locale&, const std::string& encoding, char_facet_t); + std::locale create_boundary(const std::locale&, const cdata&, char_facet_t); + std::locale create_calendar(const std::locale&, const cdata&); }}} // namespace boost::locale::impl_icu diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/boundary.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/boundary.cpp index 11d0de8a1d..a992048f75 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/boundary.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/boundary.cpp @@ -5,9 +5,9 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/boundary.hpp> #include <boost/locale/generator.hpp> +#include "boost/locale//util/encoding.hpp" #include "boost/locale/icu/all_generator.hpp" #include "boost/locale/icu/cdata.hpp" #include "boost/locale/icu/icu_util.hpp" @@ -133,7 +133,7 @@ namespace boost { namespace locale { #if BOOST_LOCALE_ICU_VERSION >= 306 UErrorCode err = U_ZERO_ERROR; BOOST_LOCALE_START_CONST_CONDITION - if(sizeof(CharType) == 2 || (sizeof(CharType) == 1 && encoding == "UTF-8")) { + if(sizeof(CharType) == 2 || (sizeof(CharType) == 1 && util::normalize_encoding(encoding) == "utf8")) { UText* ut = 0; try { if(sizeof(CharType) == 1) diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.cpp index f7bf5503a8..b62a542fb0 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/icu/codecvt.hpp" #include <boost/locale/encoding.hpp> #include <boost/locale/encoding_errors.hpp> @@ -14,6 +13,7 @@ #include "boost/locale/icu/all_generator.hpp" #include "boost/locale/icu/icu_util.hpp" #include "boost/locale/icu/uconv.hpp" +#include "boost/locale/util/encoding.hpp" #include <unicode/ucnv.h> #include <unicode/ucnv_err.h> @@ -110,7 +110,7 @@ namespace boost { namespace locale { namespace impl_icu { std::locale create_codecvt(const std::locale& in, const std::string& encoding, char_facet_t type) { - if(conv::impl::normalize_encoding(encoding.c_str()) == "utf8") + if(util::normalize_encoding(encoding) == "utf8") return util::create_utf8_codecvt(in, type); try { diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.hpp b/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.hpp index 02b7f1bfd0..f406f7f533 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.hpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/codecvt.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_LOCALE_IMPL_ICU_CODECVT_HPP #define BOOST_LOCALE_IMPL_ICU_CODECVT_HPP -#include <boost/locale/config.hpp> #include <boost/locale/util.hpp> #include <memory> #include <string> diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/collator.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/collator.cpp index 0f66b7a8ee..c199ba9312 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/collator.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/collator.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/collator.hpp> #include <boost/locale/generator.hpp> #include "boost/locale/icu/all_generator.hpp" diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/conversion.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/conversion.cpp index fdfdd99264..89609c127d 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/conversion.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/conversion.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/conversion.hpp> #include "boost/locale/icu/all_generator.hpp" #include "boost/locale/icu/cdata.hpp" diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/date_time.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/date_time.cpp index c8303cdea5..450e7eadfa 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/date_time.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/date_time.cpp @@ -5,7 +5,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/date_time.hpp> #include <boost/locale/date_time_facet.hpp> #include <boost/locale/formatting.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/formatter.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/formatter.cpp index 7fe2a3b70a..6167852bb6 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/formatter.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/formatter.cpp @@ -5,7 +5,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/icu/formatter.hpp" #include <boost/locale/formatting.hpp> #include <boost/locale/info.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/icu_backend.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/icu_backend.cpp index a0da62b4a9..acf1afccff 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/icu_backend.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/icu_backend.cpp @@ -4,14 +4,13 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/icu/icu_backend.hpp" #include <boost/locale/gnu_gettext.hpp> #include <boost/locale/localization_backend.hpp> #include <boost/locale/util.hpp> +#include <boost/locale/util/locale_data.hpp> #include "boost/locale/icu/all_generator.hpp" #include "boost/locale/icu/cdata.hpp" -#include "boost/locale/util/locale_data.hpp" #include <algorithm> #include <iterator> @@ -63,11 +62,11 @@ namespace boost { namespace locale { namespace impl_icu { d.parse(real_id_); data_.locale = icu::Locale::createCanonical(real_id_.c_str()); - data_.encoding = d.encoding; - data_.utf8 = d.utf8; - language_ = d.language; - country_ = d.country; - variant_ = d.variant; + data_.encoding = d.encoding(); + data_.utf8 = d.is_utf8(); + language_ = d.language(); + country_ = d.country(); + variant_ = d.variant(); } std::locale install(const std::locale& base, category_t category, char_facet_t type) override diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/numeric.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/numeric.cpp index 571a241abc..d3fdaaa2b8 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/numeric.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/numeric.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/formatting.hpp> #include "boost/locale/icu/all_generator.hpp" #include "boost/locale/icu/cdata.hpp" diff --git a/contrib/restricted/boost/locale/src/boost/locale/icu/time_zone.cpp b/contrib/restricted/boost/locale/src/boost/locale/icu/time_zone.cpp index 8457866405..dc69f2dd90 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/icu/time_zone.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/icu/time_zone.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/icu/time_zone.hpp" #include <boost/locale/hold_ptr.hpp> #include "boost/locale/icu/icu_util.hpp" diff --git a/contrib/restricted/boost/locale/src/boost/locale/posix/codecvt.cpp b/contrib/restricted/boost/locale/src/boost/locale/posix/codecvt.cpp index 38b60e1122..d2c5acf006 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/posix/codecvt.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/posix/codecvt.cpp @@ -1,206 +1,21 @@ // // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2022-2023 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE -#include "boost/locale/posix/codecvt.hpp" -#include <boost/locale/encoding.hpp> -#include <boost/locale/hold_ptr.hpp> -#include <boost/locale/util.hpp> -#include <algorithm> -#include <cerrno> -#include <stdexcept> -#include <vector> - -#include "boost/locale/encoding/conv.hpp" +#include <boost/locale/encoding_errors.hpp> #include "boost/locale/posix/all_generator.hpp" -#ifdef BOOST_LOCALE_WITH_ICONV -# include "boost/locale/util/iconv.hpp" -#endif +#include "boost/locale/shared/iconv_codecvt.hpp" +#include "boost/locale/util/encoding.hpp" +#include <stdexcept> namespace boost { namespace locale { namespace impl_posix { -#ifdef BOOST_LOCALE_WITH_ICONV - class mb2_iconv_converter : public util::base_converter { - public: - mb2_iconv_converter(const std::string& encoding) : - encoding_(encoding), to_utf_((iconv_t)(-1)), from_utf_((iconv_t)(-1)) - { - iconv_t d = (iconv_t)(-1); - std::vector<uint32_t> first_byte_table; - try { - d = iconv_open(utf32_encoding(), encoding.c_str()); - if(d == (iconv_t)(-1)) { - throw std::runtime_error("Unsupported encoding" + encoding); - } - for(unsigned c = 0; c < 256; c++) { - const char ibuf[2] = {char(c), 0}; - size_t insize = sizeof(ibuf); - uint32_t obuf[2] = {illegal, illegal}; - size_t outsize = sizeof(obuf); - // Basic single codepoint conversion - call_iconv(d, ibuf, &insize, reinterpret_cast<char*>(obuf), &outsize); - if(insize == 0 && outsize == 0 && obuf[1] == 0) { - first_byte_table.push_back(obuf[0]); - continue; - } - - // Test if this is illegal first byte or incomplete - insize = 1; - outsize = sizeof(obuf); - call_iconv(d, nullptr, nullptr, nullptr, nullptr); - size_t res = call_iconv(d, ibuf, &insize, reinterpret_cast<char*>(obuf), &outsize); - - // Now if this single byte starts a sequence we add incomplete - // to know to ask that we need two bytes, otherwise it may only be - // illegal - - uint32_t point; - if(res == (size_t)(-1) && errno == EINVAL) - point = incomplete; - else - point = illegal; - first_byte_table.push_back(point); - } - } catch(...) { - if(d != (iconv_t)(-1)) - iconv_close(d); - throw; - } - iconv_close(d); - first_byte_table_.reset(new std::vector<uint32_t>()); - first_byte_table_->swap(first_byte_table); - } - - mb2_iconv_converter(const mb2_iconv_converter& other) : - first_byte_table_(other.first_byte_table_), encoding_(other.encoding_), to_utf_((iconv_t)(-1)), - from_utf_((iconv_t)(-1)) - {} - - ~mb2_iconv_converter() - { - if(to_utf_ != (iconv_t)(-1)) - iconv_close(to_utf_); - if(from_utf_ != (iconv_t)(-1)) - iconv_close(from_utf_); - } - - bool is_thread_safe() const override { return false; } - - mb2_iconv_converter* clone() const override { return new mb2_iconv_converter(*this); } - - uint32_t to_unicode(const char*& begin, const char* end) override - { - if(begin == end) - return incomplete; - - unsigned char seq0 = *begin; - uint32_t index = (*first_byte_table_)[seq0]; - if(index == illegal) - return illegal; - if(index != incomplete) { - begin++; - return index; - } else if(begin + 1 == end) - return incomplete; - - open(to_utf_, utf32_encoding(), encoding_.c_str()); - - // maybe illegal or may be double byte - - const char inseq[3] = {static_cast<char>(seq0), begin[1], 0}; - size_t insize = sizeof(inseq); - uint32_t result[2] = {illegal, illegal}; - size_t outsize = sizeof(result); - call_iconv(to_utf_, inseq, &insize, reinterpret_cast<char*>(result), &outsize); - if(outsize == 0 && insize == 0 && result[1] == 0) { - begin += 2; - return result[0]; - } - return illegal; - } - - uint32_t from_unicode(uint32_t cp, char* begin, const char* end) override - { - if(cp == 0) { - if(begin != end) { - *begin = 0; - return 1; - } else { - return incomplete; - } - } - - open(from_utf_, encoding_.c_str(), utf32_encoding()); - - const uint32_t inbuf[2] = {cp, 0}; - size_t insize = sizeof(inbuf); - char outseq[3] = {0}; - size_t outsize = 3; - - call_iconv(from_utf_, reinterpret_cast<const char*>(inbuf), &insize, outseq, &outsize); - - if(insize != 0 || outsize > 1) - return illegal; - size_t len = 2 - outsize; - size_t reminder = end - begin; - if(reminder < len) - return incomplete; - for(unsigned i = 0; i < len; i++) - *begin++ = outseq[i]; - return len; - } - - void open(iconv_t& d, const char* to, const char* from) - { - if(d != (iconv_t)(-1)) - return; - d = iconv_open(to, from); - } - - static const char* utf32_encoding() - { - union { - char one; - uint32_t value; - } test; - test.value = 1; - if(test.one == 1) - return "UTF-32LE"; - else - return "UTF-32BE"; - } - - int max_len() const override { return 2; } - - private: - std::shared_ptr<std::vector<uint32_t>> first_byte_table_; - std::string encoding_; - iconv_t to_utf_; - iconv_t from_utf_; - }; - - std::unique_ptr<util::base_converter> create_iconv_converter(const std::string& encoding) - { - try { - return std::unique_ptr<util::base_converter>(new mb2_iconv_converter(encoding)); - } catch(const std::exception& e) { - return nullptr; - } - } - -#else // no iconv - std::unique_ptr<util::base_converter> create_iconv_converter(const std::string& /*encoding*/) - { - return nullptr; - } -#endif - std::locale create_codecvt(const std::locale& in, const std::string& encoding, char_facet_t type) { - if(conv::impl::normalize_encoding(encoding.c_str()) == "utf8") + if(util::normalize_encoding(encoding) == "utf8") return util::create_utf8_codecvt(in, type); try { diff --git a/contrib/restricted/boost/locale/src/boost/locale/posix/collate.cpp b/contrib/restricted/boost/locale/src/boost/locale/posix/collate.cpp index 8050471e50..410d8bed45 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/posix/collate.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/posix/collate.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/generator.hpp> #if defined(__FreeBSD__) # include <xlocale.h> diff --git a/contrib/restricted/boost/locale/src/boost/locale/posix/converter.cpp b/contrib/restricted/boost/locale/src/boost/locale/posix/converter.cpp index 6c45eb5f24..4dfa6babee 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/posix/converter.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/posix/converter.cpp @@ -4,8 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE - #include <boost/locale/conversion.hpp> #include <boost/locale/encoding.hpp> #include <boost/locale/generator.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/posix/numeric.cpp b/contrib/restricted/boost/locale/src/boost/locale/posix/numeric.cpp index f1b4a5605a..6c63a88810 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/posix/numeric.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/posix/numeric.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #if defined(__FreeBSD__) # include <xlocale.h> #endif diff --git a/contrib/restricted/boost/locale/src/boost/locale/posix/posix_backend.cpp b/contrib/restricted/boost/locale/src/boost/locale/posix/posix_backend.cpp index ef6f498830..df87fa14f7 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/posix/posix_backend.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/posix/posix_backend.cpp @@ -4,12 +4,12 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/posix/posix_backend.hpp" #include <boost/locale/gnu_gettext.hpp> #include <boost/locale/info.hpp> #include <boost/locale/localization_backend.hpp> #include <boost/locale/util.hpp> +#include <boost/locale/util/locale_data.hpp> #include <algorithm> #include <iterator> #include <langinfo.h> @@ -20,7 +20,6 @@ #include "boost/locale/posix/all_generator.hpp" #include "boost/locale/util/gregorian.hpp" -#include "boost/locale/util/locale_data.hpp" namespace boost { namespace locale { namespace impl_posix { @@ -102,16 +101,16 @@ namespace boost { namespace locale { namespace impl_posix { case category_t::calendar: { util::locale_data inf; inf.parse(real_id_); - return util::install_gregorian_calendar(base, inf.country); + return util::install_gregorian_calendar(base, inf.country()); } case category_t::message: { gnu_gettext::messages_info minf; util::locale_data inf; inf.parse(real_id_); - minf.language = inf.language; - minf.country = inf.country; - minf.variant = inf.variant; - minf.encoding = inf.encoding; + minf.language = inf.language(); + minf.country = inf.country(); + minf.variant = inf.variant(); + minf.encoding = inf.encoding(); std::copy(domains_.begin(), domains_.end(), std::back_inserter<gnu_gettext::messages_info::domains_type>(minf.domains)); diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/date_time.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/date_time.cpp index e719cc3247..1970fec8bb 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/date_time.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/date_time.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/date_time.hpp> #include <boost/locale/formatting.hpp> #include <boost/thread/locks.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp index a72e13d4e3..8d3f7406af 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/format.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/format.hpp> #include <boost/locale/generator.hpp> #include <boost/locale/info.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp index 9c30d2af80..5c1e5e7ab5 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/formatting.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/date_time.hpp> #include <boost/locale/formatting.hpp> #include "boost/locale/shared/ios_prop.hpp" @@ -49,8 +48,8 @@ namespace boost { namespace locale { ios_info::~ios_info() = default; - ios_info::ios_info(const ios_info& other) = default; - ios_info& ios_info::operator=(const ios_info& other) = default; + ios_info::ios_info(const ios_info&) = default; + ios_info& ios_info::operator=(const ios_info&) = default; void ios_info::display_flags(uint64_t f) { diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp index 047ddb407c..fe4e20c3c8 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/generator.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/encoding.hpp> #include <boost/locale/generator.hpp> #include <boost/locale/localization_backend.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp new file mode 100644 index 0000000000..764fe3c686 --- /dev/null +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.cpp @@ -0,0 +1,179 @@ +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2022-2023 Alexander Grund +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include "iconv_codecvt.hpp" +#include <boost/assert.hpp> +#include <array> +#include <cerrno> +#include <limits> +#include <vector> +#ifdef BOOST_LOCALE_WITH_ICONV +# include "boost/locale/util/iconv.hpp" +#endif + +namespace boost { namespace locale { + +#ifdef BOOST_LOCALE_WITH_ICONV + static const char* utf32_encoding() + { + union { + char one; + uint32_t value; + } test; + test.value = 1; + return (test.one == 1) ? "UTF-32LE" : "UTF-32BE"; + } + + class mb2_iconv_converter : public util::base_converter { + public: + mb2_iconv_converter(const std::string& encoding) : encoding_(encoding) + { + iconv_handle d = iconv_open(utf32_encoding(), encoding.c_str()); + if(!d) + throw std::runtime_error("Unsupported encoding" + encoding); + + for(unsigned c = 0; c < first_byte_table_.size(); c++) { + const char ibuf[2] = {char(c), 0}; + size_t insize = sizeof(ibuf); + uint32_t obuf[2] = {illegal, illegal}; + size_t outsize = sizeof(obuf); + // Basic single codepoint conversion + call_iconv(d, ibuf, &insize, reinterpret_cast<char*>(obuf), &outsize); + if(insize == 0 && outsize == 0 && obuf[1] == 0) + first_byte_table_[c] = obuf[0]; + else { + // Test if this is illegal first byte or incomplete + insize = 1; + outsize = sizeof(obuf); + call_iconv(d, nullptr, nullptr, nullptr, nullptr); + size_t res = call_iconv(d, ibuf, &insize, reinterpret_cast<char*>(obuf), &outsize); + + // Now if this single byte starts a sequence we add incomplete + // to know to ask that we need two bytes, otherwise it may only be illegal + + first_byte_table_[c] = (res == size_t(-1) && errno == EINVAL) ? incomplete : illegal; + } + } + } + + mb2_iconv_converter(const mb2_iconv_converter& other) : + first_byte_table_(other.first_byte_table_), encoding_(other.encoding_) + {} + + bool is_thread_safe() const override { return false; } + + mb2_iconv_converter* clone() const override { return new mb2_iconv_converter(*this); } + + uint32_t to_unicode(const char*& begin, const char* end) override + { + if(begin == end) + return incomplete; + + const unsigned char seq0 = *begin; + +# if defined(BOOST_GCC_VERSION) && BOOST_GCC_VERSION >= 40600 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wtype-limits" +# endif + static_assert(std::numeric_limits<unsigned char>::max() + < std::tuple_size<decltype(first_byte_table_)>::value, + "Wrong table size"); +# if defined(BOOST_GCC_VERSION) && BOOST_GCC_VERSION >= 40600 +# pragma GCC diagnostic pop +# endif + + const uint32_t index = first_byte_table_[seq0]; + if(index == illegal) + return illegal; + if(index != incomplete) { + begin++; + return index; + } else if(begin + 1 == end) + return incomplete; + + open(to_utf_, utf32_encoding(), encoding_.c_str()); + + // maybe illegal or may be double byte + + const char inseq[3] = {static_cast<char>(seq0), begin[1], 0}; + size_t insize = sizeof(inseq); + uint32_t result[2] = {illegal, illegal}; + size_t outsize = sizeof(result); + call_iconv(to_utf_, inseq, &insize, reinterpret_cast<char*>(result), &outsize); + if(outsize == 0 && insize == 0 && result[1] == 0) { + begin += 2; + return result[0]; + } + return illegal; + } + + uint32_t from_unicode(uint32_t cp, char* begin, const char* end) override + { + if(cp == 0) { + if(begin != end) { + *begin = 0; + return 1; + } else { + return incomplete; + } + } + + open(from_utf_, encoding_.c_str(), utf32_encoding()); + + const uint32_t inbuf[2] = {cp, 0}; + size_t insize = sizeof(inbuf); + char outseq[3] = {0}; + size_t outsize = 3; + + call_iconv(from_utf_, reinterpret_cast<const char*>(inbuf), &insize, outseq, &outsize); + + if(insize != 0 || outsize > 1) + return illegal; + size_t len = 2 - outsize; + size_t reminder = end - begin; + if(reminder < len) + return incomplete; + for(unsigned i = 0; i < len; i++) + *begin++ = outseq[i]; + return static_cast<uint32_t>(len); + } + + int max_len() const override + { + return 2; + } + + private: + std::array<uint32_t, 256> first_byte_table_; + std::string encoding_; + iconv_handle to_utf_, from_utf_; + + static void open(iconv_handle& d, const char* to, const char* from) + { + if(!d) + d = iconv_open(to, from); + BOOST_ASSERT(d); + } + }; + + std::unique_ptr<util::base_converter> create_iconv_converter(const std::string& encoding) + { + try { + return std::unique_ptr<util::base_converter>(new mb2_iconv_converter(encoding)); + } catch(const std::exception&) { + return nullptr; + } + } + +#else // no iconv + std::unique_ptr<util::base_converter> create_iconv_converter(const std::string& /*encoding*/) + { + return nullptr; + } +#endif + +}} // namespace boost::locale diff --git a/contrib/restricted/boost/locale/src/boost/locale/posix/codecvt.hpp b/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.hpp index 3ed08b81d6..51ddc71b68 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/posix/codecvt.hpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/iconv_codecvt.hpp @@ -4,18 +4,17 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#ifndef BOOST_LOCALE_IMPL_POSIX_CODECVT_HPP -#define BOOST_LOCALE_IMPL_POSIX_CODECVT_HPP -#include <boost/locale/config.hpp> -#include <boost/locale/util.hpp> +#ifndef BOOST_LOCALE_ICONV_CODECVT_HPP +#define BOOST_LOCALE_ICONV_CODECVT_HPP +#include <boost/locale/util.hpp> #include <memory> #include <string> -namespace boost { namespace locale { namespace impl_posix { +namespace boost { namespace locale { BOOST_LOCALE_DECL std::unique_ptr<util::base_converter> create_iconv_converter(const std::string& encoding); -}}} // namespace boost::locale::impl_posix +}} // namespace boost::locale #endif diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp index 312b9474a9..30d91d7454 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/ids.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/boundary.hpp> #include <boost/locale/collator.hpp> #include <boost/locale/conversion.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp index c697175acb..e15de171a6 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/localization_backend.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/hold_ptr.hpp> #include <boost/locale/localization_backend.hpp> #include <boost/thread/locks.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp b/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp index 1fb4c6a915..424e77a197 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/shared/message.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #define BOOST_DETAIL_NO_CONTAINER_FWD // Need _wfopen which is an extension on MinGW but not on MinGW-w64 @@ -20,9 +19,9 @@ #include <boost/locale/gnu_gettext.hpp> #include <boost/locale/hold_ptr.hpp> #include <boost/locale/message.hpp> -#include <boost/locale/util/string.hpp> #include "boost/locale/shared/mo_hash.hpp" #include "boost/locale/shared/mo_lambda.hpp" +#include "boost/locale/util/encoding.hpp" #include <boost/version.hpp> #include <algorithm> #include <cstdio> @@ -204,7 +203,7 @@ namespace boost { namespace locale { namespace gnu_gettext { { uint32_t magic = 0; // if the size is wrong magic would be wrong - // ok to ingnore fread result + // ok to ignore fread result size_t four_bytes = fread(&magic, 4, 1, file); (void)four_bytes; // shut GCC @@ -525,27 +524,6 @@ namespace boost { namespace locale { namespace gnu_gettext { } private: - int compare_encodings(const std::string& left, const std::string& right) - { - return convert_encoding_name(left).compare(convert_encoding_name(right)); - } - - std::string convert_encoding_name(const std::string& in) - { - std::string result; - for(unsigned i = 0; i < in.size(); i++) { - char c = in[i]; - if('A' <= c && c <= 'Z') - c = c - 'A' + 'a'; - else if(('a' <= c && c <= 'z') || ('0' <= c && c <= '9')) - ; - else - continue; - result += c; - } - return result; - } - bool load_file(const std::string& file_name, const std::string& locale_encoding, const std::string& key_encoding, @@ -555,7 +533,8 @@ namespace boost { namespace locale { namespace gnu_gettext { locale_encoding_ = locale_encoding; key_encoding_ = key_encoding; - key_conversion_required_ = sizeof(CharType) == 1 && compare_encodings(locale_encoding, key_encoding) != 0; + key_conversion_required_ = + sizeof(CharType) == 1 && !util::are_encodings_equal(locale_encoding, key_encoding); std::shared_ptr<mo_file> mo; @@ -613,9 +592,9 @@ namespace boost { namespace locale { namespace gnu_gettext { BOOST_LOCALE_END_CONST_CONDITION if(!mo.has_hash()) return false; - if(compare_encodings(mo_encoding, locale_encoding_) != 0) + if(!util::are_encodings_equal(mo_encoding, locale_encoding_)) return false; - if(compare_encodings(mo_encoding, key_encoding_) == 0) { + if(util::are_encodings_equal(mo_encoding, key_encoding_)) { return true; } for(unsigned i = 0; i < mo.size(); i++) { diff --git a/contrib/restricted/boost/locale/src/boost/locale/std/codecvt.cpp b/contrib/restricted/boost/locale/src/boost/locale/std/codecvt.cpp index 4e6f9e53b5..e5f702afb0 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/std/codecvt.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/std/codecvt.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/util.hpp> #include "boost/locale/std/all_generator.hpp" #include <locale> diff --git a/contrib/restricted/boost/locale/src/boost/locale/std/collate.cpp b/contrib/restricted/boost/locale/src/boost/locale/std/collate.cpp index 4a41784561..ced58ec597 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/std/collate.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/std/collate.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/encoding.hpp> #include "boost/locale/std/all_generator.hpp" #include <ios> diff --git a/contrib/restricted/boost/locale/src/boost/locale/std/converter.cpp b/contrib/restricted/boost/locale/src/boost/locale/std/converter.cpp index 5b242f78fa..a883ef7430 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/std/converter.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/std/converter.cpp @@ -4,9 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE - -#include <boost/locale/config.hpp> #include <boost/locale/conversion.hpp> #include <boost/locale/encoding.hpp> #include <boost/locale/generator.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/std/numeric.cpp b/contrib/restricted/boost/locale/src/boost/locale/std/numeric.cpp index 91d266c22d..2f93d2c88a 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/std/numeric.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/std/numeric.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/encoding.hpp> #include <boost/locale/formatting.hpp> #include <boost/locale/generator.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp b/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp index 3857c62630..05967eb4bc 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/std/std_backend.cpp @@ -4,11 +4,11 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/std/std_backend.hpp" #include <boost/locale/gnu_gettext.hpp> #include <boost/locale/localization_backend.hpp> #include <boost/locale/util.hpp> +#include <boost/locale/util/locale_data.hpp> #include <algorithm> #include <iterator> #include <vector> @@ -18,12 +18,12 @@ # define NOMINMAX # endif # include "boost/locale/encoding/conv.hpp" +# include "boost/locale/util/encoding.hpp" # include "boost/locale/win32/lcid.hpp" # include <windows.h> #endif #include "boost/locale/std/all_generator.hpp" #include "boost/locale/util/gregorian.hpp" -#include "boost/locale/util/locale_data.hpp" namespace boost { namespace locale { namespace impl_std { @@ -77,12 +77,11 @@ namespace boost { namespace locale { namespace impl_std { const int win_codepage = wl_inf.second; #endif - if(!data_.utf8) { + if(!data_.is_utf8()) { if(loadable(lid)) name_ = lid; #if defined(BOOST_WINDOWS) - else if(loadable(win_name) - && win_codepage == conv::impl::encoding_to_windows_codepage(data_.encoding.c_str())) + else if(loadable(win_name) && win_codepage == util::encoding_to_windows_codepage(data_.encoding())) name_ = win_name; #endif utf_mode_ = utf8_support::none; @@ -154,13 +153,13 @@ namespace boost { namespace locale { namespace impl_std { case category_t::formatting: return create_formatting(base, name_, type, utf_mode_); case category_t::parsing: return create_parsing(base, name_, type, utf_mode_); case category_t::codepage: return create_codecvt(base, name_, type, utf_mode_); - case category_t::calendar: return util::install_gregorian_calendar(base, data_.country); + case category_t::calendar: return util::install_gregorian_calendar(base, data_.country()); case category_t::message: { gnu_gettext::messages_info minf; - minf.language = data_.language; - minf.country = data_.country; - minf.variant = data_.variant; - minf.encoding = data_.encoding; + minf.language = data_.language(); + minf.country = data_.country(); + minf.variant = data_.variant(); + minf.encoding = data_.encoding(); std::copy(domains_.begin(), domains_.end(), std::back_inserter<gnu_gettext::messages_info::domains_type>(minf.domains)); diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp b/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp index 6f544ce183..40759882f2 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/codecvt_converter.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/encoding.hpp> #include <boost/locale/generator.hpp> #include <boost/locale/utf8_codecvt.hpp> @@ -14,6 +13,7 @@ #include <cstring> #include "boost/locale/encoding/conv.hpp" +#include "boost/locale/util/encoding.hpp" #ifdef BOOST_MSVC # pragma warning(disable : 4244) // loose data @@ -188,7 +188,7 @@ namespace boost { namespace locale { namespace util { bool check_is_simple_encoding(const std::string& encoding) { - std::string norm = conv::impl::normalize_encoding(encoding.c_str()); + std::string norm = util::normalize_encoding(encoding); return std::binary_search<const char**>(simple_encoding_table, simple_encoding_table + sizeof(simple_encoding_table) / sizeof(const char*), diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp b/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp index 92d55af57d..d4ede78b1b 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/default_locale.cpp @@ -4,58 +4,60 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/util.hpp> #include <cstdlib> -#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) +#if BOOST_LOCALE_USE_WIN32_API # ifndef NOMINMAX # define NOMINMAX # endif # include <windows.h> -# define BOOST_LOCALE_USE_WIN32_API +#endif + +#if BOOST_LOCALE_USE_WIN32_API +// Get information about the user default locale and put it into the buffer. +// Return true on success +template<size_t N> +static bool get_user_default_locale_info(LCTYPE lcType, char (&buf)[N]) +{ + return GetLocaleInfoA(LOCALE_USER_DEFAULT, lcType, buf, N) != 0; +} #endif namespace boost { namespace locale { namespace util { - std::string get_system_locale(bool use_utf8) + std::string get_system_locale(bool use_utf8_on_windows) { const char* lang = 0; if(!lang || !*lang) - lang = getenv("LC_CTYPE"); - if(!lang || !*lang) lang = getenv("LC_ALL"); if(!lang || !*lang) + lang = getenv("LC_CTYPE"); + if(!lang || !*lang) lang = getenv("LANG"); -#ifndef BOOST_LOCALE_USE_WIN32_API - (void)use_utf8; // not relevant for non-windows +#if !BOOST_LOCALE_USE_WIN32_API + (void)use_utf8_on_windows; // not relevant for non-windows if(!lang || !*lang) lang = "C"; return lang; #else - if(lang && *lang) { + if(lang && *lang) return lang; - } - char buf[10]; - if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, buf, sizeof(buf)) == 0) + + char buf[10]{}; + if(!get_user_default_locale_info(LOCALE_SISO639LANGNAME, buf)) return "C"; std::string lc_name = buf; - if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, buf, sizeof(buf)) != 0) { + if(get_user_default_locale_info(LOCALE_SISO3166CTRYNAME, buf)) { lc_name += "_"; lc_name += buf; } - if(!use_utf8) { - if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, buf, sizeof(buf)) != 0) { - if(atoi(buf) == 0) - lc_name += ".UTF-8"; - else { - lc_name += ".windows-"; - lc_name += buf; - } - } else { - lc_name += "UTF-8"; - } - } else { + if(use_utf8_on_windows || !get_user_default_locale_info(LOCALE_IDEFAULTANSICODEPAGE, buf)) lc_name += ".UTF-8"; + else { + if(atoi(buf) == 0) + lc_name += ".UTF-8"; + else + lc_name.append(".windows-").append(buf); } return lc_name; diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp b/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp new file mode 100644 index 0000000000..232fdaf245 --- /dev/null +++ b/contrib/restricted/boost/locale/src/boost/locale/util/encoding.cpp @@ -0,0 +1,78 @@ +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2022-2023 Alexander Grund +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include "boost/locale/util/encoding.hpp" +#include "boost/locale/util/string.hpp" +#include <boost/assert.hpp> +#if BOOST_LOCALE_USE_WIN32_API +# include "boost/locale/util/win_codepages.hpp" +# ifndef NOMINMAX +# define NOMINMAX +# endif +# include <windows.h> +#endif +#include <algorithm> +#include <cstring> + +namespace boost { namespace locale { namespace util { + static std::string do_normalize_encoding(const char* encoding, const size_t len) + { + std::string result; + result.reserve(len); + for(char c = *encoding; c != 0; 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; + } + + std::string normalize_encoding(const std::string& encoding) + { + return do_normalize_encoding(encoding.c_str(), encoding.size()); + } + + std::string normalize_encoding(const char* encoding) + { + return do_normalize_encoding(encoding, std::strlen(encoding)); + } + +#if BOOST_LOCALE_USE_WIN32_API + static int normalized_encoding_to_windows_codepage(const std::string& encoding) + { + constexpr size_t n = sizeof(all_windows_encodings) / sizeof(all_windows_encodings[0]); + windows_encoding* begin = all_windows_encodings; + windows_encoding* end = all_windows_encodings + n; + + windows_encoding* ptr = std::lower_bound(begin, 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 char* encoding) + { + return normalized_encoding_to_windows_codepage(normalize_encoding(encoding)); + } + + int encoding_to_windows_codepage(const std::string& encoding) + { + return normalized_encoding_to_windows_codepage(normalize_encoding(encoding)); + } + +#endif +}}} // namespace boost::locale::util diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/encoding.hpp b/contrib/restricted/boost/locale/src/boost/locale/util/encoding.hpp new file mode 100644 index 0000000000..958233fb35 --- /dev/null +++ b/contrib/restricted/boost/locale/src/boost/locale/util/encoding.hpp @@ -0,0 +1,55 @@ +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2022-2023 Alexander Grund +// +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_LOCALE_UTIL_ENCODING_HPP +#define BOOST_LOCALE_UTIL_ENCODING_HPP + +#include <boost/locale/config.hpp> +#include <cstdint> +#include <string> + +namespace boost { namespace locale { namespace util { + + /// Get the UTF encoding name of the given \a CharType + template<typename CharType> + const char* utf_name() + { + constexpr auto CharSize = sizeof(CharType); + static_assert(CharSize == 1 || CharSize == 2 || CharSize == 4, "Unknown Character Encoding"); + switch(CharSize) { + case 1: return "UTF-8"; + case 2: { + const int16_t endianMark = 1; + const bool isLittleEndian = reinterpret_cast<const char*>(&endianMark)[0] == 1; + return isLittleEndian ? "UTF-16LE" : "UTF-16BE"; + } + case 4: { + const int32_t endianMark = 1; + const bool isLittleEndian = reinterpret_cast<const char*>(&endianMark)[0] == 1; + return isLittleEndian ? "UTF-32LE" : "UTF-32BE"; + } + } + BOOST_UNREACHABLE_RETURN("Unknown UTF"); + } + + /// Make encoding lowercase and remove all non-alphanumeric characters + BOOST_LOCALE_DECL std::string normalize_encoding(const std::string& encoding); + BOOST_LOCALE_DECL std::string normalize_encoding(const char* encoding); + /// True if the normalized encodings are equal + inline bool are_encodings_equal(const std::string& l, const std::string& r) + { + return normalize_encoding(l) == normalize_encoding(r); + } + +#if BOOST_LOCALE_USE_WIN32_API + int encoding_to_windows_codepage(const char* encoding); + int encoding_to_windows_codepage(const std::string& encoding); +#endif + +}}} // namespace boost::locale::util + +#endif diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp b/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp index 882366b838..5c74b54eee 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/gregorian.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/util/gregorian.hpp" #include <boost/locale/date_time.hpp> #include <boost/locale/date_time_facet.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/iconv.hpp b/contrib/restricted/boost/locale/src/boost/locale/util/iconv.hpp index cca703a3f3..25701f7eca 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/util/iconv.hpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/iconv.hpp @@ -7,9 +7,38 @@ #ifndef BOOST_LOCALE_ICONV_FIXER_HPP #define BOOST_LOCALE_ICONV_FIXER_HPP +#include <boost/core/exchange.hpp> #include <iconv.h> namespace boost { namespace locale { + class iconv_handle { + iconv_t h_; + void close() + { + if(*this) + iconv_close(h_); + } + + public: + iconv_handle(iconv_t h = iconv_t(-1)) : h_(h) {} + iconv_handle(iconv_handle&& rhs) noexcept : h_(exchange(rhs.h_, iconv_t(-1))) {} + iconv_handle& operator=(iconv_handle&& rhs) noexcept + { + h_ = exchange(rhs.h_, iconv_t(-1)); + return *this; + } + iconv_handle& operator=(iconv_t h) + { + close(); + h_ = h; + return *this; + } + ~iconv_handle() { close(); } + + operator iconv_t() const { return h_; } + explicit operator bool() const { return h_ != iconv_t(-1); } + }; + extern "C" { #if defined(__ICONV_F_HIDE_INVALID) && defined(__FreeBSD__) # define BOOST_LOCALE_ICONV_FUNC __iconv diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp b/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp index 16b93e04ea..65f8167a59 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/info.cpp @@ -4,18 +4,16 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/generator.hpp> #include <boost/locale/info.hpp> #include <boost/locale/util.hpp> +#include <boost/locale/util/locale_data.hpp> #include <cstdlib> #include <ios> #include <locale> #include <sstream> #include <string> -#include "boost/locale/util/locale_data.hpp" - namespace boost { namespace locale { namespace util { class simple_info : public info { @@ -24,10 +22,10 @@ namespace boost { namespace locale { namespace util { std::string get_string_property(string_propery v) const override { switch(v) { - case language_property: return d.language; - case country_property: return d.country; - case variant_property: return d.variant; - case encoding_property: return d.encoding; + case language_property: return d.language(); + case country_property: return d.country(); + case variant_property: return d.variant(); + case encoding_property: return d.encoding(); case name_property: return name_; } return ""; @@ -36,7 +34,7 @@ namespace boost { namespace locale { namespace util { int get_integer_property(integer_property v) const override { switch(v) { - case utf8_property: return d.utf8; + case utf8_property: return d.is_utf8(); } return 0; } diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp b/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp index fced746aae..113d27fffc 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.cpp @@ -1,103 +1,160 @@ // // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// Copyright (c) 2022-2023 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE -#include "boost/locale/util/locale_data.hpp" +#include <boost/locale/util/locale_data.hpp> #include "boost/locale/encoding/conv.hpp" +#include "boost/locale/util/encoding.hpp" +#include "boost/locale/util/string.hpp" +#include <boost/assert.hpp> +#include <algorithm> +#include <stdexcept> #include <string> namespace boost { namespace locale { namespace util { - void locale_data::parse(const std::string& locale_name) + locale_data::locale_data() { - language = "C"; - country.clear(); - variant.clear(); - encoding = "us-ascii"; - utf8 = false; - parse_from_lang(locale_name); + reset(); } - void locale_data::parse_from_lang(const std::string& locale_name) + locale_data::locale_data(const std::string& locale_name) { - size_t end = locale_name.find_first_of("-_@."); - std::string tmp = locale_name.substr(0, end); + if(!parse(locale_name)) + throw std::invalid_argument("Failed to parse locale name: " + locale_name); + } + + void locale_data::reset() + { + language_ = "C"; + country_.clear(); + encoding_ = "US-ASCII"; + variant_.clear(); + utf8_ = false; + } + + std::string locale_data::to_string() const + { + std::string result = language_; + if(!country_.empty()) + (result += '_') += country_; + if(!encoding_.empty() && !util::are_encodings_equal(encoding_, "US-ASCII")) + (result += '.') += encoding_; + if(!variant_.empty()) + (result += '@') += variant_; + return result; + } + + bool locale_data::parse(const std::string& locale_name) + { + reset(); + return parse_from_lang(locale_name); + } + + bool locale_data::parse_from_lang(const std::string& input) + { + const auto end = input.find_first_of("-_@."); + std::string tmp = input.substr(0, end); if(tmp.empty()) - return; - for(unsigned i = 0; i < tmp.size(); i++) { - if('A' <= tmp[i] && tmp[i] <= 'Z') - tmp[i] = tmp[i] - 'A' + 'a'; - else if(tmp[i] < 'a' || 'z' < tmp[i]) - return; + return false; + // lowercase ASCII + for(char& c : tmp) { + if(is_upper_ascii(c)) + c += 'a' - 'A'; + else if(!is_lower_ascii(c)) + return false; } - language = tmp; - if(end >= locale_name.size()) - return; - - if(locale_name[end] == '-' || locale_name[end] == '_') { - parse_from_country(locale_name.substr(end + 1)); - } else if(locale_name[end] == '.') { - parse_from_encoding(locale_name.substr(end + 1)); - } else if(locale_name[end] == '@') { - parse_from_variant(locale_name.substr(end + 1)); + if(tmp != "c" && tmp != "posix") // Keep default + language_ = tmp; + + if(end >= input.size()) + return true; + else if(input[end] == '-' || input[end] == '_') + return parse_from_country(input.substr(end + 1)); + else if(input[end] == '.') + return parse_from_encoding(input.substr(end + 1)); + else { + BOOST_ASSERT_MSG(input[end] == '@', "Unexpected delimiter"); + return parse_from_variant(input.substr(end + 1)); } } - void locale_data::parse_from_country(const std::string& locale_name) + bool locale_data::parse_from_country(const std::string& input) { - size_t end = locale_name.find_first_of("@."); - std::string tmp = locale_name.substr(0, end); + if(language_ == "C") + return false; + + const auto end = input.find_first_of("@."); + std::string tmp = input.substr(0, end); if(tmp.empty()) - return; - for(unsigned i = 0; i < tmp.size(); i++) { - if('a' <= tmp[i] && tmp[i] <= 'z') - tmp[i] = tmp[i] - 'a' + 'A'; - else if(tmp[i] < 'A' || 'Z' < tmp[i]) - return; - } + return false; - country = tmp; + // Make uppercase + for(char& c : tmp) { + if(util::is_lower_ascii(c)) + c += 'A' - 'a'; + } + // If it's ALL uppercase ASCII, assume ISO 3166 country id + if(std::find_if_not(tmp.begin(), tmp.end(), util::is_upper_ascii) != tmp.end()) { + // else handle special cases: + // - en_US_POSIX is an alias for C + // - M49 country code: 3 digits + if(language_ == "en" && tmp == "US_POSIX") { + language_ = "C"; + tmp.clear(); + } else if(tmp.size() != 3u || std::find_if_not(tmp.begin(), tmp.end(), util::is_numeric_ascii) != tmp.end()) + return false; + } - if(end >= locale_name.size()) - return; - else if(locale_name[end] == '.') { - parse_from_encoding(locale_name.substr(end + 1)); - } else if(locale_name[end] == '@') { - parse_from_variant(locale_name.substr(end + 1)); + country_ = tmp; + if(end >= input.size()) + return true; + else if(input[end] == '.') + return parse_from_encoding(input.substr(end + 1)); + else { + BOOST_ASSERT_MSG(input[end] == '@', "Unexpected delimiter"); + return parse_from_variant(input.substr(end + 1)); } } - void locale_data::parse_from_encoding(const std::string& locale_name) + bool locale_data::parse_from_encoding(const std::string& input) { - size_t end = locale_name.find_first_of('@'); - std::string tmp = locale_name.substr(0, end); + const auto end = input.find_first_of('@'); + std::string tmp = input.substr(0, end); if(tmp.empty()) - return; - for(unsigned i = 0; i < tmp.size(); i++) { - if('A' <= tmp[i] && tmp[i] <= 'Z') - tmp[i] = tmp[i] - 'A' + 'a'; + return false; + // No assumptions, but uppercase + for(char& c : tmp) { + if(util::is_lower_ascii(c)) + c += 'A' - 'a'; } - encoding = tmp; - - utf8 = conv::impl::normalize_encoding(encoding.c_str()) == "utf8"; + encoding_ = tmp; - if(end >= locale_name.size()) - return; + utf8_ = util::normalize_encoding(encoding_) == "utf8"; - if(locale_name[end] == '@') { - parse_from_variant(locale_name.substr(end + 1)); + if(end >= input.size()) + return true; + else { + BOOST_ASSERT_MSG(input[end] == '@', "Unexpected delimiter"); + return parse_from_variant(input.substr(end + 1)); } } - void locale_data::parse_from_variant(const std::string& locale_name) + bool locale_data::parse_from_variant(const std::string& input) { - variant = locale_name; - for(unsigned i = 0; i < variant.size(); i++) { - if('A' <= variant[i] && variant[i] <= 'Z') - variant[i] = variant[i] - 'A' + 'a'; + if(language_ == "C") + return false; + if(input.empty()) + return false; + variant_ = input; + // No assumptions, just make it lowercase + for(char& c : variant_) { + if(util::is_upper_ascii(c)) + c += 'a' - 'A'; } + return true; } }}} // namespace boost::locale::util diff --git a/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.hpp b/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.hpp deleted file mode 100644 index 2190b62050..0000000000 --- a/contrib/restricted/boost/locale/src/boost/locale/util/locale_data.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt - -#ifndef BOOST_LOCALE_IMPL_UTIL_LOCALE_DATA_HPP -#define BOOST_LOCALE_IMPL_UTIL_LOCALE_DATA_HPP - -#include <string> - -namespace boost { namespace locale { namespace util { - - class locale_data { - public: - locale_data() : language("C"), encoding("us-ascii"), utf8(false) {} - - std::string language; - std::string country; - std::string variant; - std::string encoding; - bool utf8; - - void parse(const std::string& locale_name); - - private: - void parse_from_lang(const std::string& locale_name); - void parse_from_country(const std::string& locale_name); - void parse_from_encoding(const std::string& locale_name); - void parse_from_variant(const std::string& locale_name); - }; - -}}} // namespace boost::locale::util - -#endif diff --git a/contrib/restricted/boost/locale/src/boost/locale/encoding/win_codepages.hpp b/contrib/restricted/boost/locale/src/boost/locale/util/win_codepages.hpp index 8dd4bfe3b7..4c3df668b5 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/encoding/win_codepages.hpp +++ b/contrib/restricted/boost/locale/src/boost/locale/util/win_codepages.hpp @@ -3,9 +3,8 @@ #include <boost/locale/config.hpp> #include <cstring> -#include <string> -namespace boost { namespace locale { namespace conv { namespace impl { +namespace boost { namespace locale { namespace util { struct windows_encoding { const char* name; @@ -177,6 +176,6 @@ namespace boost { namespace locale { namespace conv { namespace impl { {"xmacturkish", 10081, 0}, {"xmacukrainian", 10017, 0}, }; -}}}} // namespace boost::locale::conv::impl +}}} // namespace boost::locale::util #endif
\ No newline at end of file diff --git a/contrib/restricted/boost/locale/src/boost/locale/win32/collate.cpp b/contrib/restricted/boost/locale/src/boost/locale/win32/collate.cpp index aa8be85d71..bd78c2116d 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/win32/collate.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/win32/collate.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include <boost/locale/encoding.hpp> #include <boost/locale/generator.hpp> #include "boost/locale/shared/mo_hash.hpp" diff --git a/contrib/restricted/boost/locale/src/boost/locale/win32/converter.cpp b/contrib/restricted/boost/locale/src/boost/locale/win32/converter.cpp index 15090bc205..6911ab5996 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/win32/converter.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/win32/converter.cpp @@ -4,8 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE - #include <boost/locale/conversion.hpp> #include <boost/locale/encoding.hpp> #include <boost/locale/generator.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/win32/lcid.cpp b/contrib/restricted/boost/locale/src/boost/locale/win32/lcid.cpp index f4c47a5dc4..f27cd099e5 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/win32/lcid.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/win32/lcid.cpp @@ -4,13 +4,12 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #ifndef NOMINMAX # define NOMINMAX #endif #include "boost/locale/win32/lcid.hpp" -#include "boost/locale/util/locale_data.hpp" +#include <boost/locale/util/locale_data.hpp> #include <boost/thread/locks.hpp> #include <boost/thread/mutex.hpp> #include <map> @@ -95,13 +94,13 @@ namespace boost { namespace locale { namespace impl_win { } boost::locale::util::locale_data d; d.parse(locale_name); - std::string id = d.language; + std::string id = d.language(); - if(!d.country.empty()) { - id += "_" + d.country; + if(!d.country().empty()) { + id += "_" + d.country(); } - if(!d.variant.empty()) { - id += "@" + d.variant; + if(!d.variant().empty()) { + id += "@" + d.variant(); } const table_type& tbl = get_ready_lcid_table(); diff --git a/contrib/restricted/boost/locale/src/boost/locale/win32/numeric.cpp b/contrib/restricted/boost/locale/src/boost/locale/win32/numeric.cpp index d6725295d2..2654be7ed4 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/win32/numeric.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/win32/numeric.cpp @@ -4,7 +4,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/util/numeric.hpp" #include <boost/locale/encoding.hpp> #include <boost/locale/formatting.hpp> diff --git a/contrib/restricted/boost/locale/src/boost/locale/win32/win_backend.cpp b/contrib/restricted/boost/locale/src/boost/locale/win32/win_backend.cpp index b7aae73b84..c1a8107423 100644 --- a/contrib/restricted/boost/locale/src/boost/locale/win32/win_backend.cpp +++ b/contrib/restricted/boost/locale/src/boost/locale/win32/win_backend.cpp @@ -4,14 +4,13 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_LOCALE_SOURCE #include "boost/locale/win32/win_backend.hpp" #include <boost/locale/gnu_gettext.hpp> #include <boost/locale/info.hpp> #include <boost/locale/localization_backend.hpp> #include <boost/locale/util.hpp> +#include <boost/locale/util/locale_data.hpp> #include "boost/locale/util/gregorian.hpp" -#include "boost/locale/util/locale_data.hpp" #include "boost/locale/win32/all_generator.hpp" #include "boost/locale/win32/api.hpp" #include <algorithm> @@ -61,7 +60,7 @@ namespace boost { namespace locale { namespace impl_win { } util::locale_data d; d.parse(real_id_); - if(!d.utf8) { + if(!d.is_utf8()) { lc_ = winlocale(); // Make it C as non-UTF8 locales are not supported } @@ -79,7 +78,7 @@ namespace boost { namespace locale { namespace impl_win { case category_t::calendar: { util::locale_data inf; inf.parse(real_id_); - return util::install_gregorian_calendar(base, inf.country); + return util::install_gregorian_calendar(base, inf.country()); } case category_t::message: { gnu_gettext::messages_info minf; |