diff options
author | neksard <neksard@yandex-team.ru> | 2022-02-10 16:45:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:33 +0300 |
commit | 1d9c550e7c38e051d7961f576013a482003a70d9 (patch) | |
tree | b2cc84ee7850122e7ccf51d0ea21e4fa7e7a5685 /contrib/restricted/boost/libs/locale/src/std | |
parent | 8f7cf138264e0caa318144bf8a2c950e0b0a8593 (diff) | |
download | ydb-1d9c550e7c38e051d7961f576013a482003a70d9.tar.gz |
Restoring authorship annotation for <neksard@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/boost/libs/locale/src/std')
7 files changed, 1078 insertions, 1078 deletions
diff --git a/contrib/restricted/boost/libs/locale/src/std/all_generator.hpp b/contrib/restricted/boost/libs/locale/src/std/all_generator.hpp index 7c7b12af81..d79525b71b 100644 --- a/contrib/restricted/boost/libs/locale/src/std/all_generator.hpp +++ b/contrib/restricted/boost/libs/locale/src/std/all_generator.hpp @@ -1,54 +1,54 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#ifndef BOOST_LOCALE_IMPL_STD_ALL_GENERATOR_HPP -#define BOOST_LOCALE_IMPL_STD_ALL_GENERATOR_HPP - -#include <boost/locale/generator.hpp> -#include <vector> - -namespace boost { - namespace locale { - namespace impl_std { - typedef enum { - utf8_none, - utf8_native, - utf8_native_with_wide, - utf8_from_wide - } utf8_support; - - std::locale create_convert( std::locale const &in, - std::string const &locale_name, - character_facet_type type, +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#ifndef BOOST_LOCALE_IMPL_STD_ALL_GENERATOR_HPP +#define BOOST_LOCALE_IMPL_STD_ALL_GENERATOR_HPP + +#include <boost/locale/generator.hpp> +#include <vector> + +namespace boost { + namespace locale { + namespace impl_std { + typedef enum { + utf8_none, + utf8_native, + utf8_native_with_wide, + utf8_from_wide + } utf8_support; + + std::locale create_convert( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf = utf8_none); + + std::locale create_collate( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf = utf8_none); + + std::locale create_formatting( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf = utf8_none); + + std::locale create_parsing( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf = utf8_none); + + std::locale create_codecvt( std::locale const &in, + std::string const &locale_name, + character_facet_type type, utf8_support utf = utf8_none); - - std::locale create_collate( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf = utf8_none); - - std::locale create_formatting( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf = utf8_none); - - std::locale create_parsing( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf = utf8_none); - - std::locale create_codecvt( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf = utf8_none); - - } - } -} - -#endif -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 + + } + } +} + +#endif +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/contrib/restricted/boost/libs/locale/src/std/codecvt.cpp b/contrib/restricted/boost/libs/locale/src/std/codecvt.cpp index e8d14658d6..9b62d2f4f6 100644 --- a/contrib/restricted/boost/libs/locale/src/std/codecvt.cpp +++ b/contrib/restricted/boost/libs/locale/src/std/codecvt.cpp @@ -1,55 +1,55 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#define BOOST_LOCALE_SOURCE -#include <locale> -#include <boost/cstdint.hpp> -#include <boost/locale/util.hpp> -#include "all_generator.hpp" -#include <vector> -namespace boost { -namespace locale { -namespace impl_std { - template<typename CharType> - std::locale codecvt_bychar( std::locale const &in, - std::string const &locale_name) - { - return std::locale(in,new std::codecvt_byname<CharType,char,std::mbstate_t>(locale_name.c_str())); - } - - - std::locale create_codecvt( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf) - { - if(utf == utf8_from_wide) { - return util::create_utf8_codecvt(in,type); - } - switch(type) { - case char_facet: - return codecvt_bychar<char>(in,locale_name); - case wchar_t_facet: - return codecvt_bychar<wchar_t>(in,locale_name); - #if defined(BOOST_LOCALE_ENABLE_CHAR16_T) && !defined(BOOST_NO_CHAR16_T_CODECVT) - case char16_t_facet: - return codecvt_bychar<char16_t>(in,locale_name); - #endif - #if defined(BOOST_LOCALE_ENABLE_CHAR32_T) && !defined(BOOST_NO_CHAR32_T_CODECVT) - case char32_t_facet: - return codecvt_bychar<char32_t>(in,locale_name); - #endif - default: - return in; - } - } - -} // impl_std -} // locale -} // boost - -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#define BOOST_LOCALE_SOURCE +#include <locale> +#include <boost/cstdint.hpp> +#include <boost/locale/util.hpp> +#include "all_generator.hpp" +#include <vector> +namespace boost { +namespace locale { +namespace impl_std { + template<typename CharType> + std::locale codecvt_bychar( std::locale const &in, + std::string const &locale_name) + { + return std::locale(in,new std::codecvt_byname<CharType,char,std::mbstate_t>(locale_name.c_str())); + } + + + std::locale create_codecvt( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf) + { + if(utf == utf8_from_wide) { + return util::create_utf8_codecvt(in,type); + } + switch(type) { + case char_facet: + return codecvt_bychar<char>(in,locale_name); + case wchar_t_facet: + return codecvt_bychar<wchar_t>(in,locale_name); + #if defined(BOOST_LOCALE_ENABLE_CHAR16_T) && !defined(BOOST_NO_CHAR16_T_CODECVT) + case char16_t_facet: + return codecvt_bychar<char16_t>(in,locale_name); + #endif + #if defined(BOOST_LOCALE_ENABLE_CHAR32_T) && !defined(BOOST_NO_CHAR32_T_CODECVT) + case char32_t_facet: + return codecvt_bychar<char32_t>(in,locale_name); + #endif + default: + return in; + } + } + +} // impl_std +} // locale +} // boost + +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/contrib/restricted/boost/libs/locale/src/std/collate.cpp b/contrib/restricted/boost/libs/locale/src/std/collate.cpp index 8eccdecb52..8b7127ad77 100644 --- a/contrib/restricted/boost/libs/locale/src/std/collate.cpp +++ b/contrib/restricted/boost/libs/locale/src/std/collate.cpp @@ -1,113 +1,113 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#define BOOST_LOCALE_SOURCE -#include <locale> -#include <string> -#include <ios> -#include <boost/locale/encoding.hpp> -#include "all_generator.hpp" - -namespace boost { -namespace locale { -namespace impl_std { - -class utf8_collator_from_wide : public std::collate<char> { -public: - typedef std::collate<wchar_t> wfacet; - utf8_collator_from_wide(std::locale const &base,size_t refs = 0) : - std::collate<char>(refs), - base_(base) - { - } - virtual int do_compare(char const *lb,char const *le,char const *rb,char const *re) const - { - std::wstring l=conv::to_utf<wchar_t>(lb,le,"UTF-8"); - std::wstring r=conv::to_utf<wchar_t>(rb,re,"UTF-8"); - return std::use_facet<wfacet>(base_).compare( l.c_str(),l.c_str()+l.size(), - r.c_str(),r.c_str()+r.size()); - } - virtual long do_hash(char const *b,char const *e) const - { - std::wstring tmp=conv::to_utf<wchar_t>(b,e,"UTF-8"); - return std::use_facet<wfacet>(base_).hash(tmp.c_str(),tmp.c_str()+tmp.size()); - } - virtual std::string do_transform(char const *b,char const *e) const - { - std::wstring tmp=conv::to_utf<wchar_t>(b,e,"UTF-8"); - std::wstring wkey = - std::use_facet<wfacet>(base_).transform(tmp.c_str(),tmp.c_str()+tmp.size()); - std::string key; - if(sizeof(wchar_t)==2) - key.reserve(wkey.size()*2); - else - key.reserve(wkey.size()*3); - for(unsigned i=0;i<wkey.size();i++) { - if(sizeof(wchar_t)==2) { - uint16_t tv = static_cast<uint16_t>(wkey[i]); - key += char(tv >> 8); - key += char(tv & 0xFF); - } - else { // 4 - uint32_t tv = static_cast<uint32_t>(wkey[i]); - // 21 bit - key += char((tv >> 16) & 0xFF); - key += char((tv >> 8) & 0xFF); - key += char(tv & 0xFF); - } - } - return key; - } -private: - std::locale base_; -}; - -std::locale create_collate( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf) -{ - switch(type) { - case char_facet: - { - if(utf == utf8_from_wide) { - std::locale base= - std::locale(std::locale::classic(), - new std::collate_byname<wchar_t>(locale_name.c_str())); - return std::locale(in,new utf8_collator_from_wide(base)); - } - else - { - return std::locale(in,new std::collate_byname<char>(locale_name.c_str())); - } - } - - case wchar_t_facet: - return std::locale(in,new std::collate_byname<wchar_t>(locale_name.c_str())); - - #ifdef BOOST_LOCALE_ENABLE_CHAR16_T - case char16_t_facet: - return std::locale(in,new std::collate_byname<char16_t>(locale_name.c_str())); - #endif - - #ifdef BOOST_LOCALE_ENABLE_CHAR32_T - case char32_t_facet: - return std::locale(in,new std::collate_byname<char32_t>(locale_name.c_str())); - #endif - default: - return in; - } -} - - -} // impl_std -} // locale -} //boost - - - -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#define BOOST_LOCALE_SOURCE +#include <locale> +#include <string> +#include <ios> +#include <boost/locale/encoding.hpp> +#include "all_generator.hpp" + +namespace boost { +namespace locale { +namespace impl_std { + +class utf8_collator_from_wide : public std::collate<char> { +public: + typedef std::collate<wchar_t> wfacet; + utf8_collator_from_wide(std::locale const &base,size_t refs = 0) : + std::collate<char>(refs), + base_(base) + { + } + virtual int do_compare(char const *lb,char const *le,char const *rb,char const *re) const + { + std::wstring l=conv::to_utf<wchar_t>(lb,le,"UTF-8"); + std::wstring r=conv::to_utf<wchar_t>(rb,re,"UTF-8"); + return std::use_facet<wfacet>(base_).compare( l.c_str(),l.c_str()+l.size(), + r.c_str(),r.c_str()+r.size()); + } + virtual long do_hash(char const *b,char const *e) const + { + std::wstring tmp=conv::to_utf<wchar_t>(b,e,"UTF-8"); + return std::use_facet<wfacet>(base_).hash(tmp.c_str(),tmp.c_str()+tmp.size()); + } + virtual std::string do_transform(char const *b,char const *e) const + { + std::wstring tmp=conv::to_utf<wchar_t>(b,e,"UTF-8"); + std::wstring wkey = + std::use_facet<wfacet>(base_).transform(tmp.c_str(),tmp.c_str()+tmp.size()); + std::string key; + if(sizeof(wchar_t)==2) + key.reserve(wkey.size()*2); + else + key.reserve(wkey.size()*3); + for(unsigned i=0;i<wkey.size();i++) { + if(sizeof(wchar_t)==2) { + uint16_t tv = static_cast<uint16_t>(wkey[i]); + key += char(tv >> 8); + key += char(tv & 0xFF); + } + else { // 4 + uint32_t tv = static_cast<uint32_t>(wkey[i]); + // 21 bit + key += char((tv >> 16) & 0xFF); + key += char((tv >> 8) & 0xFF); + key += char(tv & 0xFF); + } + } + return key; + } +private: + std::locale base_; +}; + +std::locale create_collate( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf) +{ + switch(type) { + case char_facet: + { + if(utf == utf8_from_wide) { + std::locale base= + std::locale(std::locale::classic(), + new std::collate_byname<wchar_t>(locale_name.c_str())); + return std::locale(in,new utf8_collator_from_wide(base)); + } + else + { + return std::locale(in,new std::collate_byname<char>(locale_name.c_str())); + } + } + + case wchar_t_facet: + return std::locale(in,new std::collate_byname<wchar_t>(locale_name.c_str())); + + #ifdef BOOST_LOCALE_ENABLE_CHAR16_T + case char16_t_facet: + return std::locale(in,new std::collate_byname<char16_t>(locale_name.c_str())); + #endif + + #ifdef BOOST_LOCALE_ENABLE_CHAR32_T + case char32_t_facet: + return std::locale(in,new std::collate_byname<char32_t>(locale_name.c_str())); + #endif + default: + return in; + } +} + + +} // impl_std +} // locale +} //boost + + + +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/contrib/restricted/boost/libs/locale/src/std/converter.cpp b/contrib/restricted/boost/libs/locale/src/std/converter.cpp index 2a4b55b97e..e4f925ade4 100644 --- a/contrib/restricted/boost/libs/locale/src/std/converter.cpp +++ b/contrib/restricted/boost/libs/locale/src/std/converter.cpp @@ -1,148 +1,148 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#define BOOST_LOCALE_SOURCE - -#include <boost/config.hpp> -#ifdef BOOST_MSVC -# pragma warning(disable : 4996) -#endif - -#include <locale> -#include <stdexcept> -#include <boost/locale/generator.hpp> -#include <boost/locale/conversion.hpp> -#include <boost/locale/encoding.hpp> -#include <vector> - - - -#include "all_generator.hpp" - -namespace boost { -namespace locale { -namespace impl_std { - - -template<typename CharType> -class std_converter : public converter<CharType> -{ -public: - typedef CharType char_type; - typedef std::basic_string<char_type> string_type; - typedef std::ctype<char_type> ctype_type; - std_converter(std::locale const &base,size_t refs = 0) : - converter<CharType>(refs), - base_(base) - { - } - virtual string_type convert(converter_base::conversion_type how,char_type const *begin,char_type const *end,int /*flags*/ = 0) const - { - switch(how) { - case converter_base::upper_case: - case converter_base::lower_case: - case converter_base::case_folding: - { - ctype_type const &ct=std::use_facet<ctype_type>(base_); - size_t len = end - begin; - std::vector<char_type> res(len+1,0); - char_type *lbegin = &res[0]; - std::copy(begin,end,lbegin); - if(how == converter_base::upper_case) - ct.toupper(lbegin,lbegin+len); - else - ct.tolower(lbegin,lbegin+len); - return string_type(lbegin,len); - } - default: - return string_type(begin,end-begin); - } - } -private: - std::locale base_; -}; - -class utf8_converter : public converter<char> { -public: - typedef std::ctype<char> ctype_type; - typedef std::ctype<wchar_t> wctype_type; - utf8_converter(std::locale const &base,size_t refs = 0) : - converter<char>(refs), - base_(base) - { - } - virtual std::string convert(converter_base::conversion_type how,char const *begin,char const *end,int /*flags*/ = 0) const - { - switch(how) { - case upper_case: - case lower_case: - case case_folding: - { - std::wstring tmp = conv::to_utf<wchar_t>(begin,end,"UTF-8"); - wctype_type const &ct=std::use_facet<wctype_type>(base_); - size_t len = tmp.size(); - std::vector<wchar_t> res(len+1,0); - wchar_t *lbegin = &res[0]; - std::copy(tmp.c_str(),tmp.c_str()+len,lbegin); - if(how == upper_case) - ct.toupper(lbegin,lbegin+len); - else - ct.tolower(lbegin,lbegin+len); - return conv::from_utf<wchar_t>(lbegin,lbegin+len,"UTF-8"); - } - default: - return std::string(begin,end-begin); - } - } -private: - std::locale base_; -}; - -std::locale create_convert( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf) -{ - switch(type) { - case char_facet: - { - if(utf == utf8_native_with_wide || utf == utf8_from_wide) { - std::locale base(std::locale::classic(),new std::ctype_byname<wchar_t>(locale_name.c_str())); - return std::locale(in,new utf8_converter(base)); - } - std::locale base(std::locale::classic(),new std::ctype_byname<char>(locale_name.c_str())); - return std::locale(in,new std_converter<char>(base)); - } - case wchar_t_facet: - { - std::locale base(std::locale::classic(),new std::ctype_byname<wchar_t>(locale_name.c_str())); - return std::locale(in,new std_converter<wchar_t>(base)); - } - #ifdef BOOST_LOCALE_ENABLE_CHAR16_T - case char16_t_facet: - { - std::locale base(std::locale::classic(),new std::ctype_byname<char16_t>(locale_name.c_str())); - return std::locale(in,new std_converter<char16_t>(base)); - } - #endif - #ifdef BOOST_LOCALE_ENABLE_CHAR32_T - case char32_t_facet: - { - std::locale base(std::locale::classic(),new std::ctype_byname<char32_t>(locale_name.c_str())); - return std::locale(in,new std_converter<char32_t>(base)); - } - #endif - default: - return in; - } -} - - -} // namespace impl_std -} // locale -} // boost -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#define BOOST_LOCALE_SOURCE + +#include <boost/config.hpp> +#ifdef BOOST_MSVC +# pragma warning(disable : 4996) +#endif + +#include <locale> +#include <stdexcept> +#include <boost/locale/generator.hpp> +#include <boost/locale/conversion.hpp> +#include <boost/locale/encoding.hpp> +#include <vector> + + + +#include "all_generator.hpp" + +namespace boost { +namespace locale { +namespace impl_std { + + +template<typename CharType> +class std_converter : public converter<CharType> +{ +public: + typedef CharType char_type; + typedef std::basic_string<char_type> string_type; + typedef std::ctype<char_type> ctype_type; + std_converter(std::locale const &base,size_t refs = 0) : + converter<CharType>(refs), + base_(base) + { + } + virtual string_type convert(converter_base::conversion_type how,char_type const *begin,char_type const *end,int /*flags*/ = 0) const + { + switch(how) { + case converter_base::upper_case: + case converter_base::lower_case: + case converter_base::case_folding: + { + ctype_type const &ct=std::use_facet<ctype_type>(base_); + size_t len = end - begin; + std::vector<char_type> res(len+1,0); + char_type *lbegin = &res[0]; + std::copy(begin,end,lbegin); + if(how == converter_base::upper_case) + ct.toupper(lbegin,lbegin+len); + else + ct.tolower(lbegin,lbegin+len); + return string_type(lbegin,len); + } + default: + return string_type(begin,end-begin); + } + } +private: + std::locale base_; +}; + +class utf8_converter : public converter<char> { +public: + typedef std::ctype<char> ctype_type; + typedef std::ctype<wchar_t> wctype_type; + utf8_converter(std::locale const &base,size_t refs = 0) : + converter<char>(refs), + base_(base) + { + } + virtual std::string convert(converter_base::conversion_type how,char const *begin,char const *end,int /*flags*/ = 0) const + { + switch(how) { + case upper_case: + case lower_case: + case case_folding: + { + std::wstring tmp = conv::to_utf<wchar_t>(begin,end,"UTF-8"); + wctype_type const &ct=std::use_facet<wctype_type>(base_); + size_t len = tmp.size(); + std::vector<wchar_t> res(len+1,0); + wchar_t *lbegin = &res[0]; + std::copy(tmp.c_str(),tmp.c_str()+len,lbegin); + if(how == upper_case) + ct.toupper(lbegin,lbegin+len); + else + ct.tolower(lbegin,lbegin+len); + return conv::from_utf<wchar_t>(lbegin,lbegin+len,"UTF-8"); + } + default: + return std::string(begin,end-begin); + } + } +private: + std::locale base_; +}; + +std::locale create_convert( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf) +{ + switch(type) { + case char_facet: + { + if(utf == utf8_native_with_wide || utf == utf8_from_wide) { + std::locale base(std::locale::classic(),new std::ctype_byname<wchar_t>(locale_name.c_str())); + return std::locale(in,new utf8_converter(base)); + } + std::locale base(std::locale::classic(),new std::ctype_byname<char>(locale_name.c_str())); + return std::locale(in,new std_converter<char>(base)); + } + case wchar_t_facet: + { + std::locale base(std::locale::classic(),new std::ctype_byname<wchar_t>(locale_name.c_str())); + return std::locale(in,new std_converter<wchar_t>(base)); + } + #ifdef BOOST_LOCALE_ENABLE_CHAR16_T + case char16_t_facet: + { + std::locale base(std::locale::classic(),new std::ctype_byname<char16_t>(locale_name.c_str())); + return std::locale(in,new std_converter<char16_t>(base)); + } + #endif + #ifdef BOOST_LOCALE_ENABLE_CHAR32_T + case char32_t_facet: + { + std::locale base(std::locale::classic(),new std::ctype_byname<char32_t>(locale_name.c_str())); + return std::locale(in,new std_converter<char32_t>(base)); + } + #endif + default: + return in; + } +} + + +} // namespace impl_std +} // locale +} // boost +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/contrib/restricted/boost/libs/locale/src/std/numeric.cpp b/contrib/restricted/boost/libs/locale/src/std/numeric.cpp index 0c2758e052..cbb0d9de31 100644 --- a/contrib/restricted/boost/libs/locale/src/std/numeric.cpp +++ b/contrib/restricted/boost/libs/locale/src/std/numeric.cpp @@ -1,456 +1,456 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#define BOOST_LOCALE_SOURCE -#include <locale> -#include <string> -#include <ios> -#include <boost/locale/formatting.hpp> -#include <boost/locale/generator.hpp> -#include <boost/locale/encoding.hpp> -#include <sstream> -#include <stdlib.h> - -#include "../util/numeric.hpp" -#include "all_generator.hpp" - -namespace boost { -namespace locale { -namespace impl_std { - -template<typename CharType> -class time_put_from_base : public std::time_put<CharType> { -public: - time_put_from_base(std::locale const &base, size_t refs = 0) : - std::time_put<CharType>(refs), - base_(base) - { - } - typedef typename std::time_put<CharType>::iter_type iter_type; - - virtual iter_type do_put(iter_type out,std::ios_base &/*ios*/,CharType fill,std::tm const *tm,char format,char modifier) const - { - std::basic_stringstream<CharType> ss; - ss.imbue(base_); - return std::use_facet<std::time_put<CharType> >(base_).put(out,ss,fill,tm,format,modifier); - } -private: - std::locale base_; -}; - -class utf8_time_put_from_wide : public std::time_put<char> { -public: - utf8_time_put_from_wide(std::locale const &base, size_t refs = 0) : - std::time_put<char>(refs), - base_(base) - { - } - virtual iter_type do_put(iter_type out,std::ios_base &/*ios*/,char fill,std::tm const *tm,char format,char modifier = 0) const - { - std::basic_ostringstream<wchar_t> wtmps; - wtmps.imbue(base_); - std::use_facet<std::time_put<wchar_t> >(base_).put(wtmps,wtmps,wchar_t(fill),tm,wchar_t(format),wchar_t(modifier)); - std::wstring wtmp=wtmps.str(); - std::string const tmp = conv::from_utf<wchar_t>(wtmp,"UTF-8"); - for(unsigned i=0;i<tmp.size();i++) { - *out++ = tmp[i]; - } - return out; - } -private: - std::locale base_; -}; - -class utf8_numpunct_from_wide : public std::numpunct<char> { -public: - utf8_numpunct_from_wide(std::locale const &base,size_t refs = 0) : std::numpunct<char>(refs) - { - typedef std::numpunct<wchar_t> wfacet_type; - wfacet_type const &wfacet = std::use_facet<wfacet_type>(base); - - truename_ = conv::from_utf<wchar_t>(wfacet.truename(),"UTF-8"); - falsename_ = conv::from_utf<wchar_t>(wfacet.falsename(),"UTF-8"); - - wchar_t tmp_decimal_point = wfacet.decimal_point(); - wchar_t tmp_thousands_sep = wfacet.thousands_sep(); - std::string tmp_grouping = wfacet.grouping(); - - if( 32 <= tmp_thousands_sep && tmp_thousands_sep <=126 && - 32 <= tmp_decimal_point && tmp_decimal_point <=126) - { - thousands_sep_ = static_cast<char>(tmp_thousands_sep); - decimal_point_ = static_cast<char>(tmp_decimal_point); - grouping_ = tmp_grouping; - } - else if(32 <= tmp_decimal_point && tmp_decimal_point <=126 && tmp_thousands_sep == 0xA0) { - // workaround common bug - substitute NBSP with ordinary space - thousands_sep_ = ' '; - decimal_point_ = static_cast<char>(tmp_decimal_point); - grouping_ = tmp_grouping; - } - else if(32 <= tmp_decimal_point && tmp_decimal_point <=126) - { - thousands_sep_=','; - decimal_point_ = static_cast<char>(tmp_decimal_point); - grouping_=std::string(); - } - else { - thousands_sep_ = ','; - decimal_point_ = '.'; - grouping_=std::string(); - } - } - - virtual char do_decimal_point() const - { - return decimal_point_; - } - virtual char do_thousands_sep() const - { - return thousands_sep_; - } - virtual std::string do_grouping() const - { - return grouping_; - } - virtual std::string do_truename() const - { - return truename_; - } - virtual std::string do_falsename() const - { - return falsename_; - } -private: - std::string truename_; - std::string falsename_; - char thousands_sep_; - char decimal_point_; - std::string grouping_; - -}; - -template<bool Intl> -class utf8_moneypunct_from_wide : public std::moneypunct<char,Intl> { -public: - utf8_moneypunct_from_wide(std::locale const &base,size_t refs = 0) : std::moneypunct<char,Intl>(refs) - { - typedef std::moneypunct<wchar_t,Intl> wfacet_type; - wfacet_type const &wfacet = std::use_facet<wfacet_type>(base); - - curr_symbol_ = conv::from_utf<wchar_t>(wfacet.curr_symbol(),"UTF-8"); - positive_sign_ = conv::from_utf<wchar_t>(wfacet.positive_sign(),"UTF-8"); - negative_sign_ = conv::from_utf<wchar_t>(wfacet.negative_sign(),"UTF-8"); - frac_digits_ = wfacet.frac_digits(); - pos_format_ = wfacet.pos_format(); - neg_format_ = wfacet.neg_format(); - - wchar_t tmp_decimal_point = wfacet.decimal_point(); - wchar_t tmp_thousands_sep = wfacet.thousands_sep(); - std::string tmp_grouping = wfacet.grouping(); - if( 32 <= tmp_thousands_sep && tmp_thousands_sep <=126 && - 32 <= tmp_decimal_point && tmp_decimal_point <=126) - { - thousands_sep_ = static_cast<char>(tmp_thousands_sep); - decimal_point_ = static_cast<char>(tmp_decimal_point); - grouping_ = tmp_grouping; - } - else if(32 <= tmp_decimal_point && tmp_decimal_point <=126 && tmp_thousands_sep == 0xA0) { - // workaround common bug - substitute NBSP with ordinary space - thousands_sep_ = ' '; - decimal_point_ = static_cast<char>(tmp_decimal_point); - grouping_ = tmp_grouping; - } - else if(32 <= tmp_decimal_point && tmp_decimal_point <=126) - { - thousands_sep_=','; - decimal_point_ = static_cast<char>(tmp_decimal_point); - grouping_=std::string(); - } - else { - thousands_sep_ = ','; - decimal_point_ = '.'; - grouping_=std::string(); - } - } - - virtual char do_decimal_point() const - { - return decimal_point_; - } - - virtual char do_thousands_sep() const - { - return thousands_sep_; - } - - virtual std::string do_grouping() const - { - return grouping_; - } - - virtual std::string do_curr_symbol() const - { - return curr_symbol_; - } - virtual std::string do_positive_sign () const - { - return positive_sign_; - } - virtual std::string do_negative_sign() const - { - return negative_sign_; - } - - virtual int do_frac_digits() const - { - return frac_digits_; - } - - virtual std::money_base::pattern do_pos_format() const - { - return pos_format_; - } - - virtual std::money_base::pattern do_neg_format() const - { - return neg_format_; - } - -private: - char thousands_sep_; - char decimal_point_; - std::string grouping_; - std::string curr_symbol_; - std::string positive_sign_; - std::string negative_sign_; - int frac_digits_; - std::money_base::pattern pos_format_,neg_format_; - -}; - -class utf8_numpunct : public std::numpunct_byname<char> { -public: - typedef std::numpunct_byname<char> base_type; - utf8_numpunct(char const *name,size_t refs = 0) : - std::numpunct_byname<char>(name,refs) - { - } - virtual char do_thousands_sep() const - { - unsigned char bs = base_type::do_thousands_sep(); - if(bs > 127) - if(bs == 0xA0) - return ' '; - else - return 0; - else - return bs; - } - virtual std::string do_grouping() const - { - unsigned char bs = base_type::do_thousands_sep(); - if(bs > 127 && bs != 0xA0) - return std::string(); - return base_type::do_grouping(); - } -}; - -template<bool Intl> -class utf8_moneypunct : public std::moneypunct_byname<char,Intl> { -public: - typedef std::moneypunct_byname<char,Intl> base_type; - utf8_moneypunct(char const *name,size_t refs = 0) : - std::moneypunct_byname<char,Intl>(name,refs) - { - } - virtual char do_thousands_sep() const - { - unsigned char bs = base_type::do_thousands_sep(); - if(bs > 127) - if(bs == 0xA0) - return ' '; - else - return 0; - else - return bs; - } - virtual std::string do_grouping() const - { - unsigned char bs = base_type::do_thousands_sep(); - if(bs > 127 && bs != 0xA0) - return std::string(); - return base_type::do_grouping(); - } -}; - - -template<typename CharType> -std::locale create_basic_parsing(std::locale const &in,std::string const &locale_name) -{ - std::locale tmp = std::locale(in,new std::numpunct_byname<CharType>(locale_name.c_str())); - tmp = std::locale(tmp,new std::moneypunct_byname<CharType,true>(locale_name.c_str())); - tmp = std::locale(tmp,new std::moneypunct_byname<CharType,false>(locale_name.c_str())); - tmp = std::locale(tmp,new std::ctype_byname<CharType>(locale_name.c_str())); - return tmp; -} - -template<typename CharType> -std::locale create_basic_formatting(std::locale const &in,std::string const &locale_name) -{ - std::locale tmp = create_basic_parsing<CharType>(in,locale_name); - std::locale base(locale_name.c_str()); - tmp = std::locale(tmp,new time_put_from_base<CharType>(base)); - return tmp; -} - - -std::locale create_formatting( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf) -{ - switch(type) { - case char_facet: - { - if(utf == utf8_from_wide ) { - std::locale base = std::locale(locale_name.c_str()); - - std::locale tmp = std::locale(in,new utf8_time_put_from_wide(base)); - tmp = std::locale(tmp,new utf8_numpunct_from_wide(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); - return std::locale(tmp,new util::base_num_format<char>()); - } - else if(utf == utf8_native) { - std::locale base = std::locale(locale_name.c_str()); - - std::locale tmp = std::locale(in,new time_put_from_base<char>(base)); - tmp = std::locale(tmp,new utf8_numpunct(locale_name.c_str())); - tmp = std::locale(tmp,new utf8_moneypunct<true>(locale_name.c_str())); - tmp = std::locale(tmp,new utf8_moneypunct<false>(locale_name.c_str())); - return std::locale(tmp,new util::base_num_format<char>()); - } - else if(utf == utf8_native_with_wide) { - std::locale base = std::locale(locale_name.c_str()); - - std::locale tmp = std::locale(in,new time_put_from_base<char>(base)); - tmp = std::locale(tmp,new utf8_numpunct_from_wide(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); - return std::locale(tmp,new util::base_num_format<char>()); - } - else - { - std::locale tmp = create_basic_formatting<char>(in,locale_name); - tmp = std::locale(tmp,new util::base_num_format<char>()); - return tmp; - } - } - case wchar_t_facet: - { - std::locale tmp = create_basic_formatting<wchar_t>(in,locale_name); - tmp = std::locale(tmp,new util::base_num_format<wchar_t>()); - return tmp; - } - #ifdef BOOST_LOCALE_ENABLE_CHAR16_T - case char16_t_facet: - { - std::locale tmp = create_basic_formatting<char16_t>(in,locale_name); - tmp = std::locale(tmp,new util::base_num_format<char16_t>()); - return tmp; - } - #endif - #ifdef BOOST_LOCALE_ENABLE_CHAR32_T - case char32_t_facet: - { - std::locale tmp = create_basic_formatting<char32_t>(in,locale_name); - tmp = std::locale(tmp,new util::base_num_format<char32_t>()); - return tmp; - } - #endif - default: - return in; - } -} - -std::locale create_parsing( std::locale const &in, - std::string const &locale_name, - character_facet_type type, - utf8_support utf) -{ - switch(type) { +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#define BOOST_LOCALE_SOURCE +#include <locale> +#include <string> +#include <ios> +#include <boost/locale/formatting.hpp> +#include <boost/locale/generator.hpp> +#include <boost/locale/encoding.hpp> +#include <sstream> +#include <stdlib.h> + +#include "../util/numeric.hpp" +#include "all_generator.hpp" + +namespace boost { +namespace locale { +namespace impl_std { + +template<typename CharType> +class time_put_from_base : public std::time_put<CharType> { +public: + time_put_from_base(std::locale const &base, size_t refs = 0) : + std::time_put<CharType>(refs), + base_(base) + { + } + typedef typename std::time_put<CharType>::iter_type iter_type; + + virtual iter_type do_put(iter_type out,std::ios_base &/*ios*/,CharType fill,std::tm const *tm,char format,char modifier) const + { + std::basic_stringstream<CharType> ss; + ss.imbue(base_); + return std::use_facet<std::time_put<CharType> >(base_).put(out,ss,fill,tm,format,modifier); + } +private: + std::locale base_; +}; + +class utf8_time_put_from_wide : public std::time_put<char> { +public: + utf8_time_put_from_wide(std::locale const &base, size_t refs = 0) : + std::time_put<char>(refs), + base_(base) + { + } + virtual iter_type do_put(iter_type out,std::ios_base &/*ios*/,char fill,std::tm const *tm,char format,char modifier = 0) const + { + std::basic_ostringstream<wchar_t> wtmps; + wtmps.imbue(base_); + std::use_facet<std::time_put<wchar_t> >(base_).put(wtmps,wtmps,wchar_t(fill),tm,wchar_t(format),wchar_t(modifier)); + std::wstring wtmp=wtmps.str(); + std::string const tmp = conv::from_utf<wchar_t>(wtmp,"UTF-8"); + for(unsigned i=0;i<tmp.size();i++) { + *out++ = tmp[i]; + } + return out; + } +private: + std::locale base_; +}; + +class utf8_numpunct_from_wide : public std::numpunct<char> { +public: + utf8_numpunct_from_wide(std::locale const &base,size_t refs = 0) : std::numpunct<char>(refs) + { + typedef std::numpunct<wchar_t> wfacet_type; + wfacet_type const &wfacet = std::use_facet<wfacet_type>(base); + + truename_ = conv::from_utf<wchar_t>(wfacet.truename(),"UTF-8"); + falsename_ = conv::from_utf<wchar_t>(wfacet.falsename(),"UTF-8"); + + wchar_t tmp_decimal_point = wfacet.decimal_point(); + wchar_t tmp_thousands_sep = wfacet.thousands_sep(); + std::string tmp_grouping = wfacet.grouping(); + + if( 32 <= tmp_thousands_sep && tmp_thousands_sep <=126 && + 32 <= tmp_decimal_point && tmp_decimal_point <=126) + { + thousands_sep_ = static_cast<char>(tmp_thousands_sep); + decimal_point_ = static_cast<char>(tmp_decimal_point); + grouping_ = tmp_grouping; + } + else if(32 <= tmp_decimal_point && tmp_decimal_point <=126 && tmp_thousands_sep == 0xA0) { + // workaround common bug - substitute NBSP with ordinary space + thousands_sep_ = ' '; + decimal_point_ = static_cast<char>(tmp_decimal_point); + grouping_ = tmp_grouping; + } + else if(32 <= tmp_decimal_point && tmp_decimal_point <=126) + { + thousands_sep_=','; + decimal_point_ = static_cast<char>(tmp_decimal_point); + grouping_=std::string(); + } + else { + thousands_sep_ = ','; + decimal_point_ = '.'; + grouping_=std::string(); + } + } + + virtual char do_decimal_point() const + { + return decimal_point_; + } + virtual char do_thousands_sep() const + { + return thousands_sep_; + } + virtual std::string do_grouping() const + { + return grouping_; + } + virtual std::string do_truename() const + { + return truename_; + } + virtual std::string do_falsename() const + { + return falsename_; + } +private: + std::string truename_; + std::string falsename_; + char thousands_sep_; + char decimal_point_; + std::string grouping_; + +}; + +template<bool Intl> +class utf8_moneypunct_from_wide : public std::moneypunct<char,Intl> { +public: + utf8_moneypunct_from_wide(std::locale const &base,size_t refs = 0) : std::moneypunct<char,Intl>(refs) + { + typedef std::moneypunct<wchar_t,Intl> wfacet_type; + wfacet_type const &wfacet = std::use_facet<wfacet_type>(base); + + curr_symbol_ = conv::from_utf<wchar_t>(wfacet.curr_symbol(),"UTF-8"); + positive_sign_ = conv::from_utf<wchar_t>(wfacet.positive_sign(),"UTF-8"); + negative_sign_ = conv::from_utf<wchar_t>(wfacet.negative_sign(),"UTF-8"); + frac_digits_ = wfacet.frac_digits(); + pos_format_ = wfacet.pos_format(); + neg_format_ = wfacet.neg_format(); + + wchar_t tmp_decimal_point = wfacet.decimal_point(); + wchar_t tmp_thousands_sep = wfacet.thousands_sep(); + std::string tmp_grouping = wfacet.grouping(); + if( 32 <= tmp_thousands_sep && tmp_thousands_sep <=126 && + 32 <= tmp_decimal_point && tmp_decimal_point <=126) + { + thousands_sep_ = static_cast<char>(tmp_thousands_sep); + decimal_point_ = static_cast<char>(tmp_decimal_point); + grouping_ = tmp_grouping; + } + else if(32 <= tmp_decimal_point && tmp_decimal_point <=126 && tmp_thousands_sep == 0xA0) { + // workaround common bug - substitute NBSP with ordinary space + thousands_sep_ = ' '; + decimal_point_ = static_cast<char>(tmp_decimal_point); + grouping_ = tmp_grouping; + } + else if(32 <= tmp_decimal_point && tmp_decimal_point <=126) + { + thousands_sep_=','; + decimal_point_ = static_cast<char>(tmp_decimal_point); + grouping_=std::string(); + } + else { + thousands_sep_ = ','; + decimal_point_ = '.'; + grouping_=std::string(); + } + } + + virtual char do_decimal_point() const + { + return decimal_point_; + } + + virtual char do_thousands_sep() const + { + return thousands_sep_; + } + + virtual std::string do_grouping() const + { + return grouping_; + } + + virtual std::string do_curr_symbol() const + { + return curr_symbol_; + } + virtual std::string do_positive_sign () const + { + return positive_sign_; + } + virtual std::string do_negative_sign() const + { + return negative_sign_; + } + + virtual int do_frac_digits() const + { + return frac_digits_; + } + + virtual std::money_base::pattern do_pos_format() const + { + return pos_format_; + } + + virtual std::money_base::pattern do_neg_format() const + { + return neg_format_; + } + +private: + char thousands_sep_; + char decimal_point_; + std::string grouping_; + std::string curr_symbol_; + std::string positive_sign_; + std::string negative_sign_; + int frac_digits_; + std::money_base::pattern pos_format_,neg_format_; + +}; + +class utf8_numpunct : public std::numpunct_byname<char> { +public: + typedef std::numpunct_byname<char> base_type; + utf8_numpunct(char const *name,size_t refs = 0) : + std::numpunct_byname<char>(name,refs) + { + } + virtual char do_thousands_sep() const + { + unsigned char bs = base_type::do_thousands_sep(); + if(bs > 127) + if(bs == 0xA0) + return ' '; + else + return 0; + else + return bs; + } + virtual std::string do_grouping() const + { + unsigned char bs = base_type::do_thousands_sep(); + if(bs > 127 && bs != 0xA0) + return std::string(); + return base_type::do_grouping(); + } +}; + +template<bool Intl> +class utf8_moneypunct : public std::moneypunct_byname<char,Intl> { +public: + typedef std::moneypunct_byname<char,Intl> base_type; + utf8_moneypunct(char const *name,size_t refs = 0) : + std::moneypunct_byname<char,Intl>(name,refs) + { + } + virtual char do_thousands_sep() const + { + unsigned char bs = base_type::do_thousands_sep(); + if(bs > 127) + if(bs == 0xA0) + return ' '; + else + return 0; + else + return bs; + } + virtual std::string do_grouping() const + { + unsigned char bs = base_type::do_thousands_sep(); + if(bs > 127 && bs != 0xA0) + return std::string(); + return base_type::do_grouping(); + } +}; + + +template<typename CharType> +std::locale create_basic_parsing(std::locale const &in,std::string const &locale_name) +{ + std::locale tmp = std::locale(in,new std::numpunct_byname<CharType>(locale_name.c_str())); + tmp = std::locale(tmp,new std::moneypunct_byname<CharType,true>(locale_name.c_str())); + tmp = std::locale(tmp,new std::moneypunct_byname<CharType,false>(locale_name.c_str())); + tmp = std::locale(tmp,new std::ctype_byname<CharType>(locale_name.c_str())); + return tmp; +} + +template<typename CharType> +std::locale create_basic_formatting(std::locale const &in,std::string const &locale_name) +{ + std::locale tmp = create_basic_parsing<CharType>(in,locale_name); + std::locale base(locale_name.c_str()); + tmp = std::locale(tmp,new time_put_from_base<CharType>(base)); + return tmp; +} + + +std::locale create_formatting( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf) +{ + switch(type) { case char_facet: - { - if(utf == utf8_from_wide ) { - std::locale base = std::locale::classic(); - - base = std::locale(base,new std::numpunct_byname<wchar_t>(locale_name.c_str())); - base = std::locale(base,new std::moneypunct_byname<wchar_t,true>(locale_name.c_str())); - base = std::locale(base,new std::moneypunct_byname<wchar_t,false>(locale_name.c_str())); - - std::locale tmp = std::locale(in,new utf8_numpunct_from_wide(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); - return std::locale(tmp,new util::base_num_parse<char>()); - } - else if(utf == utf8_native) { - std::locale tmp = std::locale(in,new utf8_numpunct(locale_name.c_str())); - tmp = std::locale(tmp,new utf8_moneypunct<true>(locale_name.c_str())); - tmp = std::locale(tmp,new utf8_moneypunct<false>(locale_name.c_str())); - return std::locale(tmp,new util::base_num_parse<char>()); - } - else if(utf == utf8_native_with_wide) { - std::locale base = std::locale(locale_name.c_str()); - - std::locale tmp = std::locale(in,new utf8_numpunct_from_wide(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); - tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); - return std::locale(tmp,new util::base_num_parse<char>()); - } - else - { - std::locale tmp = create_basic_parsing<char>(in,locale_name); - tmp = std::locale(in,new util::base_num_parse<char>()); - return tmp; - } - } - case wchar_t_facet: - { - std::locale tmp = create_basic_parsing<wchar_t>(in,locale_name); - tmp = std::locale(in,new util::base_num_parse<wchar_t>()); - return tmp; - } - #ifdef BOOST_LOCALE_ENABLE_CHAR16_T - case char16_t_facet: - { - std::locale tmp = create_basic_parsing<char16_t>(in,locale_name); - tmp = std::locale(in,new util::base_num_parse<char16_t>()); - return tmp; - } - #endif - #ifdef BOOST_LOCALE_ENABLE_CHAR32_T - case char32_t_facet: - { - std::locale tmp = create_basic_parsing<char32_t>(in,locale_name); - tmp = std::locale(in,new util::base_num_parse<char32_t>()); - return tmp; - } - #endif - default: - return in; - } -} - - -} // impl_std -} // locale -} //boost - - - -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 + { + if(utf == utf8_from_wide ) { + std::locale base = std::locale(locale_name.c_str()); + + std::locale tmp = std::locale(in,new utf8_time_put_from_wide(base)); + tmp = std::locale(tmp,new utf8_numpunct_from_wide(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); + return std::locale(tmp,new util::base_num_format<char>()); + } + else if(utf == utf8_native) { + std::locale base = std::locale(locale_name.c_str()); + + std::locale tmp = std::locale(in,new time_put_from_base<char>(base)); + tmp = std::locale(tmp,new utf8_numpunct(locale_name.c_str())); + tmp = std::locale(tmp,new utf8_moneypunct<true>(locale_name.c_str())); + tmp = std::locale(tmp,new utf8_moneypunct<false>(locale_name.c_str())); + return std::locale(tmp,new util::base_num_format<char>()); + } + else if(utf == utf8_native_with_wide) { + std::locale base = std::locale(locale_name.c_str()); + + std::locale tmp = std::locale(in,new time_put_from_base<char>(base)); + tmp = std::locale(tmp,new utf8_numpunct_from_wide(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); + return std::locale(tmp,new util::base_num_format<char>()); + } + else + { + std::locale tmp = create_basic_formatting<char>(in,locale_name); + tmp = std::locale(tmp,new util::base_num_format<char>()); + return tmp; + } + } + case wchar_t_facet: + { + std::locale tmp = create_basic_formatting<wchar_t>(in,locale_name); + tmp = std::locale(tmp,new util::base_num_format<wchar_t>()); + return tmp; + } + #ifdef BOOST_LOCALE_ENABLE_CHAR16_T + case char16_t_facet: + { + std::locale tmp = create_basic_formatting<char16_t>(in,locale_name); + tmp = std::locale(tmp,new util::base_num_format<char16_t>()); + return tmp; + } + #endif + #ifdef BOOST_LOCALE_ENABLE_CHAR32_T + case char32_t_facet: + { + std::locale tmp = create_basic_formatting<char32_t>(in,locale_name); + tmp = std::locale(tmp,new util::base_num_format<char32_t>()); + return tmp; + } + #endif + default: + return in; + } +} + +std::locale create_parsing( std::locale const &in, + std::string const &locale_name, + character_facet_type type, + utf8_support utf) +{ + switch(type) { + case char_facet: + { + if(utf == utf8_from_wide ) { + std::locale base = std::locale::classic(); + + base = std::locale(base,new std::numpunct_byname<wchar_t>(locale_name.c_str())); + base = std::locale(base,new std::moneypunct_byname<wchar_t,true>(locale_name.c_str())); + base = std::locale(base,new std::moneypunct_byname<wchar_t,false>(locale_name.c_str())); + + std::locale tmp = std::locale(in,new utf8_numpunct_from_wide(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); + return std::locale(tmp,new util::base_num_parse<char>()); + } + else if(utf == utf8_native) { + std::locale tmp = std::locale(in,new utf8_numpunct(locale_name.c_str())); + tmp = std::locale(tmp,new utf8_moneypunct<true>(locale_name.c_str())); + tmp = std::locale(tmp,new utf8_moneypunct<false>(locale_name.c_str())); + return std::locale(tmp,new util::base_num_parse<char>()); + } + else if(utf == utf8_native_with_wide) { + std::locale base = std::locale(locale_name.c_str()); + + std::locale tmp = std::locale(in,new utf8_numpunct_from_wide(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<true>(base)); + tmp = std::locale(tmp,new utf8_moneypunct_from_wide<false>(base)); + return std::locale(tmp,new util::base_num_parse<char>()); + } + else + { + std::locale tmp = create_basic_parsing<char>(in,locale_name); + tmp = std::locale(in,new util::base_num_parse<char>()); + return tmp; + } + } + case wchar_t_facet: + { + std::locale tmp = create_basic_parsing<wchar_t>(in,locale_name); + tmp = std::locale(in,new util::base_num_parse<wchar_t>()); + return tmp; + } + #ifdef BOOST_LOCALE_ENABLE_CHAR16_T + case char16_t_facet: + { + std::locale tmp = create_basic_parsing<char16_t>(in,locale_name); + tmp = std::locale(in,new util::base_num_parse<char16_t>()); + return tmp; + } + #endif + #ifdef BOOST_LOCALE_ENABLE_CHAR32_T + case char32_t_facet: + { + std::locale tmp = create_basic_parsing<char32_t>(in,locale_name); + tmp = std::locale(in,new util::base_num_parse<char32_t>()); + return tmp; + } + #endif + default: + return in; + } +} + + +} // impl_std +} // locale +} //boost + + + +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/contrib/restricted/boost/libs/locale/src/std/std_backend.cpp b/contrib/restricted/boost/libs/locale/src/std/std_backend.cpp index 66672e86f3..f9afcb417e 100644 --- a/contrib/restricted/boost/libs/locale/src/std/std_backend.cpp +++ b/contrib/restricted/boost/libs/locale/src/std/std_backend.cpp @@ -1,234 +1,234 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#define BOOST_LOCALE_SOURCE -#include <boost/locale/localization_backend.hpp> -#include <boost/locale/gnu_gettext.hpp> -#include "all_generator.hpp" -#include "../util/locale_data.hpp" -#include "../util/gregorian.hpp" -#include <boost/locale/util.hpp> -#include <algorithm> -#include <iterator> - -#if defined(BOOST_WINDOWS) -# ifndef NOMINMAX -# define NOMINMAX -# endif -# include <windows.h> -# include "../encoding/conv.hpp" -# include "../win32/lcid.hpp" -#endif - -#include "std_backend.hpp" - -namespace boost { -namespace locale { -namespace impl_std { - - class std_localization_backend : public localization_backend { - public: - std_localization_backend() : - invalid_(true), - use_ansi_encoding_(false) - { - } - std_localization_backend(std_localization_backend const &other) : - localization_backend(), - paths_(other.paths_), - domains_(other.domains_), - locale_id_(other.locale_id_), - invalid_(true), - use_ansi_encoding_(other.use_ansi_encoding_) - { - } - virtual std_localization_backend *clone() const - { - return new std_localization_backend(*this); - } - - void set_option(std::string const &name,std::string const &value) - { - invalid_ = true; - if(name=="locale") - locale_id_ = value; - else if(name=="message_path") - paths_.push_back(value); - else if(name=="message_application") - domains_.push_back(value); - else if(name=="use_ansi_encoding") - use_ansi_encoding_ = value == "true"; - - } - void clear_options() - { - invalid_ = true; - use_ansi_encoding_ = false; - locale_id_.clear(); - paths_.clear(); - domains_.clear(); - } - - void prepare_data() - { - if(!invalid_) - return; - invalid_ = false; - std::string lid=locale_id_; - if(lid.empty()) { - bool use_utf8 = ! use_ansi_encoding_; - lid = util::get_system_locale(use_utf8); - } - in_use_id_ = lid; - data_.parse(lid); - name_ = "C"; - utf_mode_ = utf8_none; - - #if defined(BOOST_WINDOWS) - std::pair<std::string,int> wl_inf = to_windows_name(lid); - std::string win_name = wl_inf.first; - int win_codepage = wl_inf.second; - #endif - - if(!data_.utf8) { - if(loadable(lid)) { - name_ = lid; - utf_mode_ = utf8_none; - } - #if defined(BOOST_WINDOWS) - else if(loadable(win_name) - && win_codepage == conv::impl::encoding_to_windows_codepage(data_.encoding.c_str())) - { - name_ = win_name; - utf_mode_ = utf8_none; - } - #endif - } - else { - if(loadable(lid)) { - name_ = lid; - utf_mode_ = utf8_native_with_wide; - } - #if defined(BOOST_WINDOWS) - else if(loadable(win_name)) { - name_ = win_name; - utf_mode_ = utf8_from_wide; - } - #endif - } - } - - #if defined(BOOST_WINDOWS) - std::pair<std::string,int> to_windows_name(std::string const &l) - { - std::pair<std::string,int> res("C",0); - unsigned lcid = impl_win::locale_to_lcid(l); - char win_lang[256] = {0}; - char win_country[256] = {0}; - char win_codepage[10] = {0}; - if(GetLocaleInfoA(lcid,LOCALE_SENGLANGUAGE,win_lang,sizeof(win_lang))==0) - return res; - std::string lc_name = win_lang; - if(GetLocaleInfoA(lcid,LOCALE_SENGCOUNTRY,win_country,sizeof(win_country))!=0) { - lc_name += "_"; - lc_name += win_country; - } - - res.first = lc_name; - - if(GetLocaleInfoA(lcid,LOCALE_IDEFAULTANSICODEPAGE,win_codepage,sizeof(win_codepage))!=0) - res.second = atoi(win_codepage); - return res; - } - #endif - - bool loadable(std::string name) - { - try { - std::locale l(name.c_str()); - return true; - } - catch(std::exception const &/*e*/) { - return false; - } - } - - virtual std::locale install(std::locale const &base, - locale_category_type category, - character_facet_type type = nochar_facet) - { - prepare_data(); - - switch(category) { - case convert_facet: - return create_convert(base,name_,type,utf_mode_); - case collation_facet: - return create_collate(base,name_,type,utf_mode_); - case formatting_facet: - return create_formatting(base,name_,type,utf_mode_); - case parsing_facet: - return create_parsing(base,name_,type,utf_mode_); - case codepage_facet: - return create_codecvt(base,name_,type,utf_mode_); - case calendar_facet: - return util::install_gregorian_calendar(base,data_.country); - case message_facet: - { - gnu_gettext::messages_info minf; - 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)); - minf.paths = paths_; - switch(type) { - case char_facet: - return std::locale(base,gnu_gettext::create_messages_facet<char>(minf)); - case wchar_t_facet: - return std::locale(base,gnu_gettext::create_messages_facet<wchar_t>(minf)); - #ifdef BOOST_LOCALE_ENABLE_CHAR16_T - case char16_t_facet: - return std::locale(base,gnu_gettext::create_messages_facet<char16_t>(minf)); - #endif - #ifdef BOOST_LOCALE_ENABLE_CHAR32_T - case char32_t_facet: - return std::locale(base,gnu_gettext::create_messages_facet<char32_t>(minf)); - #endif - default: - return base; - } - } - case information_facet: - return util::create_info(base,in_use_id_); - default: - return base; - } - } - - private: - - std::vector<std::string> paths_; - std::vector<std::string> domains_; - std::string locale_id_; - - util::locale_data data_; - std::string name_; - std::string in_use_id_; - utf8_support utf_mode_; - bool invalid_; - bool use_ansi_encoding_; - }; - - localization_backend *create_localization_backend() - { - return new std_localization_backend(); - } - -} // impl icu -} // locale -} // boost -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#define BOOST_LOCALE_SOURCE +#include <boost/locale/localization_backend.hpp> +#include <boost/locale/gnu_gettext.hpp> +#include "all_generator.hpp" +#include "../util/locale_data.hpp" +#include "../util/gregorian.hpp" +#include <boost/locale/util.hpp> +#include <algorithm> +#include <iterator> + +#if defined(BOOST_WINDOWS) +# ifndef NOMINMAX +# define NOMINMAX +# endif +# include <windows.h> +# include "../encoding/conv.hpp" +# include "../win32/lcid.hpp" +#endif + +#include "std_backend.hpp" + +namespace boost { +namespace locale { +namespace impl_std { + + class std_localization_backend : public localization_backend { + public: + std_localization_backend() : + invalid_(true), + use_ansi_encoding_(false) + { + } + std_localization_backend(std_localization_backend const &other) : + localization_backend(), + paths_(other.paths_), + domains_(other.domains_), + locale_id_(other.locale_id_), + invalid_(true), + use_ansi_encoding_(other.use_ansi_encoding_) + { + } + virtual std_localization_backend *clone() const + { + return new std_localization_backend(*this); + } + + void set_option(std::string const &name,std::string const &value) + { + invalid_ = true; + if(name=="locale") + locale_id_ = value; + else if(name=="message_path") + paths_.push_back(value); + else if(name=="message_application") + domains_.push_back(value); + else if(name=="use_ansi_encoding") + use_ansi_encoding_ = value == "true"; + + } + void clear_options() + { + invalid_ = true; + use_ansi_encoding_ = false; + locale_id_.clear(); + paths_.clear(); + domains_.clear(); + } + + void prepare_data() + { + if(!invalid_) + return; + invalid_ = false; + std::string lid=locale_id_; + if(lid.empty()) { + bool use_utf8 = ! use_ansi_encoding_; + lid = util::get_system_locale(use_utf8); + } + in_use_id_ = lid; + data_.parse(lid); + name_ = "C"; + utf_mode_ = utf8_none; + + #if defined(BOOST_WINDOWS) + std::pair<std::string,int> wl_inf = to_windows_name(lid); + std::string win_name = wl_inf.first; + int win_codepage = wl_inf.second; + #endif + + if(!data_.utf8) { + if(loadable(lid)) { + name_ = lid; + utf_mode_ = utf8_none; + } + #if defined(BOOST_WINDOWS) + else if(loadable(win_name) + && win_codepage == conv::impl::encoding_to_windows_codepage(data_.encoding.c_str())) + { + name_ = win_name; + utf_mode_ = utf8_none; + } + #endif + } + else { + if(loadable(lid)) { + name_ = lid; + utf_mode_ = utf8_native_with_wide; + } + #if defined(BOOST_WINDOWS) + else if(loadable(win_name)) { + name_ = win_name; + utf_mode_ = utf8_from_wide; + } + #endif + } + } + + #if defined(BOOST_WINDOWS) + std::pair<std::string,int> to_windows_name(std::string const &l) + { + std::pair<std::string,int> res("C",0); + unsigned lcid = impl_win::locale_to_lcid(l); + char win_lang[256] = {0}; + char win_country[256] = {0}; + char win_codepage[10] = {0}; + if(GetLocaleInfoA(lcid,LOCALE_SENGLANGUAGE,win_lang,sizeof(win_lang))==0) + return res; + std::string lc_name = win_lang; + if(GetLocaleInfoA(lcid,LOCALE_SENGCOUNTRY,win_country,sizeof(win_country))!=0) { + lc_name += "_"; + lc_name += win_country; + } + + res.first = lc_name; + + if(GetLocaleInfoA(lcid,LOCALE_IDEFAULTANSICODEPAGE,win_codepage,sizeof(win_codepage))!=0) + res.second = atoi(win_codepage); + return res; + } + #endif + + bool loadable(std::string name) + { + try { + std::locale l(name.c_str()); + return true; + } + catch(std::exception const &/*e*/) { + return false; + } + } + + virtual std::locale install(std::locale const &base, + locale_category_type category, + character_facet_type type = nochar_facet) + { + prepare_data(); + + switch(category) { + case convert_facet: + return create_convert(base,name_,type,utf_mode_); + case collation_facet: + return create_collate(base,name_,type,utf_mode_); + case formatting_facet: + return create_formatting(base,name_,type,utf_mode_); + case parsing_facet: + return create_parsing(base,name_,type,utf_mode_); + case codepage_facet: + return create_codecvt(base,name_,type,utf_mode_); + case calendar_facet: + return util::install_gregorian_calendar(base,data_.country); + case message_facet: + { + gnu_gettext::messages_info minf; + 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)); + minf.paths = paths_; + switch(type) { + case char_facet: + return std::locale(base,gnu_gettext::create_messages_facet<char>(minf)); + case wchar_t_facet: + return std::locale(base,gnu_gettext::create_messages_facet<wchar_t>(minf)); + #ifdef BOOST_LOCALE_ENABLE_CHAR16_T + case char16_t_facet: + return std::locale(base,gnu_gettext::create_messages_facet<char16_t>(minf)); + #endif + #ifdef BOOST_LOCALE_ENABLE_CHAR32_T + case char32_t_facet: + return std::locale(base,gnu_gettext::create_messages_facet<char32_t>(minf)); + #endif + default: + return base; + } + } + case information_facet: + return util::create_info(base,in_use_id_); + default: + return base; + } + } + + private: + + std::vector<std::string> paths_; + std::vector<std::string> domains_; + std::string locale_id_; + + util::locale_data data_; + std::string name_; + std::string in_use_id_; + utf8_support utf_mode_; + bool invalid_; + bool use_ansi_encoding_; + }; + + localization_backend *create_localization_backend() + { + return new std_localization_backend(); + } + +} // impl icu +} // locale +} // boost +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/contrib/restricted/boost/libs/locale/src/std/std_backend.hpp b/contrib/restricted/boost/libs/locale/src/std/std_backend.hpp index 6b0c7bb4d2..0caf779c67 100644 --- a/contrib/restricted/boost/libs/locale/src/std/std_backend.hpp +++ b/contrib/restricted/boost/libs/locale/src/std/std_backend.hpp @@ -1,20 +1,20 @@ -// -// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -#ifndef BOOST_LOCALE_IMPL_STD_LOCALIZATION_BACKEND_HPP -#define BOOST_LOCALE_IMPL_STD_LOCALIZATION_BACKEND_HPP -namespace boost { - namespace locale { - class localization_backend; - namespace impl_std { - localization_backend *create_localization_backend(); - } // impl_std - } // locale -} // boost -#endif -// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 - +// +// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#ifndef BOOST_LOCALE_IMPL_STD_LOCALIZATION_BACKEND_HPP +#define BOOST_LOCALE_IMPL_STD_LOCALIZATION_BACKEND_HPP +namespace boost { + namespace locale { + class localization_backend; + namespace impl_std { + localization_backend *create_localization_backend(); + } // impl_std + } // locale +} // boost +#endif +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 + |