aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbString.cc
diff options
context:
space:
mode:
authormathias <mathias>2006-10-27 06:57:43 (GMT)
committermathias <mathias>2006-10-27 06:57:43 (GMT)
commit10082d821d6691f42a8d8ad6fa2e42e5b3f44edd (patch)
tree99c94a6105cf35612307e307be343eda2aea8baf /src/FbTk/FbString.cc
parent34b7f7ddfc3e914238fd0d30ff50c4f37c2a6dd8 (diff)
downloadfluxbox_pavel-10082d821d6691f42a8d8ad6fa2e42e5b3f44edd.zip
fluxbox_pavel-10082d821d6691f42a8d8ad6fa2e42e5b3f44edd.tar.bz2
cosmetic patch from slava semushin, removes whitespaces and
uses only those things from "namespace std" what we really need.
Diffstat (limited to 'src/FbTk/FbString.cc')
-rw-r--r--src/FbTk/FbString.cc50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/FbTk/FbString.cc b/src/FbTk/FbString.cc
index ff4d27a..c767a30 100644
--- a/src/FbTk/FbString.cc
+++ b/src/FbTk/FbString.cc
@@ -40,7 +40,13 @@
40#include <locale.h> 40#include <locale.h>
41 41
42#include <iostream> 42#include <iostream>
43using namespace std; 43
44using std::string;
45
46#ifdef DEBUG
47using std::cerr;
48using std::endl;
49#endif // DEBUG
44 50
45namespace FbTk { 51namespace FbTk {
46 52
@@ -54,7 +60,7 @@ static iconv_t *iconv_convs = 0;
54static int iconv_convs[CONVSIZE]; 60static int iconv_convs[CONVSIZE];
55#endif // HAVE_ICONV 61#endif // HAVE_ICONV
56 62
57static std::string locale_codeset; 63static string locale_codeset;
58 64
59/// Initialise all of the iconv conversion descriptors 65/// Initialise all of the iconv conversion descriptors
60void init() { 66void init() {
@@ -70,9 +76,9 @@ void init() {
70 locale_codeset = nl_langinfo(CODESET); 76 locale_codeset = nl_langinfo(CODESET);
71#else // openbsd doesnt have this (yet?) 77#else // openbsd doesnt have this (yet?)
72 locale_codeset = ""; 78 locale_codeset = "";
73 std::string locale = setlocale(LC_CTYPE, NULL); 79 string locale = setlocale(LC_CTYPE, NULL);
74 size_t pos = locale.find('.'); 80 size_t pos = locale.find('.');
75 if (pos != std::string::npos) 81 if (pos != string::npos)
76 locale_codeset = locale.substr(pos); 82 locale_codeset = locale.substr(pos);
77#endif // CODESET 83#endif // CODESET
78 84
@@ -85,7 +91,7 @@ void init() {
85 iconv_convs[FB2LOCALE] = iconv_open(locale_codeset.c_str(), "UTF-8"); 91 iconv_convs[FB2LOCALE] = iconv_open(locale_codeset.c_str(), "UTF-8");
86 iconv_convs[LOCALE2FB] = iconv_open("UTF-8", locale_codeset.c_str()); 92 iconv_convs[LOCALE2FB] = iconv_open("UTF-8", locale_codeset.c_str());
87#else 93#else
88 for (int i=0; i < CONVSIZE; ++i) 94 for (int i=0; i < CONVSIZE; ++i)
89 iconv_convs[i] = 0; 95 iconv_convs[i] = 0;
90#endif // HAVE_ICONV 96#endif // HAVE_ICONV
91 97
@@ -96,7 +102,7 @@ void shutdown() {
96 if (iconv_convs == 0) 102 if (iconv_convs == 0)
97 return; 103 return;
98 104
99 for (int i=0; i < CONVSIZE; ++i) 105 for (int i=0; i < CONVSIZE; ++i)
100 if (iconv_convs[i] != (iconv_t)(-1)) 106 if (iconv_convs[i] != (iconv_t)(-1))
101 iconv_close(iconv_convs[i]); 107 iconv_close(iconv_convs[i]);
102 108
@@ -118,18 +124,18 @@ void shutdown() {
118 @return the recoded string, or 0 on failure 124 @return the recoded string, or 0 on failure
119*/ 125*/
120 126
121/** 127/**
122 --NOTE-- 128 --NOTE--
123 In the "C" locale, this will strip any high-bit characters 129 In the "C" locale, this will strip any high-bit characters
124 because C means 7-bit ASCII charset. If you don't want this 130 because C means 7-bit ASCII charset. If you don't want this
125 then you need to set your locale to something UTF-8, OR something 131 then you need to set your locale to something UTF-8, OR something
126 ISO8859-1. 132 ISO8859-1.
127*/ 133*/
128std::string recode(iconv_t cd, 134string recode(iconv_t cd,
129 const std::string &in) { 135 const string &in) {
130 136
131 // If empty message, yes this can happen, return 137 // If empty message, yes this can happen, return
132 if (in.empty()) 138 if (in.empty())
133 return ""; 139 return "";
134 140
135 if (cd == ((iconv_t)(-1))) 141 if (cd == ((iconv_t)(-1)))
@@ -183,7 +189,7 @@ std::string recode(iconv_t cd,
183 } 189 }
184 190
185 // copy to our return string 191 // copy to our return string
186 std::string ret; 192 string ret;
187 ret.append(out, outsize - outbytesleft); 193 ret.append(out, outsize - outbytesleft);
188 194
189 // reset the conversion descriptor 195 // reset the conversion descriptor
@@ -195,27 +201,27 @@ std::string recode(iconv_t cd,
195 return ret; 201 return ret;
196} 202}
197#else 203#else
198std::string recode(int cd, 204string recode(int cd,
199 const std::string &str) { 205 const string &str) {
200 return str; 206 return str;
201} 207}
202#endif // HAVE_ICONV 208#endif // HAVE_ICONV
203 209
204FbString XStrToFb(const std::string &src) { 210FbString XStrToFb(const string &src) {
205 return recode(iconv_convs[X2FB], src); 211 return recode(iconv_convs[X2FB], src);
206} 212}
207 213
208std::string FbStrToX(const FbString &src) { 214string FbStrToX(const FbString &src) {
209 return recode(iconv_convs[FB2X], src); 215 return recode(iconv_convs[FB2X], src);
210} 216}
211 217
212 218
213/// Handle thislocale string encodings (strings coming from userspace) 219/// Handle thislocale string encodings (strings coming from userspace)
214FbString LocaleStrToFb(const std::string &src) { 220FbString LocaleStrToFb(const string &src) {
215 return recode(iconv_convs[LOCALE2FB], src); 221 return recode(iconv_convs[LOCALE2FB], src);
216} 222}
217 223
218std::string FbStrToLocale(const FbString &src) { 224string FbStrToLocale(const FbString &src) {
219 return recode(iconv_convs[FB2LOCALE], src); 225 return recode(iconv_convs[FB2LOCALE], src);
220} 226}
221 227
@@ -231,7 +237,7 @@ bool haveUTF8() {
231 237
232}; // end namespace StringUtil 238}; // end namespace StringUtil
233 239
234StringConvertor::StringConvertor(EncodingTarget target): 240StringConvertor::StringConvertor(EncodingTarget target):
235#ifdef HAVE_ICONV 241#ifdef HAVE_ICONV
236 m_iconv((iconv_t)(-1)) { 242 m_iconv((iconv_t)(-1)) {
237 if (target == ToLocaleStr) 243 if (target == ToLocaleStr)
@@ -251,9 +257,9 @@ StringConvertor::~StringConvertor() {
251#endif 257#endif
252} 258}
253 259
254bool StringConvertor::setSource(const std::string &encoding) { 260bool StringConvertor::setSource(const string &encoding) {
255#ifdef HAVE_ICONV 261#ifdef HAVE_ICONV
256 std::string tempenc = encoding; 262 string tempenc = encoding;
257 if (encoding == "") 263 if (encoding == "")
258 tempenc = FbStringUtil::locale_codeset; 264 tempenc = FbStringUtil::locale_codeset;
259 265
@@ -270,8 +276,8 @@ bool StringConvertor::setSource(const std::string &encoding) {
270 return false; 276 return false;
271#endif 277#endif
272} 278}
273 279
274std::string StringConvertor::recode(const std::string &src) { 280string StringConvertor::recode(const string &src) {
275#ifdef HAVE_ICONV 281#ifdef HAVE_ICONV
276 return FbStringUtil::recode(m_iconv, src); 282 return FbStringUtil::recode(m_iconv, src);
277#else 283#else