Skip to content
This repository
Browse code

Merge pull request #3097 from Karlson2k/charsetconverter_rework_01

CharsetConverter rework - part 1
  • Loading branch information...
commit ecce0015c29bf74758af2a47524a9e09c3cdb3d4 2 parents 1f83206 + 4af1fcd
Martijn Kaijser authored September 22, 2013
6  configure.in
@@ -916,6 +916,12 @@ if test "x$have_builtin_sync_val_compare_and_swap" = "xyes"; then
916 916
         [Define to 1 if your compiler supports the __sync_val_compare_and_swap() intrinsic.])
917 917
 fi
918 918
 
  919
+# Check for u16string/u32string declarations
  920
+AC_LANG_PUSH([C++])
  921
+AC_CHECK_TYPES([std::u16string, std::u32string], [], [], [[#include <string>]])
  922
+AC_CHECK_TYPES([char16_t, char32_t])
  923
+AC_LANG_POP([C++])
  924
+
919 925
 # Add top source directory for all builds so we can use config.h
920 926
 INCLUDES="-I\$(abs_top_srcdir) $INCLUDES" 
921 927
 
1  project/VS2010Express/XBMC.vcxproj
@@ -1210,6 +1210,7 @@
1210 1210
     <ClInclude Include="..\..\xbmc\utils\LegacyPathTranslation.h" />
1211 1211
     <ClInclude Include="..\..\xbmc\utils\RssManager.h" />
1212 1212
     <ClInclude Include="..\..\xbmc\utils\StringValidation.h" />
  1213
+    <ClInclude Include="..\..\xbmc\utils\uXstrings.h" />
1213 1214
     <ClInclude Include="..\..\xbmc\utils\Vector.h" />
1214 1215
     <ClInclude Include="..\..\xbmc\video\FFmpegVideoDecoder.h" />
1215 1216
     <ClInclude Include="..\..\xbmc\interfaces\python\swig.h" />
3  project/VS2010Express/XBMC.vcxproj.filters
@@ -6034,6 +6034,9 @@
6034 6034
     <ClInclude Include="..\..\xbmc\utils\StringValidation.h">
6035 6035
       <Filter>utils</Filter>
6036 6036
     </ClInclude>
  6037
+    <ClInclude Include="..\..\xbmc\utils\uXstrings.h">
  6038
+      <Filter>utils</Filter>
  6039
+    </ClInclude>
6037 6040
   </ItemGroup>
6038 6041
   <ItemGroup>
6039 6042
     <ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
2  xbmc/NfoFile.h
@@ -65,7 +65,7 @@ class CNfoFile
65 65
     if (encoding.IsEmpty())
66 66
       g_charsetConverter.unknownToUTF8(strUtf8);
67 67
     else
68  
-      g_charsetConverter.stringCharsetToUtf8(encoding, strDoc, strUtf8);
  68
+      g_charsetConverter.ToUtf8(encoding, strDoc, strUtf8);
69 69
 
70 70
     doc.Clear();
71 71
     doc.Parse(strUtf8.c_str(),0,TIXML_ENCODING_UTF8);
2  xbmc/cores/DllLoader/Win32DllLoader.cpp
@@ -157,7 +157,7 @@ bool Win32DllLoader::Load()
157 157
   CStdString strFileName = GetFileName();
158 158
 
159 159
   CStdStringW strDllW;
160  
-  g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(strFileName), strDllW);
  160
+  g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(strFileName), strDllW, false, false, false);
161 161
   m_dllHandle = LoadLibraryExW(strDllW.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
162 162
   if (!m_dllHandle)
163 163
   {
2  xbmc/cores/dvdplayer/DVDSubtitles/DVDSubtitleStream.cpp
@@ -61,7 +61,7 @@ bool CDVDSubtitleStream::Open(const string& strFile)
61 61
       {
62 62
         buffer[size_read] = buffer[size_read + 1] = '\0';
63 63
         CStdStringW temp; 
64  
-        g_charsetConverter.utf16LEtoW(CStdString16((uint16_t*)buffer),temp); 
  64
+        g_charsetConverter.utf16LEtoW(std::u16string((char16_t*)buffer),temp); 
65 65
         wstringstream << temp; 
66 66
       }
67 67
       delete pInputStream;
2  xbmc/filesystem/iso9660.cpp
@@ -701,7 +701,7 @@ bool iso9660::FindClose( HANDLE szLocalFolder )
701 701
 string iso9660::GetThinText(BYTE* strTxt, int iLen )
702 702
 {
703 703
   // convert from "fat" text (UTF-16BE) to "thin" text (UTF-8)
704  
-  CStdString16 strTxtUnicode((uint16_t*)strTxt, iLen / 2);
  704
+  std::u16string strTxtUnicode((char16_t*)strTxt, iLen / 2);
705 705
   CStdString utf8String;
706 706
 
707 707
   g_charsetConverter.utf16BEtoUTF8(strTxtUnicode, utf8String);
2  xbmc/guilib/LocalizeStrings.cpp
@@ -45,7 +45,7 @@ CStdString CLocalizeStrings::ToUTF8(const CStdString& strEncoding, const CStdStr
45 45
     return str;
46 46
 
47 47
   CStdString ret;
48  
-  g_charsetConverter.stringCharsetToUtf8(strEncoding, str, ret);
  48
+  g_charsetConverter.ToUtf8(strEncoding, str, ret);
49 49
   return ret;
50 50
 }
51 51
 
2  xbmc/music/karaoke/karaokelyricstextkar.cpp
@@ -603,7 +603,7 @@ CStdString CKaraokeLyricsTextKAR::convertText( const char * data )
603 603
   if ( g_charsetConverter.isValidUtf8(data) || CSettings::Get().GetString("karaoke.charset") == "DEFAULT" )
604 604
     strUTF8 = data;
605 605
   else
606  
-    g_charsetConverter.stringCharsetToUtf8( CSettings::Get().GetString("karaoke.charset"), data, strUTF8 );
  606
+    g_charsetConverter.ToUtf8( CSettings::Get().GetString("karaoke.charset"), data, strUTF8 );
607 607
 
608 608
   if ( strUTF8.size() == 0 )
609 609
     strUTF8 = " ";
2  xbmc/pictures/PictureInfoTag.cpp
@@ -328,7 +328,7 @@ const CStdString CPictureInfoTag::GetInfo(int info) const
328 328
     // Ascii, Unicode (UCS2), JIS (X208-1990), Unknown (application specific)
329 329
     if (m_exifInfo.CommentsCharset == EXIF_COMMENT_CHARSET_UNICODE)
330 330
     {
331  
-      g_charsetConverter.ucs2ToUTF8(CStdString16((uint16_t*)m_exifInfo.Comments), value);
  331
+      g_charsetConverter.ucs2ToUTF8(std::u16string((char16_t*)m_exifInfo.Comments), value);
332 332
     }
333 333
     else
334 334
     {
4  xbmc/playlists/SmartPlayList.cpp
@@ -211,7 +211,7 @@ bool CSmartPlaylistRule::Load(const TiXmlNode *node, const std::string &encoding
211 211
     if (encoding.empty()) // utf8
212 212
       utf8Parameter = parameter->ValueStr();
213 213
     else
214  
-      g_charsetConverter.stringCharsetToUtf8(encoding, parameter->ValueStr(), utf8Parameter);
  214
+      g_charsetConverter.ToUtf8(encoding, parameter->ValueStr(), utf8Parameter);
215 215
 
216 216
     if (!utf8Parameter.empty())
217 217
       m_parameter.push_back(utf8Parameter);
@@ -228,7 +228,7 @@ bool CSmartPlaylistRule::Load(const TiXmlNode *node, const std::string &encoding
228 228
         if (encoding.empty()) // utf8
229 229
           utf8Parameter = value->ValueStr();
230 230
         else
231  
-          g_charsetConverter.stringCharsetToUtf8(encoding, value->ValueStr(), utf8Parameter);
  231
+          g_charsetConverter.ToUtf8(encoding, value->ValueStr(), utf8Parameter);
232 232
 
233 233
         if (!utf8Parameter.empty())
234 234
           m_parameter.push_back(utf8Parameter);
372  xbmc/utils/CharsetConverter.cpp
@@ -20,6 +20,7 @@
20 20
 
21 21
 #include "CharsetConverter.h"
22 22
 #include "Util.h"
  23
+#include "utils/StringUtils.h"
23 24
 #include <fribidi/fribidi.h>
24 25
 #include "LangInfo.h"
25 26
 #include "guilib/LocalizeStrings.h"
@@ -55,11 +56,9 @@
55 56
 #endif
56 57
 
57 58
 
58  
-static iconv_t m_iconvStringCharsetToFontCharset = (iconv_t)-1;
59 59
 static iconv_t m_iconvSubtitleCharsetToW         = (iconv_t)-1;
60 60
 static iconv_t m_iconvUtf8ToStringCharset        = (iconv_t)-1;
61 61
 static iconv_t m_iconvStringCharsetToUtf8        = (iconv_t)-1;
62  
-static iconv_t m_iconvUcs2CharsetToStringCharset = (iconv_t)-1;
63 62
 static iconv_t m_iconvUtf32ToStringCharset       = (iconv_t)-1;
64 63
 static iconv_t m_iconvWtoUtf8                    = (iconv_t)-1;
65 64
 static iconv_t m_iconvUtf16LEtoW                 = (iconv_t)-1;
@@ -137,13 +136,15 @@ static struct SCharsetMapping
137 136
 };
138 137
 
139 138
 
140  
-#define UTF8_DEST_MULTIPLIER 6
  139
+/* single symbol sizes in chars */
  140
+const int CCharsetConverter::m_Utf8CharMinSize = 1;
  141
+const int CCharsetConverter::m_Utf8CharMaxSize = 6;
141 142
 
142 143
 #define ICONV_PREPARE(iconv) iconv=(iconv_t)-1
143 144
 #define ICONV_SAFE_CLOSE(iconv) if (iconv!=(iconv_t)-1) { iconv_close(iconv); iconv=(iconv_t)-1; }
144 145
 
145  
-size_t iconv_const (void* cd, const char** inbuf, size_t *inbytesleft,
146  
-                    char* * outbuf, size_t *outbytesleft)
  146
+size_t iconv_const (void* cd, const char** inbuf, size_t* inbytesleft,
  147
+                    char** outbuf, size_t* outbytesleft)
147 148
 {
148 149
     struct iconv_param_adapter {
149 150
         iconv_param_adapter(const char**p) : p(p) {}
@@ -163,8 +164,10 @@ size_t iconv_const (void* cd, const char** inbuf, size_t *inbytesleft,
163 164
 }
164 165
 
165 166
 template<class INPUT,class OUTPUT>
166  
-static bool convert_checked(iconv_t& type, int multiplier, const CStdString& strFromCharset, const CStdString& strToCharset, const INPUT& strSource, OUTPUT& strDest)
  167
+static bool convert(iconv_t& type, int multiplier, const std::string& strFromCharset, const std::string& strToCharset, const INPUT& strSource, OUTPUT& strDest, bool failOnInvalidChar = false)
167 168
 {
  169
+  strDest.clear();
  170
+
168 171
   if (type == (iconv_t)-1)
169 172
   {
170 173
     type = iconv_open(strToCharset.c_str(), strFromCharset.c_str());
@@ -176,31 +179,34 @@ static bool convert_checked(iconv_t& type, int multiplier, const CStdString& str
176 179
     }
177 180
   }
178 181
 
179  
-  if (strSource.IsEmpty())
180  
-  {
181  
-    strDest.clear(); //empty strings are easy
182  
-    return true;
183  
-  }
  182
+  if (strSource.empty())
  183
+    return true; //empty strings are easy
184 184
 
185 185
   //input buffer for iconv() is the buffer from strSource
186  
-  size_t      inBufSize  = (strSource.length() + 1) * sizeof(strSource[0]);
  186
+  size_t      inBufSize  = (strSource.length() + 1) * sizeof(typename INPUT::value_type);
187 187
   const char* inBuf      = (const char*)strSource.c_str();
188 188
 
189 189
   //allocate output buffer for iconv()
190  
-  size_t      outBufSize = (strSource.length() + 1) * multiplier;
  190
+  size_t      outBufSize = (strSource.length() + 1) * sizeof(typename OUTPUT::value_type) * multiplier;
191 191
   char*       outBuf     = (char*)malloc(outBufSize);
  192
+  if (outBuf == NULL)
  193
+  {
  194
+      CLog::Log(LOGSEVERE, "%s: malloc failed", __FUNCTION__);
  195
+      return false;
  196
+  }
192 197
 
193 198
   size_t      inBytesAvail  = inBufSize;  //how many bytes iconv() can read
194 199
   size_t      outBytesAvail = outBufSize; //how many bytes iconv() can write
195 200
   const char* inBufStart    = inBuf;      //where in our input buffer iconv() should start reading
196 201
   char*       outBufStart   = outBuf;     //where in out output buffer iconv() should start writing
197 202
 
  203
+  size_t returnV;
198 204
   while(1)
199 205
   {
200 206
     //iconv() will update inBufStart, inBytesAvail, outBufStart and outBytesAvail
201  
-    size_t returnV = iconv_const(type, &inBufStart, &inBytesAvail, &outBufStart, &outBytesAvail);
  207
+    returnV = iconv_const(type, &inBufStart, &inBytesAvail, &outBufStart, &outBytesAvail);
202 208
 
203  
-    if ((returnV == (size_t)-1) && (errno != EINVAL))
  209
+    if (returnV == (size_t)-1)
204 210
     {
205 211
       if (errno == E2BIG) //output buffer is not big enough
206 212
       {
@@ -212,10 +218,9 @@ static bool convert_checked(iconv_t& type, int multiplier, const CStdString& str
212 218
         char* newBuf  = (char*)realloc(outBuf, outBufSize);
213 219
         if (!newBuf)
214 220
         {
215  
-          CLog::Log(LOGERROR, "%s realloc failed with buffer=%p size=%zu errno=%d(%s)",
216  
-                    __FUNCTION__, outBuf, outBufSize, errno, strerror(errno));
217  
-          free(outBuf);
218  
-          return false;
  221
+          CLog::Log(LOGSEVERE, "%s realloc failed with errno=%d(%s)",
  222
+                    __FUNCTION__, errno, strerror(errno));
  223
+          break;
219 224
         }
220 225
         outBuf = newBuf;
221 226
 
@@ -224,79 +229,96 @@ static bool convert_checked(iconv_t& type, int multiplier, const CStdString& str
224 229
         outBytesAvail = outBufSize - bytesConverted;
225 230
 
226 231
         //continue in the loop and convert the rest
  232
+        continue;
227 233
       }
228 234
       else if (errno == EILSEQ) //An invalid multibyte sequence has been encountered in the input
229 235
       {
  236
+        if (failOnInvalidChar)
  237
+          break;
  238
+
230 239
         //skip invalid byte
231 240
         inBufStart++;
232 241
         inBytesAvail--;
233  
-
234 242
         //continue in the loop and convert the rest
  243
+        continue;
  244
+      }
  245
+      else if (errno == EINVAL) /* Invalid sequence at the end of input buffer */
  246
+      {
  247
+        if (!failOnInvalidChar)
  248
+          returnV = 0; /* reset error status to use converted part */
  249
+
  250
+        break;
235 251
       }
236 252
       else //iconv() had some other error
237 253
       {
238 254
         CLog::Log(LOGERROR, "%s iconv() failed from %s to %s, errno=%d(%s)",
239 255
                   __FUNCTION__, strFromCharset.c_str(), strToCharset.c_str(), errno, strerror(errno));
240  
-        free(outBuf);
241  
-        return false;
242 256
       }
243 257
     }
244  
-    else
245  
-    {
246  
-      //complete the conversion, otherwise the current data will prefix the data on the next call
247  
-      returnV = iconv_const(type, NULL, NULL, &outBufStart, &outBytesAvail);
248  
-      if (returnV == (size_t)-1)
249  
-        CLog::Log(LOGERROR, "%s failed cleanup errno=%d(%s)", __FUNCTION__, errno, strerror(errno));
250  
-
251  
-      //we're done
252  
-      break;
253  
-    }
  258
+    break;
254 259
   }
255 260
 
256  
-  size_t bytesWritten = outBufSize - outBytesAvail;
257  
-  char*  dest         = (char*)strDest.GetBuffer(bytesWritten);
  261
+  //complete the conversion (reset buffers), otherwise the current data will prefix the data on the next call
  262
+  if (iconv_const(type, NULL, NULL, &outBufStart, &outBytesAvail) == (size_t)-1)
  263
+    CLog::Log(LOGERROR, "%s failed cleanup errno=%d(%s)", __FUNCTION__, errno, strerror(errno));
258 264
 
259  
-  //copy the output from iconv() into the CStdString
260  
-  memcpy(dest, outBuf, bytesWritten);
  265
+  if (returnV == (size_t)-1)
  266
+  {
  267
+    free(outBuf);
  268
+    return false;
  269
+  }
  270
+  //we're done
  271
+
  272
+  const typename OUTPUT::size_type sizeInChars = (typename OUTPUT::size_type) (outBufSize - outBytesAvail) / sizeof(typename OUTPUT::value_type);
  273
+  typename OUTPUT::const_pointer strPtr = (typename OUTPUT::const_pointer) outBuf;
  274
+  /* Make sure that all buffer is assigned and string is stopped at end of buffer */
  275
+  if (strPtr[sizeInChars-1] == 0)
  276
+    strDest.assign(strPtr, sizeInChars-1);
  277
+  else
  278
+    strDest.assign(strPtr, sizeInChars);
261 279
 
262  
-  strDest.ReleaseBuffer();
263  
-  
264 280
   free(outBuf);
265 281
 
266 282
   return true;
267 283
 }
268 284
 
269  
-template<class INPUT,class OUTPUT>
270  
-static void convert(iconv_t& type, int multiplier, const CStdString& strFromCharset, const CStdString& strToCharset, const INPUT& strSource,  OUTPUT& strDest)
271  
-{
272  
-  if(!convert_checked(type, multiplier, strFromCharset, strToCharset, strSource, strDest))
273  
-    strDest = strSource;
274  
-}
275  
-
276 285
 using namespace std;
277 286
 
278  
-static void logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDest, FriBidiCharSet fribidiCharset, FriBidiCharType base = FRIBIDI_TYPE_LTR, bool* bWasFlipped =NULL)
  287
+static bool logicalToVisualBiDi(const std::string& stringSrc, std::string& stringDst, FriBidiCharSet fribidiCharset, FriBidiCharType base = FRIBIDI_TYPE_LTR, bool* bWasFlipped =NULL)
279 288
 {
280  
-  // libfribidi is not threadsafe, so make sure we make it so
281  
-  CSingleLock lock(m_critSection);
282  
-
283  
-  vector<CStdString> lines;
284  
-  CUtil::Tokenize(strSource, lines, "\n");
285  
-  CStdString resultString;
  289
+  stringDst.clear();
  290
+  vector<std::string> lines = StringUtils::Split(stringSrc, "\n");
286 291
 
287 292
   if (bWasFlipped)
288 293
     *bWasFlipped = false;
289 294
 
290  
-  for (unsigned int i = 0; i < lines.size(); i++)
  295
+  // libfribidi is not threadsafe, so make sure we make it so
  296
+  CSingleLock lock(m_critSection);
  297
+
  298
+  const size_t numLines = lines.size();
  299
+  for (size_t i = 0; i < numLines; i++)
291 300
   {
292 301
     int sourceLen = lines[i].length();
293 302
 
294 303
     // Convert from the selected charset to Unicode
295 304
     FriBidiChar* logical = (FriBidiChar*) malloc((sourceLen + 1) * sizeof(FriBidiChar));
  305
+    if (logical == NULL)
  306
+    {
  307
+      CLog::Log(LOGSEVERE, "%s: can't allocate memory", __FUNCTION__);
  308
+      return false;
  309
+    }
296 310
     int len = fribidi_charset_to_unicode(fribidiCharset, (char*) lines[i].c_str(), sourceLen, logical);
297 311
 
298 312
     FriBidiChar* visual = (FriBidiChar*) malloc((len + 1) * sizeof(FriBidiChar));
299 313
     FriBidiLevel* levels = (FriBidiLevel*) malloc((len + 1) * sizeof(FriBidiLevel));
  314
+    if (levels == NULL || visual == NULL)
  315
+    {
  316
+      free(logical);
  317
+      free(visual);
  318
+      free(levels);
  319
+      CLog::Log(LOGSEVERE, "%s: can't allocate memory", __FUNCTION__);
  320
+      return false;
  321
+    }
300 322
 
301 323
     if (fribidi_log2vis(logical, len, &base, visual, NULL, NULL, levels))
302 324
     {
@@ -306,14 +328,13 @@ static void logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDe
306 328
       // Apperently a string can get longer during this transformation
307 329
       // so make sure we allocate the maximum possible character utf8
308 330
       // can generate atleast, should cover all bases
309  
-      char *result = strDest.GetBuffer(len*4);
  331
+      char* result = new char[len*4];
310 332
 
311 333
       // Convert back from Unicode to the charset
312 334
       int len2 = fribidi_unicode_to_charset(fribidiCharset, visual, len, result);
313  
-      ASSERT(len2 <= len*4);
314  
-      strDest.ReleaseBuffer();
315  
-
316  
-      resultString += strDest;
  335
+      assert(len2 <= len*4);
  336
+      stringDst += result;
  337
+      delete[] result;
317 338
 
318 339
       // Check whether the string was flipped if one of the embedding levels is greater than 0
319 340
       if (bWasFlipped && !*bWasFlipped)
@@ -334,19 +355,19 @@ static void logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDe
334 355
     free(levels);
335 356
   }
336 357
 
337  
-  strDest = resultString;
  358
+  return true;
338 359
 }
339 360
 
340 361
 CCharsetConverter::CCharsetConverter()
341 362
 {
342 363
 }
343 364
 
344  
-void CCharsetConverter::OnSettingChanged(const CSetting *setting)
  365
+void CCharsetConverter::OnSettingChanged(const CSetting* setting)
345 366
 {
346 367
   if (setting == NULL)
347 368
     return;
348 369
 
349  
-  const std::string &settingId = setting->GetId();
  370
+  const std::string& settingId = setting->GetId();
350 371
   // TODO: does this make any sense at all for subtitles and karaoke?
351 372
   if (settingId == "subtitles.charset" ||
352 373
       settingId == "karaoke.charset" ||
@@ -358,42 +379,42 @@ void CCharsetConverter::clear()
358 379
 {
359 380
 }
360 381
 
361  
-vector<CStdString> CCharsetConverter::getCharsetLabels()
  382
+std::vector<std::string> CCharsetConverter::getCharsetLabels()
362 383
 {
363  
-  vector<CStdString> lab;
364  
-  for(SCharsetMapping * c = g_charsets; c->charset; c++)
  384
+  vector<std::string> lab;
  385
+  for(SCharsetMapping* c = g_charsets; c->charset; c++)
365 386
     lab.push_back(c->caption);
366 387
 
367 388
   return lab;
368 389
 }
369 390
 
370  
-CStdString CCharsetConverter::getCharsetLabelByName(const CStdString& charsetName)
  391
+std::string CCharsetConverter::getCharsetLabelByName(const std::string& charsetName)
371 392
 {
372  
-  for(SCharsetMapping * c = g_charsets; c->charset; c++)
  393
+  for(SCharsetMapping* c = g_charsets; c->charset; c++)
373 394
   {
374  
-    if (charsetName.Equals(c->charset))
  395
+    if (StringUtils::EqualsNoCase(charsetName,c->charset))
375 396
       return c->caption;
376 397
   }
377 398
 
378 399
   return "";
379 400
 }
380 401
 
381  
-CStdString CCharsetConverter::getCharsetNameByLabel(const CStdString& charsetLabel)
  402
+std::string CCharsetConverter::getCharsetNameByLabel(const std::string& charsetLabel)
382 403
 {
383  
-  for(SCharsetMapping *c = g_charsets; c->charset; c++)
  404
+  for(SCharsetMapping* c = g_charsets; c->charset; c++)
384 405
   {
385  
-    if (charsetLabel.Equals(c->caption))
  406
+    if (StringUtils::EqualsNoCase(charsetLabel, c->caption))
386 407
       return c->charset;
387 408
   }
388 409
 
389 410
   return "";
390 411
 }
391 412
 
392  
-bool CCharsetConverter::isBidiCharset(const CStdString& charset)
  413
+bool CCharsetConverter::isBidiCharset(const std::string& charset)
393 414
 {
394  
-  for(SFribidMapping *c = g_fribidi; c->charset; c++)
  415
+  for(SFribidMapping* c = g_fribidi; c->charset; c++)
395 416
   {
396  
-    if (charset.Equals(c->charset))
  417
+    if (StringUtils::EqualsNoCase(charset, c->charset))
397 418
       return true;
398 419
   }
399 420
   return false;
@@ -403,10 +424,8 @@ void CCharsetConverter::reset(void)
403 424
 {
404 425
   CSingleLock lock(m_critSection);
405 426
 
406  
-  ICONV_SAFE_CLOSE(m_iconvStringCharsetToFontCharset);
407 427
   ICONV_SAFE_CLOSE(m_iconvUtf8ToStringCharset);
408 428
   ICONV_SAFE_CLOSE(m_iconvStringCharsetToUtf8);
409  
-  ICONV_SAFE_CLOSE(m_iconvUcs2CharsetToStringCharset);
410 429
   ICONV_SAFE_CLOSE(m_iconvSubtitleCharsetToW);
411 430
   ICONV_SAFE_CLOSE(m_iconvWtoUtf8);
412 431
   ICONV_SAFE_CLOSE(m_iconvUtf16BEtoUtf8);
@@ -418,237 +437,188 @@ void CCharsetConverter::reset(void)
418 437
 
419 438
   m_stringFribidiCharset = FRIBIDI_NOTFOUND;
420 439
 
421  
-  CStdString strCharset=g_langInfo.GetGuiCharSet();
422  
-  for(SFribidMapping *c = g_fribidi; c->charset; c++)
  440
+  std::string strCharset=g_langInfo.GetGuiCharSet();
  441
+  for(SFribidMapping* c = g_fribidi; c->charset; c++)
423 442
   {
424  
-    if (strCharset.Equals(c->charset))
  443
+    if (StringUtils::EqualsNoCase(strCharset, c->charset))
  444
+    {
425 445
       m_stringFribidiCharset = c->name;
  446
+      break;
  447
+    }
426 448
   }
427 449
 }
428 450
 
429 451
 // The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
430 452
 // of the string is already made or the string is not displayed in the GUI
431  
-void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/, bool forceLTRReadingOrder /*=false*/, bool* bWasFlipped/*=NULL*/)
  453
+bool CCharsetConverter::utf8ToW(const std::string& utf8StringSrc, std::wstring& wStringDst, bool bVisualBiDiFlip /*= true*/, 
  454
+                                bool forceLTRReadingOrder /*= false*/, bool failOnBadChar /*= false*/, bool* bWasFlipped /*= NULL*/)
432 455
 {
433 456
   // Try to flip hebrew/arabic characters, if any
434 457
   if (bVisualBiDiFlip)
435 458
   {
436  
-    CStdStringA strFlipped;
  459
+    std::string strFlipped;
437 460
     FriBidiCharType charset = forceLTRReadingOrder ? FRIBIDI_TYPE_LTR : FRIBIDI_TYPE_PDF;
438  
-    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_UTF8, charset, bWasFlipped);
  461
+    logicalToVisualBiDi(utf8StringSrc, strFlipped, FRIBIDI_UTF8, charset, bWasFlipped);
439 462
     CSingleLock lock(m_critSection);
440  
-    convert(m_iconvUtf8toW,sizeof(wchar_t),UTF8_SOURCE,WCHAR_CHARSET,strFlipped,wString);
  463
+    return convert(m_iconvUtf8toW,1,UTF8_SOURCE,WCHAR_CHARSET,strFlipped,wStringDst, failOnBadChar);
441 464
   }
442 465
   else
443 466
   {
444 467
     CSingleLock lock(m_critSection);
445  
-    convert(m_iconvUtf8toW,sizeof(wchar_t),UTF8_SOURCE,WCHAR_CHARSET,utf8String,wString);
  468
+    return convert(m_iconvUtf8toW,1,UTF8_SOURCE,WCHAR_CHARSET,utf8StringSrc,wStringDst, failOnBadChar);
446 469
   }
447 470
 }
448 471
 
449  
-void CCharsetConverter::subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest)
  472
+bool CCharsetConverter::subtitleCharsetToW(const std::string& stringSrc, std::wstring& wStringDst)
450 473
 {
451 474
   // No need to flip hebrew/arabic as mplayer does the flipping
452 475
   CSingleLock lock(m_critSection);
453  
-  convert(m_iconvSubtitleCharsetToW,sizeof(wchar_t),g_langInfo.GetSubtitleCharSet(),WCHAR_CHARSET,strSource,strDest);
  476
+  return convert(m_iconvSubtitleCharsetToW,1,g_langInfo.GetSubtitleCharSet(),WCHAR_CHARSET,stringSrc,wStringDst);
454 477
 }
455 478
 
456  
-void CCharsetConverter::fromW(const CStdStringW& strSource,
457  
-                              CStdStringA& strDest, const CStdString& enc)
  479
+bool CCharsetConverter::fromW(const std::wstring& wStringSrc,
  480
+                              std::string& stringDst, const std::string& enc)
458 481
 {
459 482
   iconv_t iconvString;
460 483
   ICONV_PREPARE(iconvString);
461  
-  convert(iconvString,4,WCHAR_CHARSET,enc,strSource,strDest);
  484
+  const bool result = convert(iconvString,m_Utf8CharMaxSize,WCHAR_CHARSET,enc,wStringSrc,stringDst);
462 485
   iconv_close(iconvString);
  486
+  return result;
463 487
 }
464 488
 
465  
-void CCharsetConverter::toW(const CStdStringA& strSource,
466  
-                            CStdStringW& strDest, const CStdString& enc)
  489
+bool CCharsetConverter::toW(const std::string& stringSrc,
  490
+                            std::wstring& wStringDst, const std::string& enc)
467 491
 {
468 492
   iconv_t iconvString;
469 493
   ICONV_PREPARE(iconvString);
470  
-  convert(iconvString,sizeof(wchar_t),enc,WCHAR_CHARSET,strSource,strDest);
  494
+  const bool result = convert(iconvString,1,enc,WCHAR_CHARSET,stringSrc,wStringDst);
471 495
   iconv_close(iconvString);
  496
+  return result;
472 497
 }
473 498
 
474  
-void CCharsetConverter::utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest)
  499
+bool CCharsetConverter::utf8ToStringCharset(const std::string& utf8StringSrc, std::string& stringDst)
475 500
 {
476 501
   CSingleLock lock(m_critSection);
477  
-  convert(m_iconvUtf8ToStringCharset,1,UTF8_SOURCE,g_langInfo.GetGuiCharSet(),strSource,strDest);
  502
+  return convert(m_iconvUtf8ToStringCharset,1,UTF8_SOURCE,g_langInfo.GetGuiCharSet(),utf8StringSrc,stringDst);
478 503
 }
479 504
 
480  
-void CCharsetConverter::utf8ToStringCharset(CStdStringA& strSourceDest)
  505
+bool CCharsetConverter::utf8ToStringCharset(std::string& stringSrcDst)
481 506
 {
482  
-  CStdString strDest;
483  
-  utf8ToStringCharset(strSourceDest, strDest);
484  
-  strSourceDest=strDest;
  507
+  std::string strSrc(stringSrcDst);
  508
+  return utf8ToStringCharset(strSrc, stringSrcDst);
485 509
 }
486 510
 
487  
-void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest)
  511
+bool CCharsetConverter::ToUtf8(const std::string& strSourceCharset, const std::string& stringSrc, std::string& utf8StringDst)
488 512
 {
  513
+  if (strSourceCharset == "UTF-8")
  514
+  { // simple case - no conversion necessary
  515
+    utf8StringDst = stringSrc;
  516
+    return true;
  517
+  }
489 518
   iconv_t iconvString;
490 519
   ICONV_PREPARE(iconvString);
491  
-  convert(iconvString,UTF8_DEST_MULTIPLIER,strSourceCharset,"UTF-8",strSource,strDest);
  520
+  const bool result = convert(iconvString,m_Utf8CharMaxSize,strSourceCharset,"UTF-8",stringSrc,utf8StringDst);
492 521
   iconv_close(iconvString);
  522
+  return result;
493 523
 }
494 524
 
495  
-void CCharsetConverter::utf8To(const CStdStringA& strDestCharset, const CStdStringA& strSource, CStdStringA& strDest)
  525
+bool CCharsetConverter::utf8To(const std::string& strDestCharset, const std::string& utf8StringSrc, std::string& stringDst)
496 526
 {
497 527
   if (strDestCharset == "UTF-8")
498 528
   { // simple case - no conversion necessary
499  
-    strDest = strSource;
500  
-    return;
  529
+    stringDst = utf8StringSrc;
  530
+    return true;
501 531
   }
502 532
   iconv_t iconvString;
503 533
   ICONV_PREPARE(iconvString);
504  
-  convert(iconvString,UTF8_DEST_MULTIPLIER,UTF8_SOURCE,strDestCharset,strSource,strDest);
  534
+  const bool result = convert(iconvString,1,UTF8_SOURCE,strDestCharset,utf8StringSrc,stringDst);
505 535
   iconv_close(iconvString);
  536
+  return result;
506 537
 }
507 538
 
508  
-void CCharsetConverter::utf8To(const CStdStringA& strDestCharset, const CStdStringA& strSource, CStdString16& strDest)
  539
+bool CCharsetConverter::utf8To(const std::string& strDestCharset, const std::string& utf8StringSrc, std::u16string& utf16StringDst)
509 540
 {
510 541
   iconv_t iconvString;
511 542
   ICONV_PREPARE(iconvString);
512  
-  if(!convert_checked(iconvString,UTF8_DEST_MULTIPLIER,UTF8_SOURCE,strDestCharset,strSource,strDest))
513  
-    strDest.clear();
  543
+  const bool result = convert(iconvString,1,UTF8_SOURCE,strDestCharset,utf8StringSrc,utf16StringDst);
514 544
   iconv_close(iconvString);
  545
+  return result;
515 546
 }
516 547
 
517  
-void CCharsetConverter::utf8To(const CStdStringA& strDestCharset, const CStdStringA& strSource, CStdString32& strDest)
  548
+bool CCharsetConverter::utf8To(const std::string& strDestCharset, const std::string& utf8StringSrc, std::u32string& utf32StringDst)
518 549
 {
519 550
   iconv_t iconvString;
520 551
   ICONV_PREPARE(iconvString);
521  
-  if(!convert_checked(iconvString,UTF8_DEST_MULTIPLIER,UTF8_SOURCE,strDestCharset,strSource,strDest))
522  
-    strDest.clear();
  552
+  const bool result = convert(iconvString,1,UTF8_SOURCE,strDestCharset,utf8StringSrc,utf32StringDst);
523 553
   iconv_close(iconvString);
  554
+  return result;
524 555
 }
525 556
 
526  
-void CCharsetConverter::unknownToUTF8(CStdStringA &sourceAndDest)
  557
+bool CCharsetConverter::unknownToUTF8(std::string& stringSrcDst)
527 558
 {
528  
-  CStdString source = sourceAndDest;
529  
-  unknownToUTF8(source, sourceAndDest);
  559
+  std::string source(stringSrcDst);
  560
+  return unknownToUTF8(source, stringSrcDst);
530 561
 }
531 562
 
532  
-void CCharsetConverter::unknownToUTF8(const CStdStringA &source, CStdStringA &dest)
  563
+bool CCharsetConverter::unknownToUTF8(const std::string& stringSrc, std::string& utf8StringDst, bool failOnBadChar /*= false*/)
533 564
 {
534 565
   // checks whether it's utf8 already, and if not converts using the sourceCharset if given, else the string charset
535  
-  if (isValidUtf8(source))
536  
-    dest = source;
537  
-  else
  566
+  if (isValidUtf8(stringSrc))
538 567
   {
539  
-    CSingleLock lock(m_critSection);
540  
-    convert(m_iconvStringCharsetToUtf8, UTF8_DEST_MULTIPLIER, g_langInfo.GetGuiCharSet(), "UTF-8", source, dest);
  568
+    utf8StringDst = stringSrc;
  569
+    return true;
541 570
   }
542  
-}
543  
-
544  
-void CCharsetConverter::wToUTF8(const CStdStringW& strSource, CStdStringA &strDest)
545  
-{
546 571
   CSingleLock lock(m_critSection);
547  
-  convert(m_iconvWtoUtf8,UTF8_DEST_MULTIPLIER,WCHAR_CHARSET,"UTF-8",strSource,strDest);
  572
+  return convert(m_iconvStringCharsetToUtf8, m_Utf8CharMaxSize, g_langInfo.GetGuiCharSet(), "UTF-8", stringSrc, utf8StringDst, failOnBadChar);
548 573
 }
549 574
 
550  
-void CCharsetConverter::utf16BEtoUTF8(const CStdString16& strSource, CStdStringA &strDest)
  575
+bool CCharsetConverter::wToUTF8(const std::wstring& wStringSrc, std::string& utf8StringDst, bool failOnBadChar /*= false*/)
551 576
 {
552 577
   CSingleLock lock(m_critSection);
553  
-  if(!convert_checked(m_iconvUtf16BEtoUtf8,UTF8_DEST_MULTIPLIER,"UTF-16BE","UTF-8",strSource,strDest))
554  
-    strDest.clear();
  578
+  return convert(m_iconvWtoUtf8,m_Utf8CharMaxSize,WCHAR_CHARSET,"UTF-8",wStringSrc,utf8StringDst, failOnBadChar);
555 579
 }
556 580
 
557  
-void CCharsetConverter::utf16LEtoUTF8(const CStdString16& strSource,
558  
-                                      CStdStringA &strDest)
  581
+bool CCharsetConverter::utf16BEtoUTF8(const std::u16string& utf16StringSrc, std::string& utf8StringDst)
559 582
 {
560 583
   CSingleLock lock(m_critSection);
561  
-  if(!convert_checked(m_iconvUtf16LEtoUtf8,UTF8_DEST_MULTIPLIER,"UTF-16LE","UTF-8",strSource,strDest))
562  
-    strDest.clear();
  584
+  return convert(m_iconvUtf16BEtoUtf8,m_Utf8CharMaxSize,"UTF-16BE","UTF-8",utf16StringSrc,utf8StringDst);
563 585
 }
564 586
 
565  
-void CCharsetConverter::ucs2ToUTF8(const CStdString16& strSource, CStdStringA& strDest)
  587
+bool CCharsetConverter::utf16LEtoUTF8(const std::u16string& utf16StringSrc,
  588
+                                      std::string& utf8StringDst)
566 589
 {
567 590
   CSingleLock lock(m_critSection);
568  
-  if(!convert_checked(m_iconvUcs2CharsetToUtf8,UTF8_DEST_MULTIPLIER,"UCS-2LE","UTF-8",strSource,strDest))
569  
-    strDest.clear();
  591
+  return convert(m_iconvUtf16LEtoUtf8,m_Utf8CharMaxSize,"UTF-16LE","UTF-8",utf16StringSrc,utf8StringDst);
570 592
 }
571 593
 
572  
-void CCharsetConverter::utf16LEtoW(const CStdString16& strSource, CStdStringW &strDest)
  594
+bool CCharsetConverter::ucs2ToUTF8(const std::u16string& ucs2StringSrc, std::string& utf8StringDst)
573 595
 {
574 596
   CSingleLock lock(m_critSection);
575  
-  if(!convert_checked(m_iconvUtf16LEtoW,sizeof(wchar_t),"UTF-16LE",WCHAR_CHARSET,strSource,strDest))
576  
-    strDest.clear();
  597
+  return convert(m_iconvUcs2CharsetToUtf8,m_Utf8CharMaxSize,"UCS-2LE","UTF-8",ucs2StringSrc,utf8StringDst);
577 598
 }
578 599
 
579  
-void CCharsetConverter::ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap)
  600
+bool CCharsetConverter::utf16LEtoW(const std::u16string& utf16String, std::wstring& wString)
580 601
 {
581  
-  CStdStringW strCopy = strSource;
582  
-  if (swap)
583  
-  {
584  
-    char* s = (char*) strCopy.c_str();
585  
-
586  
-    while (*s || *(s + 1))
587  
-    {
588  
-      char c = *s;
589  
-      *s = *(s + 1);
590  
-      *(s + 1) = c;
591  
-
592  
-      s++;
593  
-      s++;
594  
-    }
595  
-  }
596 602
   CSingleLock lock(m_critSection);
597  
-  convert(m_iconvUcs2CharsetToStringCharset,4,"UTF-16LE",
598  
-          g_langInfo.GetGuiCharSet(),strCopy,strDest);
  603
+  return convert(m_iconvUtf16LEtoW,1,"UTF-16LE",WCHAR_CHARSET,utf16String,wString);
599 604
 }
600 605
 
601  
-void CCharsetConverter::utf32ToStringCharset(const unsigned long* strSource, CStdStringA& strDest)
  606
+bool CCharsetConverter::utf32ToStringCharset(const std::u32string& utf32StringSrc, std::string& stringDst)
602 607
 {
603 608
   CSingleLock lock(m_critSection);
604  
-
605  
-  if (m_iconvUtf32ToStringCharset == (iconv_t) - 1)
606  
-  {
607  
-    CStdString strCharset=g_langInfo.GetGuiCharSet();
608  
-    m_iconvUtf32ToStringCharset = iconv_open(strCharset.c_str(), "UTF-32LE");
609  
-  }
610  
-
611  
-  if (m_iconvUtf32ToStringCharset != (iconv_t) - 1)
612  
-  {
613  
-    const unsigned long* ptr=strSource;
614  
-    while (*ptr) ptr++;
615  
-    const char* src = (const char*) strSource;
616  
-    size_t inBytes = (ptr-strSource+1)*4;
617  
-
618  
-    char *dst = strDest.GetBuffer(inBytes);
619  
-    size_t outBytes = inBytes;
620  
-
621  
-    if (iconv_const(m_iconvUtf32ToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
622  
-    {
623  
-      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
624  
-      strDest.ReleaseBuffer();
625  
-      strDest = (const char *)strSource;
626  
-      return;
627  
-    }
628  
-
629  
-    if (iconv(m_iconvUtf32ToStringCharset, NULL, NULL, &dst, &outBytes) == (size_t)-1)
630  
-    {
631  
-      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
632  
-      strDest.ReleaseBuffer();
633  
-      strDest = (const char *)strSource;
634  
-      return;
635  
-    }
636  
-
637  
-    strDest.ReleaseBuffer();
638  
-  }
  609
+  return convert(m_iconvUtf32ToStringCharset, 1, g_langInfo.GetGuiCharSet().c_str(), "UTF-32", utf32StringSrc, stringDst);
639 610
 }
640 611
 
641  
-void CCharsetConverter::utf8ToSystem(CStdStringA& strSourceDest)
  612
+bool CCharsetConverter::utf8ToSystem(std::string& stringSrcDst, bool failOnBadChar /*= false*/)
642 613
 {
643  
-  CStdString strDest;
644  
-  g_charsetConverter.utf8To("", strSourceDest, strDest);
645  
-  strSourceDest = strDest;
  614
+  std::string strSrc(stringSrcDst);
  615
+  return utf8To("", strSrc, stringSrcDst);
646 616
 }
647 617
 
648 618
 // Taken from RFC2640
649  
-bool CCharsetConverter::isValidUtf8(const char *buf, unsigned int len)
  619
+bool CCharsetConverter::isValidUtf8(const char* buf, unsigned int len)
650 620
 {
651  
-  const unsigned char *endbuf = (unsigned char*)buf + len;
  621
+  const unsigned char* endbuf = (unsigned char*)buf + len;
652 622
   unsigned char byte2mask=0x00, c;
653 623
   int trailing=0; // trailing (continuation) bytes to follow
654 624
 
@@ -706,19 +676,19 @@ bool CCharsetConverter::isValidUtf8(const char *buf, unsigned int len)
706 676
   return trailing == 0;
707 677
 }
708 678
 
709  
-bool CCharsetConverter::isValidUtf8(const CStdString& str)
  679
+bool CCharsetConverter::isValidUtf8(const std::string& str)
710 680
 {
711 681
   return isValidUtf8(str.c_str(), str.size());
712 682
 }
713 683
 
714  
-void CCharsetConverter::utf8logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDest)
  684
+bool CCharsetConverter::utf8logicalToVisualBiDi(const std::string& utf8StringSrc, std::string& utf8StringDst)
715 685
 {
716  
-  logicalToVisualBiDi(strSource, strDest, FRIBIDI_UTF8, FRIBIDI_TYPE_RTL);
  686
+  return logicalToVisualBiDi(utf8StringSrc, utf8StringDst, FRIBIDI_UTF8, FRIBIDI_TYPE_RTL);
717 687
 }
718 688
 
719  
-void CCharsetConverter::SettingOptionsCharsetsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current)
  689
+void CCharsetConverter::SettingOptionsCharsetsFiller(const CSetting* setting, std::vector< std::pair<std::string, std::string> >& list, std::string& current)
720 690
 {
721  
-  vector<CStdString> vecCharsets = g_charsetConverter.getCharsetLabels();
  691
+  vector<std::string> vecCharsets = g_charsetConverter.getCharsetLabels();
722 692
   sort(vecCharsets.begin(), vecCharsets.end(), sortstringbyname());
723 693
 
724 694
   list.push_back(make_pair(g_localizeStrings.Get(13278), "DEFAULT")); // "Default"
67  xbmc/utils/CharsetConverter.h
@@ -24,8 +24,9 @@
24 24
 #include "settings/ISettingCallback.h"
25 25
 #include "threads/CriticalSection.h"
26 26
 #include "utils/GlobalsHandling.h"
27  
-#include "utils/StdString.h"
  27
+#include "utils/uXstrings.h"
28 28
 
  29
+#include <string>
29 30
 #include <vector>
30 31
 
31 32
 class CSetting;
@@ -35,60 +36,62 @@ class CCharsetConverter : public ISettingCallback
35 36
 public:
36 37
   CCharsetConverter();
37 38
 
38  
-  virtual void OnSettingChanged(const CSetting *setting);
  39
+  virtual void OnSettingChanged(const CSetting* setting);
39 40
 
40 41
   void reset();
41 42
 
42 43
   void clear();
43 44
 
44  
-  void utf8ToW(const CStdStringA& utf8String, CStdStringW &utf16String, bool bVisualBiDiFlip=true, bool forceLTRReadingOrder=false, bool* bWasFlipped=NULL);
  45
+  bool utf8ToW(const std::string& utf8StringSrc, std::wstring& wStringDst,
  46
+                bool bVisualBiDiFlip = true, bool forceLTRReadingOrder = false,
  47
+                bool failOnBadChar = false, bool* bWasFlipped = NULL);
45 48
 
46  
-  void utf16LEtoW(const CStdString16& utf16String, CStdStringW &wString);
  49
+  bool utf16LEtoW(const std::u16string& utf16String, std::wstring& wString);
47 50
 
48  
-  void subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest);
  51
+  bool subtitleCharsetToW(const std::string& stringSrc, std::wstring& wStringDst);
49 52
 
50  
-  void utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest);
  53
+  bool utf8ToStringCharset(const std::string& utf8StringSrc, std::string& stringDst);
51 54
 
52  
-  void utf8ToStringCharset(CStdStringA& strSourceDest);
53  
-  void utf8ToSystem(CStdStringA& strSourceDest);
  55
+  bool utf8ToStringCharset(std::string& stringSrcDst);
  56
+  bool utf8ToSystem(std::string& stringSrcDst, bool failOnBadChar = false);
54 57
 
55  
-  void utf8To(const CStdStringA& strDestCharset, const CStdStringA& strSource, CStdStringA& strDest);
56  
-  void utf8To(const CStdStringA& strDestCharset, const CStdStringA& strSource, CStdString16& strDest);
57  
-  void utf8To(const CStdStringA& strDestCharset, const CStdStringA& strSource, CStdString32& strDest);
  58
+  bool utf8To(const std::string& strDestCharset, const std::string& utf8StringSrc, std::string& stringDst);
  59
+  bool utf8To(const std::string& strDestCharset, const std::string& utf8StringSrc, std::u16string& utf16StringDst);
  60
+  bool utf8To(const std::string& strDestCharset, const std::string& utf8StringSrc, std::u32string& utf32StringDst);
58 61
 
59  
-  void stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest);
  62
+  bool ToUtf8(const std::string& strSourceCharset, const std::string& stringSrc, std::string& utf8StringDst);
60 63
 
61  
-  bool isValidUtf8(const CStdString& str);
  64
+  bool isValidUtf8(const std::string& str);
62 65
 
63  
-  bool isValidUtf8(const char *buf, unsigned int len);
  66
+  bool isValidUtf8(const char* buf, unsigned int len);
64 67
 
65  
-  void ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap = false);
  68
+  bool wToUTF8(const std::wstring& wStringSrc, std::string& utf8StringDst, bool failOnBadChar = false);
  69
+  bool utf16BEtoUTF8(const std::u16string& utf16StringSrc, std::string& utf8StringDst);
  70
+  bool utf16LEtoUTF8(const std::u16string& utf16StringSrc, std::string& utf8StringDst);
  71
+  bool ucs2ToUTF8(const std::u16string& ucs2StringSrc, std::string& utf8StringDst);
66 72
 
67  
-  void wToUTF8(const CStdStringW& strSource, CStdStringA &strDest);
68  
-  void utf16BEtoUTF8(const CStdString16& strSource, CStdStringA &strDest);
69  
-  void utf16LEtoUTF8(const CStdString16& strSource, CStdStringA &strDest);
70  
-  void ucs2ToUTF8(const CStdString16& strSource, CStdStringA& strDest);
  73
+  bool utf8logicalToVisualBiDi(const std::string& utf8StringSrc, std::string& utf8StringDst);
71 74
 
72  
-  void utf8logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDest);
  75
+  bool utf32ToStringCharset(const std::u32string& utf32StringSrc, std::string& stringDst);
73 76
 
74  
-  void utf32ToStringCharset(const unsigned long* strSource, CStdStringA& strDest);
  77
+  std::vector<std::string> getCharsetLabels();
  78
+  std::string getCharsetLabelByName(const std::string& charsetName);
  79
+  std::string getCharsetNameByLabel(const std::string& charsetLabel);
  80
+  bool isBidiCharset(const std::string& charset);
75 81
 
76  
-  std::vector<CStdString> getCharsetLabels();
77  
-  CStdString getCharsetLabelByName(const CStdString& charsetName);
78  
-  CStdString getCharsetNameByLabel(const CStdString& charsetLabel);
79  
-  bool isBidiCharset(const CStdString& charset);
  82
+  bool unknownToUTF8(std::string& stringSrcDst);
  83
+  bool unknownToUTF8(const std::string& stringSrc, std::string& utf8StringDst, bool failOnBadChar = false);
80 84
 
81  
-  void unknownToUTF8(CStdStringA &sourceDest);
82  
-  void unknownToUTF8(const CStdStringA &source, CStdStringA &dest);
  85
+  bool toW(const std::string& stringSrc, std::wstring& wStringDst, const std::string& enc);
  86
+  bool fromW(const std::wstring& wStringSrc, std::string& stringDst, const std::string& enc);
83 87
 
84  
-  void toW(const CStdStringA& source, CStdStringW& dest, const CStdStringA& enc);
85  
-  void fromW(const CStdStringW& source, CStdStringA& dest, const CStdStringA& enc);
86  
-
87  
-  static void SettingOptionsCharsetsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
  88
+  static void SettingOptionsCharsetsFiller(const CSetting* setting, std::vector< std::pair<std::string, std::string> >& list, std::string& current);
  89
+private:
  90
+  static const int m_Utf8CharMinSize, m_Utf8CharMaxSize;
88 91
 };
89 92
 
90 93
 XBMC_GLOBAL(CCharsetConverter,g_charsetConverter);
91 94
 
92  
-size_t iconv_const (void* cd, const char** inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
  95
+size_t iconv_const (void* cd, const char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft);
93 96
 
94 97
 #endif
2  xbmc/utils/RssReader.cpp
@@ -317,7 +317,7 @@ void CRssReader::fromRSSToUTF16(const CStdStringA& strSource, CStdStringW& strDe
317 317
 {
318 318
   CStdString flippedStrSource, strSourceUtf8;
319 319
 
320  
-  g_charsetConverter.stringCharsetToUtf8(m_encoding, strSource, strSourceUtf8);
  320
+  g_charsetConverter.ToUtf8(m_encoding, strSource, strSourceUtf8);
321 321
   if (m_rtlText)
322 322
     g_charsetConverter.utf8logicalToVisualBiDi(strSourceUtf8, flippedStrSource);
323 323
   else
2  xbmc/utils/StringUtils.cpp
@@ -341,7 +341,7 @@ CStdStringArray StringUtils::SplitString(const CStdString& input, const CStdStri
341 341
   return result;
342 342
 }
343 343
 
344  
-vector<string> StringUtils::Split(const CStdString& input, const CStdString& delimiter, unsigned int iMaxStrings /* = 0 */)
  344
+vector<string> StringUtils::Split(const std::string& input, const std::string& delimiter, unsigned int iMaxStrings /* = 0 */)
345 345
 {
346 346
   CStdStringArray result;
347 347
   SplitString(input, delimiter, result, iMaxStrings);
2  xbmc/utils/StringUtils.h
@@ -72,7 +72,7 @@ class StringUtils
72 72
   static CStdString Join(const std::vector<std::string> &strings, const CStdString& delimiter);
73 73
   static int SplitString(const CStdString& input, const CStdString& delimiter, CStdStringArray &results, unsigned int iMaxStrings = 0);
74 74
   static CStdStringArray SplitString(const CStdString& input, const CStdString& delimiter, unsigned int iMaxStrings = 0);
75  
-  static std::vector<std::string> Split(const CStdString& input, const CStdString& delimiter, unsigned int iMaxStrings = 0);
  75
+  static std::vector<std::string> Split(const std::string& input, const std::string& delimiter, unsigned int iMaxStrings = 0);
76 76
   static int FindNumber(const CStdString& strInput, const CStdString &strFind);
77 77
   static int64_t AlphaNumericCompare(const wchar_t *left, const wchar_t *right);
78 78
   static long TimeStringToSeconds(const CStdString &timeString);
2  xbmc/utils/Weather.cpp
@@ -306,7 +306,7 @@ void CWeatherJob::LoadLocalizedToken()
306 306
           if (strEncoding.IsEmpty()) // Is language file utf8?
307 307
             utf8Label=pChild->FirstChild()->Value();
308 308
           else
309  
-            g_charsetConverter.stringCharsetToUtf8(strEncoding, pChild->FirstChild()->Value(), utf8Label);
  309
+            g_charsetConverter.ToUtf8(strEncoding, pChild->FirstChild()->Value(), utf8Label);
310 310
 
311 311
           if (!utf8Label.IsEmpty())
312 312
             m_localizedTokens.insert(make_pair(utf8Label, id));
61  xbmc/utils/uXstrings.h
... ...
@@ -0,0 +1,61 @@
  1
+/*
  2
+ *      Copyright (C) 2013 Team XBMC
  3
+ *      http://xbmc.org
  4
+ *
  5
+ *  This Program is free software; you can redistribute it and/or modify
  6
+ *  it under the terms of the GNU General Public License as published by
  7
+ *  the Free Software Foundation; either version 2, or (at your option)
  8
+ *  any later version.
  9
+ *
  10
+ *  This Program is distributed in the hope that it will be useful,
  11
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13
+ *  GNU General Public License for more details.
  14
+ *
  15
+ *  You should have received a copy of the GNU General Public License
  16
+ *  along with XBMC; see the file COPYING.  If not, see
  17
+ *  <http://www.gnu.org/licenses/>.
  18
+ *
  19
+ */
  20
+
  21
+/** @file utils/uXstrings.h
  22
+ *  Declarations of std::u16string and std::u32string for systems without those declarations
  23
+ */
  24
+#pragma once
  25
+
  26
+#include <string>
  27
+
  28
+#ifndef TARGET_WINDOWS
  29
+#ifdef HAVE_CONFIG_H
  30
+#include "config.h"
  31
+#endif // HAVE_CONFIG_H
  32
+
  33
+#if !defined(HAVE_STD__U16STRING) || !defined(HAVE_STD__U32STRING) 
  34
+#if defined(HAVE_STDINT_H)
  35
+#include <stdint.h>
  36
+#elif defined(HAVE_INTTYPES_H)
  37
+#include <inttypes.h>
  38
+#endif // defined(HAVE_INTTYPES_H)
  39
+
  40
+#ifndef HAVE_STD__U16STRING
  41
+#ifndef HAVE_CHAR16_T
  42
+typedef uint_least16_t char16_t;
  43
+#endif // HAVE_CHAR16_T
  44
+namespace std
  45
+{
  46
+  typedef basic_string<char16_t> u16string;
  47
+}
  48
+#endif // HAVE_STD__U16STRING
  49
+
  50
+#ifndef HAVE_STD__U32STRING
  51
+#ifndef HAVE_CHAR32_T
  52
+typedef uint_least32_t char32_t;
  53
+#endif // HAVE_CHAR32_T
  54
+namespace std
  55
+{
  56
+  typedef basic_string<char32_t> u32string;
  57
+}
  58
+#endif // HAVE_STD__U32STRING
  59
+
  60
+#endif // !defined(HAVE_STD__U16STRING) || !defined(HAVE_STD__U32STRING) 
  61
+#endif // TARGET_WINDOWS

0 notes on commit ecce001

Please sign in to comment.
Something went wrong with that request. Please try again.