1 #ifndef CCHARSET_CONVERTER
2 #define CCHARSET_CONVERTER
5 * Copyright (C) 2005-2008 Team XBMC
8 * This Program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This Program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with XBMC; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 * http://www.gnu.org/copyleft/gpl.html
25 #include "lib/libiconv/iconv.h"
26 #include "lib/libfribidi/fribidi.h"
27 #include "CriticalSection.h"
31 class CCharsetConverter
40 void utf8ToW(const CStdStringA& utf8String, CStdStringW &utf16String, bool bVisualBiDiFlip=true, bool* bWasFlipped=NULL);
42 void utf16LEtoW(const char* utf16String, CStdStringW &wString);
44 void subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest);
46 void utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest);
48 void utf8ToStringCharset(CStdStringA& strSourceDest);
50 void stringCharsetToUtf8(const CStdStringA& strSource, CStdStringA& strDest);
52 void stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest);
54 void stringCharsetToUtf8(CStdStringA& strSourceDest);
56 bool isValidUtf8(const CStdString& str);
58 bool isValidUtf8(const char *buf, unsigned int len);
60 void ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap = false);
62 void wToUTF8(const CStdStringW& strSource, CStdStringA &strDest);
63 void utf16BEtoUTF8(const CStdStringW& strSource, CStdStringA &strDest);
65 void utf32ToStringCharset(const unsigned long* strSource, CStdStringA& strDest);
67 std::vector<CStdString> getCharsetLabels();
68 CStdString& getCharsetLabelByName(const CStdString& charsetName);
69 CStdString& getCharsetNameByLabel(const CStdString& charsetLabel);
70 bool isBidiCharset(const CStdString& charset);
72 void logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDest, FriBidiCharSet fribidiCharset, FriBidiCharType base = FRIBIDI_TYPE_LTR, bool* bWasFlipped=NULL);
73 void logicalToVisualBiDi(const CStdStringA& strSource, CStdStringA& strDest, CStdStringA& charset, FriBidiCharType base = FRIBIDI_TYPE_LTR, bool* bWasFlipped=NULL);
76 std::vector<CStdString> m_vecCharsetNames;
77 std::vector<CStdString> m_vecCharsetLabels;
78 std::vector<CStdString> m_vecBidiCharsetNames;
79 std::vector<FriBidiCharSet> m_vecBidiCharsets;
81 iconv_t m_iconvStringCharsetToFontCharset;
82 iconv_t m_iconvSubtitleCharsetToW;
83 iconv_t m_iconvUtf8ToStringCharset;
84 iconv_t m_iconvStringCharsetToUtf8;
85 iconv_t m_iconvUcs2CharsetToStringCharset;
86 iconv_t m_iconvUtf32ToStringCharset;
87 iconv_t m_iconvWtoUtf8;
88 iconv_t m_iconvUtf16LEtoW;
89 iconv_t m_iconvUtf16BEtoUtf8;
90 iconv_t m_iconvUtf8toW;
92 FriBidiCharSet m_stringFribidiCharset;
95 CCriticalSection m_bidiSection;
98 extern CCharsetConverter g_charsetConverter;