CUnicode.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef CUNICODE_H
00016 #define CUNICODE_H
00017 
00018 #include "CString.h"
00019 #include "BasicTypes.h"
00020 
00022 
00026 class CUnicode {
00027 public:
00029 
00030 
00032 
00036     static bool         isUTF8(const CString&);
00037 
00039 
00044     static CString      UTF8ToUCS2(const CString&, bool* errors = NULL);
00045 
00047 
00052     static CString      UTF8ToUCS4(const CString&, bool* errors = NULL);
00053 
00055 
00060     static CString      UTF8ToUTF16(const CString&, bool* errors = NULL);
00061 
00063 
00068     static CString      UTF8ToUTF32(const CString&, bool* errors = NULL);
00069 
00071 
00076     static CString      UTF8ToText(const CString&, bool* errors = NULL);
00077 
00079 
00083     static CString      UCS2ToUTF8(const CString&, bool* errors = NULL);
00084 
00086 
00090     static CString      UCS4ToUTF8(const CString&, bool* errors = NULL);
00091 
00093 
00097     static CString      UTF16ToUTF8(const CString&, bool* errors = NULL);
00098 
00100 
00104     static CString      UTF32ToUTF8(const CString&, bool* errors = NULL);
00105 
00107 
00111     static CString      textToUTF8(const CString&, bool* errors = NULL);
00112 
00114 
00115 private:
00116     // convert UTF8 to wchar_t string (using whatever encoding is native
00117     // to the platform).  caller must delete[] the returned string.  the
00118     // string is *not* nul terminated;  the length (in characters) is
00119     // returned in size.
00120     static wchar_t*     UTF8ToWideChar(const CString&,
00121                             UInt32& size, bool* errors);
00122 
00123     // convert nul terminated wchar_t string (in platform's native
00124     // encoding) to UTF8.
00125     static CString      wideCharToUTF8(const wchar_t*,
00126                             UInt32 size, bool* errors);
00127 
00128     // internal conversion to UTF8
00129     static CString      doUCS2ToUTF8(const UInt8* src, UInt32 n, bool* errors);
00130     static CString      doUCS4ToUTF8(const UInt8* src, UInt32 n, bool* errors);
00131     static CString      doUTF16ToUTF8(const UInt8* src, UInt32 n, bool* errors);
00132     static CString      doUTF32ToUTF8(const UInt8* src, UInt32 n, bool* errors);
00133 
00134     // convert characters to/from UTF8
00135     static UInt32       fromUTF8(const UInt8*& src, UInt32& size);
00136     static void         toUTF8(CString& dst, UInt32 c, bool* errors);
00137 
00138 private:
00139     static UInt32       s_invalid;
00140     static UInt32       s_replacement;
00141 };
00142 
00143 #endif

Generated on Fri Nov 6 00:18:45 2009 for synergy-plus by  doxygen 1.4.7