diff --git a/libs/locale/src/util/locale_data.cpp b/libs/locale/src/util/locale_data.cpp index b4598a0..c2e84cd 100644 --- a/libs/locale/src/util/locale_data.cpp +++ b/libs/locale/src/util/locale_data.cpp @@ -9,101 +9,62 @@ #include "locale_data.hpp" #include "../encoding/conv.hpp" #include +#include 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= 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) + struct name_state { - 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= 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)); + name_state(int _order = -1, std::string* _section = 0, bool _upper = false) + : order(_order), section(_section), upper(_upper) + { } - } + + int order; + std::string* section; + bool upper; + }; - void locale_data::parse_from_encoding(std::string const &locale_name) + void locale_data::parse(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= 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 states; + states[ 0 ]=name_state(0,&language,false); + states['_']=name_state(1,&country,true); + states['.']=name_state(2,&encoding,false); + states['@']=name_state(3,&variant,false); + + name_state* state=&states[0]; + + for(unsigned i=0;i state->order) + { + state=&states[c]; + } + else + { + if(isalpha(c)) + *state->section+=(state->upper) ? toupper(c) : tolower(c); + else + *state->section+=c; + } } + + if(!language.length()) + language = "C"; + + if(!encoding.length()) + encoding = "us-ascii"; + + utf8=conv::impl::normalize_encoding(encoding.c_str()) == "utf8"; } } // util