32 #include "../logger/Logger.h" 33 #include "../Exception.h" 34 #include "../translator/Translator.h" 37 #include <boost/assign/list_of.hpp> 38 #include <boost/format.hpp> 39 #include <boost/locale.hpp> 54 return boost::locale::conv::to_utf<char>(src,
EncodingString.at(from));
59 boost::locale::generator g;
60 g.locale_cache_enabled(
true);
63 std::locale loc = g(boost::locale::util::get_system_locale(
true));
64 return boost::locale::conv::to_utf<char>(src, loc);
66 catch(std::exception &e)
68 boost::format err_msg(
TE_TR(
69 "Could not get the system locale in order to convert fromUTF8 to the " 79 boost::locale::generator g;
80 g.locale_cache_enabled(
true);
83 std::locale loc = g(boost::locale::util::get_system_locale(
false));
85 std::string teste = boost::locale::conv::from_utf<char>(src, loc);
87 return boost::locale::conv::from_utf<char>(src, loc);
89 catch(std::exception &e)
91 boost::format err_msg(
TE_TR(
92 "Could not get the system locale in order to convert fromUTF8 to the " 103 return boost::locale::conv::from_utf<char>(src,
EncodingString.at(to));
115 std::string decomposed;
116 boost::locale::generator g;
120 g.locale_cache_enabled(
true);
121 std::locale loc = g.generate(
"");
122 decomposed = boost::locale::normalize(src, boost::locale::norm_nfd, loc);
124 catch(std::exception&)
126 boost::format err_msg(
TE_TR(
127 "Could not decompose the given string to extract the ASCII " 133 std::string ascii_str;
135 for(
size_t i = 0; decomposed.size() > i; ++i)
136 if(decomposed[i] >= 0 && decomposed[i] <= 127) ascii_str += decomposed[i];
147 const std::string &name)
149 std::map<EncodingType, std::string>::const_iterator it;
152 if(it->second == name)
return it->first;
155 boost::format err_msg(
TE_TR(
"There is no encoding type with the name: %1%."));
161 std::vector<std::string> vec;
163 std::map<EncodingType, std::string>::const_iterator it;
166 vec.push_back(it->second);
const std::map< te::core::EncodingType, std::string > EncodingString
static std::string toASCII(const std::string &src)
Decomposes a UTF-8 encoded string and extracts its ASCII characters.
#define TE_TR(message)
It marks a string in order to get translated.
static std::string fromUTF8(const std::string &src)
Convert a string in UTF-8 to the current locale encoding.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
EncodingType
Supported character encodings.
static std::string getEncodingName(EncodingType et)
Retrive a string from a given character encoding type enum.
A class for handling character enconding/decoding.
static te::core::EncodingType getEncodingType(const std::string &name)
Retrive an EncodingType from a given character encoding name.
static std::string convert(const std::string &src, EncodingType from, EncodingType to)
Convert a string from one character encoding to another one.
static std::string toUTF8(const std::string &src)
Convert a string from a current locale encoding to UTF-8.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
Base exception class for TerraLib Core Runtime Library.
static std::vector< std::string > getEncodingList()
Retrive a vector of string with all available encoding types name.