StatGraph: rename some variable and clean up code
[TortoiseGit.git] / src / ResText / codecvt.h
blobf19080664340970076ec5e4522d600e23bebd5d5
2 /** Several code conversions facets.
4 E.g. this is how to convert UCS-2 to UTF-8
6 @code
7 wifstream ifs("input", ios_base::binary);
8 wofstream ofs("output", ios_base::binary);
10 ifs.rdbuf()->pubimbue(locale(locale(), new ucs2_conversion()));
11 ofs.rbbuf()->pubimbue(locale(locale(), new utf8_conversion()));
12 ofs << ifs.rdbuf();
13 @endcode
15 @author Vladimir Prus <ghost@cs.msu.su>
17 @file
20 #include <locale>
21 #pragma warning(push)
22 #pragma warning(disable: 4511)
23 #pragma warning(disable: 4512)
25 /** Conversion facet that allows to use Unicode files in UCS-2 encoding */
26 class ucs2_conversion
27 : public std::codecvt<wchar_t, char, std::mbstate_t>
29 protected:
31 result do_in(std::mbstate_t& state,
32 const char* from, const char* from_end, const char*& from_next,
33 wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
35 result do_out(std::mbstate_t& state,
36 const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
37 char* to, char* to_limit, char*& to_next) const;
39 bool do_always_noconv() const throw() { return false; }
40 int do_encoding() const throw() { return 2; }
44 /** Conversion facet that allows to read Unicode files in UTF-8 encoding */
45 class utf8_conversion
46 : public std::codecvt<wchar_t, char, std::mbstate_t>
48 protected:
50 result do_in(std::mbstate_t& state,
51 const char* from, const char* from_end, const char*& from_next,
52 wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
54 result do_out(std::mbstate_t& state,
55 const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
56 char* to, char* to_limit, char*& to_next) const;
58 bool do_always_noconv() const throw() { return false; }
59 int do_encoding() const throw() { return 2; }
61 #pragma warning(pop)