blob: 6b9c617e3d2f4cc8a0955d9fa67fda74b40dbcd9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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_data.hpp"
#include "../encoding/conv.hpp"
#include <string>
namespace boost {
namespace locale {
namespace util {
void locale_data::parse(std::string const &locale_name)
{
language = "C";
country.clear();
variant.clear();
encoding = "us-ascii";
utf8=false;
parse_from_lang(locale_name);
}
void locale_data::parse_from_lang(std::string const &locale_name)
{
size_t end = locale_name.find_first_of("-_@.");
std::string tmp = locale_name.substr(0,end);
if(tmp.empty())
return;
for(unsigned i=0;i<tmp.size();i++) {
if('A' <= tmp[i] && tmp[i]<='Z')
tmp[i]=tmp[i]-'A'+'a';
else if(tmp[i] < 'a' && 'z' < tmp[i])
return;
}
language = tmp;
if(end >= locale_name.size())
return;
if(locale_name[end] == '-' || locale_name[end]=='_') {
parse_from_country(locale_name.substr(end+1));
}
else if(locale_name[end] == '.') {
parse_from_encoding(locale_name.substr(end+1));
}
else if(locale_name[end] == '@') {
parse_from_variant(locale_name.substr(end+1));
}
}
void locale_data::parse_from_country(std::string const &locale_name)
{
size_t end = locale_name.find_first_of("@.");
std::string tmp = locale_name.substr(0,end);
if(tmp.empty())
return;
for(unsigned i=0;i<tmp.size();i++) {
if('a' <= tmp[i] && tmp[i]<='z')
tmp[i]=tmp[i]-'a'+'A';
else if(tmp[i] < 'A' && 'Z' < tmp[i])
return;
}
country = tmp;
if(end >= locale_name.size())
return;
else if(locale_name[end] == '.') {
parse_from_encoding(locale_name.substr(end+1));
}
else if(locale_name[end] == '@') {
parse_from_variant(locale_name.substr(end+1));
}
}
void locale_data::parse_from_encoding(std::string const &locale_name)
{
size_t end = locale_name.find_first_of('@');
std::string tmp = locale_name.substr(0,end);
if(tmp.empty())
return;
for(unsigned i=0;i<tmp.size();i++) {
if('A' <= tmp[i] && tmp[i]<='Z')
tmp[i]=tmp[i]-'A'+'a';
}
encoding = tmp;
utf8 = conv::impl::normalize_encoding(encoding.c_str()) == "utf8";
if(end >= locale_name.size())
return;
if(locale_name[end] == '@') {
parse_from_variant(locale_name.substr(end+1));
}
}
void locale_data::parse_from_variant(std::string const &locale_name)
{
variant = locale_name;
for(unsigned i=0;i<variant.size();i++) {
if('A' <= variant[i] && variant[i]<='Z')
variant[i]=variant[i]-'A'+'a';
}
}
} // util
} // locale
} // boost
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
|