aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/libs/locale/src/win32
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2022-09-21 20:17:38 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2022-09-21 20:17:38 +0300
commite6c9b17192c56494adba359d5e132c431b241191 (patch)
tree6f2449871a118a0e8919ce842b1174e06cb470ef /contrib/restricted/boost/libs/locale/src/win32
parent285021ab1aac39e84b269d9bacd4deee69cf63fc (diff)
downloadydb-e6c9b17192c56494adba359d5e132c431b241191.tar.gz
Ydb stable 22-4-2122.4.21
x-stable-origin-commit: e89099581237299a132feafb5b58af59ebd0468a
Diffstat (limited to 'contrib/restricted/boost/libs/locale/src/win32')
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/all_generator.hpp45
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/api.hpp357
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/collate.cpp127
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/converter.cpp106
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/lcid.cpp127
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/numeric.cpp245
-rw-r--r--contrib/restricted/boost/libs/locale/src/win32/win_backend.cpp153
7 files changed, 1160 insertions, 0 deletions
diff --git a/contrib/restricted/boost/libs/locale/src/win32/all_generator.hpp b/contrib/restricted/boost/libs/locale/src/win32/all_generator.hpp
new file mode 100644
index 0000000000..083d056272
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/all_generator.hpp
@@ -0,0 +1,45 @@
+//
+// 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_WIN32_ALL_GENERATOR_HPP
+#define BOOST_LOCALE_IMPL_WIN32_ALL_GENERATOR_HPP
+
+#include <boost/locale/generator.hpp>
+#include <vector>
+#include <locale.h>
+
+namespace boost {
+ namespace locale {
+ namespace impl_win {
+
+ class winlocale;
+
+ std::locale create_convert( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type);
+
+ std::locale create_collate( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type);
+
+ std::locale create_formatting( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type);
+
+ std::locale create_parsing( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type);
+
+ std::locale create_codecvt( std::locale const &in,
+ character_facet_type type);
+
+ }
+ }
+}
+
+#endif
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/contrib/restricted/boost/libs/locale/src/win32/api.hpp b/contrib/restricted/boost/libs/locale/src/win32/api.hpp
new file mode 100644
index 0000000000..a41fbde5e6
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/api.hpp
@@ -0,0 +1,357 @@
+//
+// 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_WIN32_API_HPP
+#define BOOST_LOCALE_IMPL_WIN32_API_HPP
+
+#include <string>
+#include <vector>
+#include <sstream>
+#include <iomanip>
+#include <limits>
+#include <ctime>
+
+#include "lcid.hpp"
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#ifndef UNICODE
+#define UNICODE
+#endif
+#include <windows.h>
+
+#include <boost/locale/conversion.hpp>
+#include <boost/locale/collator.hpp>
+
+#define BOOST_LOCALE_WINDOWS_2000_API
+
+#if defined(_WIN32_NT) && _WIN32_NT >= 0x600 && !defined(BOOST_LOCALE_WINDOWS_2000_API)
+#define BOOST_LOCALE_WINDOWS_VISTA_API
+#else
+#define BOOST_LOCALE_WINDOWS_2000_API
+#endif
+
+namespace boost {
+namespace locale {
+namespace impl_win {
+
+ struct numeric_info {
+ std::wstring thousands_sep;
+ std::wstring decimal_point;
+ std::string grouping;
+ };
+
+ inline DWORD collation_level_to_flag(collator_base::level_type level)
+ {
+ DWORD flags;
+ switch(level) {
+ case collator_base::primary:
+ flags = NORM_IGNORESYMBOLS | NORM_IGNORECASE | NORM_IGNORENONSPACE;
+ break;
+ case collator_base::secondary:
+ flags = NORM_IGNORESYMBOLS | NORM_IGNORECASE;
+ break;
+ case collator_base::tertiary:
+ flags = NORM_IGNORESYMBOLS;
+ break;
+ default:
+ flags = 0;
+ }
+ return flags;
+ }
+
+
+
+ #ifdef BOOST_LOCALE_WINDOWS_2000_API
+
+ class winlocale{
+ public:
+ winlocale() :
+ lcid(0)
+ {
+ }
+
+ winlocale(std::string const &name)
+ {
+ lcid = locale_to_lcid(name);
+ }
+
+ unsigned lcid;
+
+ bool is_c() const
+ {
+ return lcid == 0;
+ }
+ };
+
+
+ ////////////////////////////////////////////////////////////////////////
+ ///
+ /// Number Format
+ ///
+ ////////////////////////////////////////////////////////////////////////
+
+ inline numeric_info wcsnumformat_l(winlocale const &l)
+ {
+ numeric_info res;
+ res.decimal_point = L'.';
+ unsigned lcid = l.lcid;
+
+ if(lcid == 0)
+ return res;
+
+ // limits according to MSDN
+ static const int th_size = 4;
+ static const int de_size = 4;
+ static const int gr_size = 10;
+
+ wchar_t th[th_size]={0};
+ wchar_t de[de_size]={0};
+ wchar_t gr[gr_size]={0};
+
+ if( GetLocaleInfoW(lcid,LOCALE_STHOUSAND,th,th_size)==0
+ || GetLocaleInfoW(lcid,LOCALE_SDECIMAL ,de,de_size)==0
+ || GetLocaleInfoW(lcid,LOCALE_SGROUPING,gr,gr_size)==0)
+ {
+ return res;
+ }
+ res.decimal_point = de;
+ res.thousands_sep = th;
+ bool inf_group = false;
+ for(unsigned i=0;gr[i];i++) {
+ if(gr[i]==L';')
+ continue;
+ if(L'1'<= gr[i] && gr[i]<=L'9') {
+ res.grouping += char(gr[i]-L'0');
+ }
+ else if(gr[i]==L'0')
+ inf_group = true;
+ }
+ if(!inf_group) {
+ if(std::numeric_limits<char>::is_signed) {
+ res.grouping+=std::numeric_limits<char>::min();
+ }
+ else {
+ res.grouping+=std::numeric_limits<char>::max();
+ }
+ }
+ return res;
+ }
+
+ inline std::wstring win_map_string_l(unsigned flags,wchar_t const *begin,wchar_t const *end,winlocale const &l)
+ {
+ std::wstring res;
+ int len = LCMapStringW(l.lcid,flags,begin,end-begin,0,0);
+ if(len == 0)
+ return res;
+ std::vector<wchar_t> buf(len+1);
+ int l2 = LCMapStringW(l.lcid,flags,begin,end-begin,&buf.front(),buf.size());
+ res.assign(&buf.front(),l2);
+ return res;
+ }
+
+ ////////////////////////////////////////////////////////////////////////
+ ///
+ /// Collation
+ ///
+ ////////////////////////////////////////////////////////////////////////
+
+
+ inline int wcscoll_l( collator_base::level_type level,
+ wchar_t const *lb,wchar_t const *le,
+ wchar_t const *rb,wchar_t const *re,
+ winlocale const &l)
+ {
+ return CompareStringW(l.lcid,collation_level_to_flag(level),lb,le-lb,rb,re-rb) - 2;
+ }
+
+
+ ////////////////////////////////////////////////////////////////////////
+ ///
+ /// Money Format
+ ///
+ ////////////////////////////////////////////////////////////////////////
+
+ inline std::wstring wcsfmon_l(double value,winlocale const &l)
+ {
+ std::wostringstream ss;
+ ss.imbue(std::locale::classic());
+
+ ss << std::setprecision(std::numeric_limits<double>::digits10+1) << value;
+ std::wstring sval = ss.str();
+ int len = GetCurrencyFormatW(l.lcid,0,sval.c_str(),0,0,0);
+ std::vector<wchar_t> buf(len+1);
+ GetCurrencyFormatW(l.lcid,0,sval.c_str(),0,&buf.front(),len);
+ return &buf.front();
+ }
+
+ ////////////////////////////////////////////////////////////////////////
+ ///
+ /// Time Format
+ ///
+ ////////////////////////////////////////////////////////////////////////
+
+
+ inline std::wstring wcs_format_date_l(wchar_t const *format,SYSTEMTIME const *tm,winlocale const &l)
+ {
+ int len = GetDateFormatW(l.lcid,0,tm,format,0,0);
+ std::vector<wchar_t> buf(len+1);
+ GetDateFormatW(l.lcid,0,tm,format,&buf.front(),len);
+ return &buf.front();
+ }
+
+ inline std::wstring wcs_format_time_l(wchar_t const *format,SYSTEMTIME const *tm,winlocale const &l)
+ {
+ int len = GetTimeFormatW(l.lcid,0,tm,format,0,0);
+ std::vector<wchar_t> buf(len+1);
+ GetTimeFormatW(l.lcid,0,tm,format,&buf.front(),len);
+ return &buf.front();
+ }
+
+ inline std::wstring wcsfold(wchar_t const *begin,wchar_t const *end)
+ {
+ winlocale l;
+ l.lcid = 0x0409; // en-US
+ return win_map_string_l(LCMAP_LOWERCASE,begin,end,l);
+ }
+
+ inline std::wstring wcsnormalize(norm_type norm,wchar_t const *begin,wchar_t const *end)
+ {
+ // We use FoldString, under Vista it actually does normalization;
+ // under XP and below it does something similar, half job, better then nothing
+ unsigned flags = 0;
+ switch(norm) {
+ case norm_nfd:
+ flags = MAP_COMPOSITE;
+ break;
+ case norm_nfc:
+ flags = MAP_PRECOMPOSED;
+ break;
+ case norm_nfkd:
+ flags = MAP_FOLDCZONE;
+ break;
+ case norm_nfkc:
+ flags = MAP_FOLDCZONE | MAP_COMPOSITE;
+ break;
+ default:
+ flags = MAP_PRECOMPOSED;
+ }
+
+ int len = FoldStringW(flags,begin,end-begin,0,0);
+ if(len == 0)
+ return std::wstring();
+ std::vector<wchar_t> v(len+1);
+ len = FoldStringW(flags,begin,end-begin,&v.front(),len+1);
+ return std::wstring(&v.front(),len);
+ }
+
+
+ #endif
+
+ inline std::wstring wcsxfrm_l(collator_base::level_type level,wchar_t const *begin,wchar_t const *end,winlocale const &l)
+ {
+ int flag = LCMAP_SORTKEY | collation_level_to_flag(level);
+
+ return win_map_string_l(flag,begin,end,l);
+ }
+
+ inline std::wstring towupper_l(wchar_t const *begin,wchar_t const *end,winlocale const &l)
+ {
+ return win_map_string_l(LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING,begin,end,l);
+ }
+
+ inline std::wstring towlower_l(wchar_t const *begin,wchar_t const *end,winlocale const &l)
+ {
+ return win_map_string_l(LCMAP_LOWERCASE | LCMAP_LINGUISTIC_CASING,begin,end,l);
+ }
+
+ inline std::wstring wcsftime_l(char c,std::tm const *tm,winlocale const &l)
+ {
+ SYSTEMTIME wtm=SYSTEMTIME();
+ wtm.wYear = tm->tm_year + 1900;
+ wtm.wMonth = tm->tm_mon+1;
+ wtm.wDayOfWeek = tm->tm_wday;
+ wtm.wDay = tm->tm_mday;
+ wtm.wHour = tm->tm_hour;
+ wtm.wMinute = tm->tm_min;
+ wtm.wSecond = tm->tm_sec;
+ switch(c) {
+ case 'a': // Abbr Weekday
+ return wcs_format_date_l(L"ddd",&wtm,l);
+ case 'A': // Full Weekday
+ return wcs_format_date_l(L"dddd",&wtm,l);
+ case 'b': // Abbr Month
+ return wcs_format_date_l(L"MMM",&wtm,l);
+ case 'B': // Full Month
+ return wcs_format_date_l(L"MMMM",&wtm,l);
+ case 'c': // DateTile Full
+ return wcs_format_date_l(0,&wtm,l) + L" " + wcs_format_time_l(0,&wtm,l);
+ // not supported by WIN ;(
+ // case 'C': // Century -> 1980 -> 19
+ // retur
+ case 'd': // Day of Month [01,31]
+ return wcs_format_date_l(L"dd",&wtm,l);
+ case 'D': // %m/%d/%y
+ return wcs_format_date_l(L"MM/dd/yy",&wtm,l);
+ case 'e': // Day of Month [1,31]
+ return wcs_format_date_l(L"d",&wtm,l);
+ case 'h': // == b
+ return wcs_format_date_l(L"MMM",&wtm,l);
+ case 'H': // 24 clock hour 00,23
+ return wcs_format_time_l(L"HH",&wtm,l);
+ case 'I': // 12 clock hour 01,12
+ return wcs_format_time_l(L"hh",&wtm,l);
+ /*
+ case 'j': // day of year 001,366
+ return "D";*/
+ case 'm': // month as [01,12]
+ return wcs_format_date_l(L"MM",&wtm,l);
+ case 'M': // minute [00,59]
+ return wcs_format_time_l(L"mm",&wtm,l);
+ case 'n': // \n
+ return L"\n";
+ case 'p': // am-pm
+ return wcs_format_time_l(L"tt",&wtm,l);
+ case 'r': // time with AM/PM %I:%M:%S %p
+ return wcs_format_time_l(L"hh:mm:ss tt",&wtm,l);
+ case 'R': // %H:%M
+ return wcs_format_time_l(L"HH:mm",&wtm,l);
+ case 'S': // second [00,61]
+ return wcs_format_time_l(L"ss",&wtm,l);
+ case 't': // \t
+ return L"\t";
+ case 'T': // %H:%M:%S
+ return wcs_format_time_l(L"HH:mm:ss",&wtm,l);
+/* case 'u': // weekday 1,7 1=Monday
+ case 'U': // week number of year [00,53] Sunday first
+ case 'V': // week number of year [01,53] Moday first
+ case 'w': // weekday 0,7 0=Sunday
+ case 'W': // week number of year [00,53] Moday first, */
+ case 'x': // Date
+ return wcs_format_date_l(0,&wtm,l);
+ case 'X': // Time
+ return wcs_format_time_l(0,&wtm,l);
+ case 'y': // Year [00-99]
+ return wcs_format_date_l(L"yy",&wtm,l);
+ case 'Y': // Year 1998
+ return wcs_format_date_l(L"yyyy",&wtm,l);
+ case '%': // %
+ return L"%";
+ default:
+ return L"";
+ }
+ }
+
+
+
+} // win
+} // locale
+} // boost
+#endif
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
+
diff --git a/contrib/restricted/boost/libs/locale/src/win32/collate.cpp b/contrib/restricted/boost/libs/locale/src/win32/collate.cpp
new file mode 100644
index 0000000000..40e8c3d217
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/collate.cpp
@@ -0,0 +1,127 @@
+//
+// 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 <boost/locale/generator.hpp>
+#include "api.hpp"
+#include "../shared/mo_hash.hpp"
+
+namespace boost {
+namespace locale {
+namespace impl_win {
+
+class utf8_collator : public collator<char> {
+public:
+ utf8_collator(winlocale lc,size_t refs = 0) :
+ collator<char>(refs),
+ lc_(lc)
+ {
+ }
+ virtual int do_compare(collator_base::level_type level,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 wcscoll_l(level,l.c_str(),l.c_str()+l.size(),r.c_str(),r.c_str()+r.size(),lc_);
+ }
+ virtual long do_hash(collator_base::level_type level,char const *b,char const *e) const
+ {
+ std::string key = do_transform(level,b,e);
+ return gnu_gettext::pj_winberger_hash_function(key.c_str(),key.c_str() + key.size());
+ }
+ virtual std::string do_transform(collator_base::level_type level,char const *b,char const *e) const
+ {
+ std::wstring tmp=conv::to_utf<wchar_t>(b,e,"UTF-8");
+ std::wstring wkey = wcsxfrm_l(level,tmp.c_str(),tmp.c_str()+tmp.size(),lc_);
+ 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:
+ winlocale lc_;
+};
+
+
+class utf16_collator : public collator<wchar_t> {
+public:
+ typedef std::collate<wchar_t> wfacet;
+ utf16_collator(winlocale lc,size_t refs = 0) :
+ collator<wchar_t>(refs),
+ lc_(lc)
+ {
+ }
+ virtual int do_compare(collator_base::level_type level,wchar_t const *lb,wchar_t const *le,wchar_t const *rb,wchar_t const *re) const
+ {
+ return wcscoll_l(level,lb,le,rb,re,lc_);
+ }
+ virtual long do_hash(collator_base::level_type level,wchar_t const *b,wchar_t const *e) const
+ {
+ std::wstring key = do_transform(level,b,e);
+ char const *begin = reinterpret_cast<char const *>(key.c_str());
+ char const *end = begin + key.size()*sizeof(wchar_t);
+ return gnu_gettext::pj_winberger_hash_function(begin,end);
+ }
+ virtual std::wstring do_transform(collator_base::level_type level,wchar_t const *b,wchar_t const *e) const
+ {
+ return wcsxfrm_l(level,b,e,lc_);
+ }
+private:
+ winlocale lc_;
+};
+
+
+std::locale create_collate( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type)
+{
+ if(lc.is_c()) {
+ switch(type) {
+ case char_facet:
+ return std::locale(in,new std::collate_byname<char>("C"));
+ case wchar_t_facet:
+ return std::locale(in,new std::collate_byname<wchar_t>("C"));
+ }
+ }
+ else {
+ switch(type) {
+ case char_facet:
+ return std::locale(in,new utf8_collator(lc));
+ case wchar_t_facet:
+ return std::locale(in,new utf16_collator(lc));
+ }
+ }
+ return in;
+}
+
+
+} // impl_std
+} // locale
+} //boost
+
+
+
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/contrib/restricted/boost/libs/locale/src/win32/converter.cpp b/contrib/restricted/boost/libs/locale/src/win32/converter.cpp
new file mode 100644
index 0000000000..fffb0c7b8a
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/converter.cpp
@@ -0,0 +1,106 @@
+//
+// 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 <stdexcept>
+#include <boost/locale/generator.hpp>
+#include <boost/locale/conversion.hpp>
+#include <boost/locale/encoding.hpp>
+#include <vector>
+#include <string.h>
+#include "api.hpp"
+#include "all_generator.hpp"
+
+namespace boost {
+namespace locale {
+namespace impl_win {
+
+class utf16_converter : public converter<wchar_t>
+{
+public:
+ utf16_converter(winlocale const &lc,size_t refs = 0) :
+ converter<wchar_t>(refs),
+ lc_(lc)
+ {
+ }
+ virtual std::wstring convert(converter_base::conversion_type how,wchar_t const *begin,wchar_t const *end,int flags = 0) const
+ {
+ switch(how) {
+ case converter_base::upper_case:
+ return towupper_l(begin,end,lc_);
+ case converter_base::lower_case:
+ return towlower_l(begin,end,lc_);
+ case converter_base::case_folding:
+ return wcsfold(begin,end);
+ case converter_base::normalization:
+ return wcsnormalize(static_cast<norm_type>(flags),begin,end);
+ default:
+ return std::wstring(begin,end-begin);
+ }
+ }
+private:
+ winlocale lc_;
+};
+
+class utf8_converter : public converter<char> {
+public:
+ utf8_converter(winlocale const &lc,size_t refs = 0) :
+ converter<char>(refs),
+ lc_(lc)
+ {
+ }
+ virtual std::string convert(converter_base::conversion_type how,char const *begin,char const *end,int flags = 0) const
+ {
+ std::wstring tmp = conv::to_utf<wchar_t>(begin,end,"UTF-8");
+ wchar_t const *wb=tmp.c_str();
+ wchar_t const *we=wb+tmp.size();
+
+ std::wstring res;
+
+ switch(how) {
+ case upper_case:
+ res = towupper_l(wb,we,lc_);
+ break;
+ case lower_case:
+ res = towlower_l(wb,we,lc_);
+ break;
+ case case_folding:
+ res = wcsfold(wb,we);
+ break;
+ case normalization:
+ res = wcsnormalize(static_cast<norm_type>(flags),wb,we);
+ break;
+ default:
+ res = tmp; // make gcc happy
+ }
+ return conv::from_utf(res,"UTF-8");
+ }
+private:
+ winlocale lc_;
+};
+
+std::locale create_convert( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type)
+{
+ switch(type) {
+ case char_facet:
+ return std::locale(in,new utf8_converter(lc));
+ case wchar_t_facet:
+ return std::locale(in,new utf16_converter(lc));
+ default:
+ return in;
+ }
+}
+
+
+} // namespace impl_win32
+} // locale
+} // boost
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/contrib/restricted/boost/libs/locale/src/win32/lcid.cpp b/contrib/restricted/boost/libs/locale/src/win32/lcid.cpp
new file mode 100644
index 0000000000..67542e6c6b
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/lcid.cpp
@@ -0,0 +1,127 @@
+//
+// 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 "lcid.hpp"
+#include <string.h>
+#include <string>
+#include <sstream>
+#include <map>
+
+#include "../util/locale_data.hpp"
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <windows.h>
+
+#include <boost/thread/mutex.hpp>
+
+namespace boost {
+namespace locale {
+namespace impl_win {
+
+typedef std::map<std::string,unsigned> table_type;
+
+static table_type * volatile table = 0;
+
+boost::mutex &lcid_table_mutex()
+{
+ static boost::mutex m;
+ return m;
+}
+
+table_type &real_lcid_table()
+{
+ static table_type table;
+ return table;
+}
+
+BOOL CALLBACK proc(char *s)
+{
+ table_type &tbl = real_lcid_table();
+ try {
+ std::istringstream ss;
+ ss.str(s);
+ ss >> std::hex;
+
+ unsigned lcid ;
+ ss >>lcid;
+ if(ss.fail() || !ss.eof()) {
+ return FALSE;
+ }
+
+ char iso_639_lang[16];
+ char iso_3166_country[16];
+ if(GetLocaleInfoA(lcid,LOCALE_SISO639LANGNAME,iso_639_lang,sizeof(iso_639_lang))==0)
+ return FALSE;
+ std::string lc_name = iso_639_lang;
+ if(GetLocaleInfoA(lcid,LOCALE_SISO3166CTRYNAME,iso_3166_country,sizeof(iso_3166_country))!=0) {
+ lc_name += "_";
+ lc_name += iso_3166_country;
+ }
+ table_type::iterator p = tbl.find(lc_name);
+ if(p!=tbl.end()) {
+ if(p->second > lcid)
+ p->second = lcid;
+ }
+ else {
+ tbl[lc_name]=lcid;
+ }
+ }
+ catch(...) {
+ tbl.clear();
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+table_type const &get_ready_lcid_table()
+{
+ if(table)
+ return *table;
+ else {
+ boost::unique_lock<boost::mutex> lock(lcid_table_mutex());
+ if(table)
+ return *table;
+ EnumSystemLocalesA(proc,LCID_INSTALLED);
+ table = &real_lcid_table();
+ return *table;
+ }
+}
+
+unsigned locale_to_lcid(std::string const &locale_name)
+{
+ if(locale_name.empty()) {
+ return LOCALE_USER_DEFAULT;
+ }
+ boost::locale::util::locale_data d;
+ d.parse(locale_name);
+ std::string id = d.language;
+
+ if(!d.country.empty()) {
+ id+="_"+d.country;
+ }
+ if(!d.variant.empty()) {
+ id+="@" + d.variant;
+ }
+
+ table_type const &tbl = get_ready_lcid_table();
+ table_type::const_iterator p = tbl.find(id);
+
+ unsigned lcid = 0;
+ if(p!=tbl.end())
+ lcid = p->second;
+ return lcid;
+}
+
+
+} // impl_win
+} // locale
+} // boost
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/contrib/restricted/boost/libs/locale/src/win32/numeric.cpp b/contrib/restricted/boost/libs/locale/src/win32/numeric.cpp
new file mode 100644
index 0000000000..00bc94fd6d
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/numeric.cpp
@@ -0,0 +1,245 @@
+//
+// 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 <boost/shared_ptr.hpp>
+#include <sstream>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <wctype.h>
+#include <ctype.h>
+
+#include "all_generator.hpp"
+#include "api.hpp"
+#include "../util/numeric.hpp"
+
+namespace boost {
+namespace locale {
+namespace impl_win {
+ namespace {
+
+ std::ostreambuf_iterator<wchar_t> write_it(std::ostreambuf_iterator<wchar_t> out,std::wstring const &s)
+ {
+ for(size_t i=0;i<s.size();i++)
+ *out++ = s[i];
+ return out;
+ }
+
+ std::ostreambuf_iterator<char> write_it(std::ostreambuf_iterator<char> out,std::wstring const &s)
+ {
+ std::string tmp = conv::from_utf(s,"UTF-8");
+ for(size_t i=0;i<tmp.size();i++)
+ *out++ = tmp[i];
+ return out;
+ }
+ }
+
+
+template<typename CharType>
+class num_format : public util::base_num_format<CharType>
+{
+public:
+ typedef typename std::num_put<CharType>::iter_type iter_type;
+ typedef std::basic_string<CharType> string_type;
+ typedef CharType char_type;
+
+ num_format(winlocale const &lc,size_t refs = 0) :
+ util::base_num_format<CharType>(refs),
+ lc_(lc)
+ {
+ }
+private:
+
+ virtual
+ iter_type do_format_currency(bool /*intl*/,iter_type out,std::ios_base &ios,char_type fill,long double val) const
+ {
+ if(lc_.is_c()) {
+ std::locale loc = ios.getloc();
+ int digits = std::use_facet<std::moneypunct<char_type> >(loc).frac_digits();
+ while(digits > 0) {
+ val*=10;
+ digits --;
+ }
+ std::ios_base::fmtflags f=ios.flags();
+ ios.flags(f | std::ios_base::showbase);
+ out = std::use_facet<std::money_put<char_type> >(loc).put(out,false,ios,fill,val);
+ ios.flags(f);
+ return out;
+ }
+ else {
+ std::wstring cur = wcsfmon_l(val,lc_);
+ return write_it(out,cur);
+ }
+ }
+
+private:
+ winlocale lc_;
+
+}; /// num_format
+
+template<typename CharType>
+class time_put_win : public std::time_put<CharType> {
+public:
+ time_put_win(winlocale const &lc, size_t refs = 0) :
+ std::time_put<CharType>(refs),
+ lc_(lc)
+ {
+ }
+ virtual ~time_put_win()
+ {
+ }
+ typedef typename std::time_put<CharType>::iter_type iter_type;
+ typedef CharType char_type;
+ typedef std::basic_string<char_type> string_type;
+
+ virtual iter_type do_put( iter_type out,
+ std::ios_base &/*ios*/,
+ CharType /*fill*/,
+ std::tm const *tm,
+ char format,
+ char /*modifier*/) const
+ {
+ return write_it(out,wcsftime_l(format,tm,lc_));
+ }
+
+private:
+ winlocale lc_;
+};
+
+
+template<typename CharType>
+class num_punct_win : public std::numpunct<CharType> {
+public:
+ typedef std::basic_string<CharType> string_type;
+ num_punct_win(winlocale const &lc,size_t refs = 0) :
+ std::numpunct<CharType>(refs)
+ {
+ numeric_info np = wcsnumformat_l(lc) ;
+ if(sizeof(CharType) == 1 && np.thousands_sep == L"\xA0")
+ np.thousands_sep=L" ";
+
+ to_str(np.thousands_sep,thousands_sep_);
+ to_str(np.decimal_point,decimal_point_);
+ grouping_ = np.grouping;
+ if(thousands_sep_.size() > 1)
+ grouping_ = std::string();
+ if(decimal_point_.size() > 1)
+ decimal_point_ = CharType('.');
+ }
+
+ void to_str(std::wstring &s1,std::wstring &s2)
+ {
+ s2.swap(s1);
+ }
+
+ void to_str(std::wstring &s1,std::string &s2)
+ {
+ s2=conv::from_utf(s1,"UTF-8");
+ }
+ virtual CharType do_decimal_point() const
+ {
+ return *decimal_point_.c_str();
+ }
+ virtual CharType do_thousands_sep() const
+ {
+ return *thousands_sep_.c_str();
+ }
+ virtual std::string do_grouping() const
+ {
+ return grouping_;
+ }
+ virtual string_type do_truename() const
+ {
+ static const char t[]="true";
+ return string_type(t,t+sizeof(t)-1);
+ }
+ virtual string_type do_falsename() const
+ {
+ static const char t[]="false";
+ return string_type(t,t+sizeof(t)-1);
+ }
+private:
+ string_type decimal_point_;
+ string_type thousands_sep_;
+ std::string grouping_;
+};
+
+template<typename CharType>
+std::locale create_formatting_impl(std::locale const &in,winlocale const &lc)
+{
+ if(lc.is_c()) {
+ std::locale tmp(in,new std::numpunct_byname<CharType>("C"));
+ tmp=std::locale(tmp,new std::time_put_byname<CharType>("C"));
+ tmp = std::locale(tmp,new num_format<CharType>(lc));
+ return tmp;
+ }
+ else {
+ std::locale tmp(in,new num_punct_win<CharType>(lc));
+ tmp = std::locale(tmp,new time_put_win<CharType>(lc));
+ tmp = std::locale(tmp,new num_format<CharType>(lc));
+ return tmp;
+ }
+}
+
+template<typename CharType>
+std::locale create_parsing_impl(std::locale const &in,winlocale const &lc)
+{
+ std::numpunct<CharType> *np = 0;
+ if(lc.is_c())
+ np = new std::numpunct_byname<CharType>("C");
+ else
+ np = new num_punct_win<CharType>(lc);
+ std::locale tmp(in,np);
+ tmp = std::locale(tmp,new util::base_num_parse<CharType>());
+ return tmp;
+}
+
+
+std::locale create_formatting( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type)
+{
+ switch(type) {
+ case char_facet:
+ return create_formatting_impl<char>(in,lc);
+ case wchar_t_facet:
+ return create_formatting_impl<wchar_t>(in,lc);
+ default:
+ return in;
+ }
+}
+
+std::locale create_parsing( std::locale const &in,
+ winlocale const &lc,
+ character_facet_type type)
+{
+ switch(type) {
+ case char_facet:
+ return create_parsing_impl<char>(in,lc);
+ case wchar_t_facet:
+ return create_parsing_impl<wchar_t>(in,lc);
+ default:
+ return in;
+ }
+}
+
+
+
+} // impl_std
+} // locale
+} //boost
+
+
+
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/contrib/restricted/boost/libs/locale/src/win32/win_backend.cpp b/contrib/restricted/boost/libs/locale/src/win32/win_backend.cpp
new file mode 100644
index 0000000000..cd9ec8375b
--- /dev/null
+++ b/contrib/restricted/boost/libs/locale/src/win32/win_backend.cpp
@@ -0,0 +1,153 @@
+//
+// 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 <boost/locale/info.hpp>
+#include "all_generator.hpp"
+#include "win_backend.hpp"
+#include <boost/locale/util.hpp>
+#include "../util/gregorian.hpp"
+#include "../util/locale_data.hpp"
+#include "api.hpp"
+#include <algorithm>
+#include <iterator>
+
+namespace boost {
+namespace locale {
+namespace impl_win {
+
+ class winapi_localization_backend : public localization_backend {
+ public:
+ winapi_localization_backend() :
+ invalid_(true)
+ {
+ }
+ winapi_localization_backend(winapi_localization_backend const &other) :
+ localization_backend(),
+ paths_(other.paths_),
+ domains_(other.domains_),
+ locale_id_(other.locale_id_),
+ invalid_(true)
+ {
+ }
+ virtual winapi_localization_backend *clone() const
+ {
+ return new winapi_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);
+
+ }
+ void clear_options()
+ {
+ invalid_ = true;
+ locale_id_.clear();
+ paths_.clear();
+ domains_.clear();
+ }
+
+ void prepare_data()
+ {
+ if(!invalid_)
+ return;
+ invalid_ = false;
+ if(locale_id_.empty()) {
+ real_id_ = util::get_system_locale(true); // always UTF-8
+ lc_ = winlocale(real_id_);
+ }
+ else {
+ lc_=winlocale(locale_id_);
+ real_id_ = locale_id_;
+ }
+ util::locale_data d;
+ d.parse(real_id_);
+ if(!d.utf8) {
+ lc_ = winlocale();
+ // Make it C as non-UTF8 locales are not supported
+ }
+ }
+
+ 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,lc_,type);
+ case collation_facet:
+ return create_collate(base,lc_,type);
+ case formatting_facet:
+ return create_formatting(base,lc_,type);
+ case parsing_facet:
+ return create_parsing(base,lc_,type);
+ case calendar_facet:
+ {
+ util::locale_data inf;
+ inf.parse(real_id_);
+ return util::install_gregorian_calendar(base,inf.country);
+ }
+ case message_facet:
+ {
+ gnu_gettext::messages_info minf;
+ std::locale tmp=util::create_info(std::locale::classic(),real_id_);
+ boost::locale::info const &inf=std::use_facet<boost::locale::info>(tmp);
+ 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));
+ 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));
+ default:
+ return base;
+ }
+ }
+ case information_facet:
+ return util::create_info(base,real_id_);
+ case codepage_facet:
+ return util::create_utf8_codecvt(base,type);
+ default:
+ return base;
+ }
+ }
+
+ private:
+
+ std::vector<std::string> paths_;
+ std::vector<std::string> domains_;
+ std::string locale_id_;
+ std::string real_id_;
+
+ bool invalid_;
+ winlocale lc_;
+ };
+
+ localization_backend *create_localization_backend()
+ {
+ return new winapi_localization_backend();
+ }
+
+} // impl win
+} // locale
+} // boost
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4