aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbString.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2006-06-25 09:05:58 (GMT)
committersimonb <simonb>2006-06-25 09:05:58 (GMT)
commit80389b5dd5e7be4025cafbb2e7b055fd06f4f56d (patch)
tree1406d6c5044958bc40f2b7f4f8326ca8cc01629f /src/FbTk/FbString.cc
parent577859034db0e0e36ceab85ebba62e1018dd3361 (diff)
downloadfluxbox-80389b5dd5e7be4025cafbb2e7b055fd06f4f56d.zip
fluxbox-80389b5dd5e7be4025cafbb2e7b055fd06f4f56d.tar.bz2
support encodings in menu files
Diffstat (limited to 'src/FbTk/FbString.cc')
-rw-r--r--src/FbTk/FbString.cc49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/FbTk/FbString.cc b/src/FbTk/FbString.cc
index 93f6aa7..3ed1c70 100644
--- a/src/FbTk/FbString.cc
+++ b/src/FbTk/FbString.cc
@@ -54,6 +54,8 @@ static iconv_t *iconv_convs = 0;
54static int iconv_convs[CONVSIZE]; 54static int iconv_convs[CONVSIZE];
55#endif // HAVE_ICONV 55#endif // HAVE_ICONV
56 56
57static std::string locale_codeset;
58
57/// Initialise all of the iconv conversion descriptors 59/// Initialise all of the iconv conversion descriptors
58void init() { 60void init() {
59 setlocale(LC_CTYPE, ""); 61 setlocale(LC_CTYPE, "");
@@ -65,9 +67,9 @@ void init() {
65 iconv_convs = new iconv_t[CONVSIZE]; 67 iconv_convs = new iconv_t[CONVSIZE];
66 68
67#ifdef CODESET 69#ifdef CODESET
68 std::string locale_codeset = nl_langinfo(CODESET); 70 locale_codeset = nl_langinfo(CODESET);
69#else // openbsd doesnt have this (yet?) 71#else // openbsd doesnt have this (yet?)
70 std::string locale_codeset = ""; 72 locale_codeset = "";
71 std::string locale = setlocale(LC_CTYPE, NULL); 73 std::string locale = setlocale(LC_CTYPE, NULL);
72 size_t pos = locale.find('.'); 74 size_t pos = locale.find('.');
73 if (pos != std::string::npos) 75 if (pos != std::string::npos)
@@ -229,4 +231,47 @@ bool haveUTF8() {
229 231
230}; // end namespace StringUtil 232}; // end namespace StringUtil
231 233
234StringConvertor::StringConvertor(EncodingTarget target): m_iconv((iconv_t)(-1)) {
235#ifdef HAVE_ICONV
236 if (target == ToLocaleStr)
237 m_destencoding = FbStringUtil::locale_codeset;
238 else
239 m_destencoding = "UTF-8";
240#endif
241}
242
243StringConvertor::~StringConvertor() {
244#ifdef HAVE_ICONV
245 if (m_iconv != ((iconv_t)-1))
246 iconv_close(m_iconv);
247#endif
248}
249
250bool StringConvertor::setSource(const std::string &encoding) {
251#ifdef HAVE_ICONV
252 std::string tempenc = encoding;
253 if (encoding == "")
254 tempenc = FbStringUtil::locale_codeset;
255
256 iconv_t newiconv = iconv_open(m_destencoding.c_str(), tempenc.c_str());
257 if (newiconv == ((iconv_t)(-1)))
258 return false;
259 else {
260 iconv_close(m_iconv);
261 m_iconv = newiconv;
262 return true;
263 }
264#else
265 return false;
266#endif
267}
268
269std::string StringConvertor::recode(const std::string &src) {
270#ifdef HAVE_ICONV
271 return FbStringUtil::recode(m_iconv, src);
272#else
273 return src;
274#endif
275}
276
232}; // end namespace FbTk 277}; // end namespace FbTk