cwidget  0.5.17
transcode.h
1 // transcode.h -*-c++-*-
2 //
3 // Copyright (C) 2005 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of
8 // the License, or (at your option) 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 GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; see the file COPYING. If not, write to
17 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 // Boston, MA 02111-1307, USA.
19 
20 #ifndef TRANSCODE_H
21 #define TRANSCODE_H
22 
23 #include <string>
24 
25 namespace cwidget
26 {
27  namespace util
28  {
40  bool transcode(const char *s,
41  std::wstring &out,
42  const char *encoding=NULL);
43 
44  inline bool transcode(const std::string &s,
45  std::wstring &out,
46  const char *encoding=NULL)
47  {
48  return transcode(s.c_str(), out, encoding);
49  }
50 
56  extern std::wstring (*transcode_mbtow_err)(int error,
57  const std::wstring &partial,
58  const std::string &input);
59 
72  std::wstring transcode(const std::string &s,
73  const char *encoding=NULL,
74  std::wstring (*errf)(int error,
75  const std::wstring &partial,
76  const std::string &input)=NULL);
77 
90  std::wstring transcode(const char *s,
91  const char *encoding=NULL,
92  std::wstring (*errf)(int error,
93  const std::wstring &partial,
94  const std::string &input)=NULL);
95 
96  // Note: would it be saner to express errors via exceptions?
97 
109  bool transcode(const wchar_t *s,
110  std::string &out,
111  const char *encoding=NULL);
112 
113 
114  inline bool transcode(const std::wstring &s,
115  std::string &out,
116  const char *encoding=NULL)
117  {
118  return transcode(s.c_str(), out, encoding);
119  }
120 
121 
127  extern std::string (*transcode_wtomb_err)(int error,
128  const std::string &partial,
129  const std::wstring &input);
130 
143  std::string transcode(const std::wstring &s,
144  const char *encoding=NULL,
145  std::string (*errf)(int error,
146  const std::string &partial,
147  const std::wstring &input)=NULL);
148 
161  std::string transcode(const wchar_t *s,
162  const char *encoding=NULL,
163  std::string (*errf)(int error,
164  const std::string &partial,
165  const std::wstring &input)=NULL);
166  }
167 }
168 
169 #endif // TRANSCODE_H
std::wstring(* transcode_mbtow_err)(int error, const std::wstring &partial, const std::string &input)=default_mbtow_err
The error handler for converting multibyte strings to wide strings: it is passed a partially-decoded ...
Definition: transcode.cc:54
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
std::string(* transcode_wtomb_err)(int error, const std::string &partial, const std::wstring &input)=default_wtomb_err
The error handler for converting multibyte strings to wide strings: it is passed a partially-decoded ...
Definition: transcode.cc:50