cwidget 0.5.16
|
00001 // transcode.h -*-c++-*- 00002 // 00003 // Copyright (C) 2005 Daniel Burrows 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License as 00007 // published by the Free Software Foundation; either version 2 of 00008 // the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; see the file COPYING. If not, write to 00017 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 // Boston, MA 02111-1307, USA. 00019 00020 #ifndef TRANSCODE_H 00021 #define TRANSCODE_H 00022 00023 #include <string> 00024 00025 namespace cwidget 00026 { 00027 namespace util 00028 { 00040 bool transcode(const char *s, 00041 std::wstring &out, 00042 const char *encoding=NULL); 00043 00044 inline bool transcode(const std::string &s, 00045 std::wstring &out, 00046 const char *encoding=NULL) 00047 { 00048 return transcode(s.c_str(), out, encoding); 00049 } 00050 00056 extern std::wstring (*transcode_mbtow_err)(int error, 00057 const std::wstring &partial, 00058 const std::string &input); 00059 00072 std::wstring transcode(const std::string &s, 00073 const char *encoding=NULL, 00074 std::wstring (*errf)(int error, 00075 const std::wstring &partial, 00076 const std::string &input)=NULL); 00077 00090 std::wstring transcode(const char *s, 00091 const char *encoding=NULL, 00092 std::wstring (*errf)(int error, 00093 const std::wstring &partial, 00094 const std::string &input)=NULL); 00095 00096 // Note: would it be saner to express errors via exceptions? 00097 00109 bool transcode(const wchar_t *s, 00110 std::string &out, 00111 const char *encoding=NULL); 00112 00113 00114 inline bool transcode(const std::wstring &s, 00115 std::string &out, 00116 const char *encoding=NULL) 00117 { 00118 return transcode(s.c_str(), out, encoding); 00119 } 00120 00121 00127 extern std::string (*transcode_wtomb_err)(int error, 00128 const std::string &partial, 00129 const std::wstring &input); 00130 00143 std::string transcode(const std::wstring &s, 00144 const char *encoding=NULL, 00145 std::string (*errf)(int error, 00146 const std::string &partial, 00147 const std::wstring &input)=NULL); 00148 00161 std::string transcode(const wchar_t *s, 00162 const char *encoding=NULL, 00163 std::string (*errf)(int error, 00164 const std::string &partial, 00165 const std::wstring &input)=NULL); 00166 } 00167 } 00168 00169 #endif // TRANSCODE_H