• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  test_codecvt.hpp  ------------------------------------------------------------------//
2 
3 //  Copyright Beman Dawes 2009, 2010
4 
5 //  Distributed under the Boost Software License, Version 1.0.
6 //  See http://www.boost.org/LICENSE_1_0.txt
7 
8 //  Library home page: http://www.boost.org/libs/filesystem
9 
10 #ifndef BOOST_FILESYSTEM3_TEST_CODECVT_HPP
11 #define BOOST_FILESYSTEM3_TEST_CODECVT_HPP
12 
13 #include <boost/filesystem/config.hpp>
14 #include <locale>
15 #include <cwchar>  // for mbstate_t
16 
17   //------------------------------------------------------------------------------------//
18   //                                                                                    //
19   //                              class test_codecvt                                    //
20   //                                                                                    //
21   //  Warning: partial implementation; even do_in and do_out only partially meet the    //
22   //  standard library specifications as the "to" buffer must hold the entire result.   //
23   //                                                                                    //
24   //  The value of a wide character is the value of the corresponding narrow character  //
25   //  plus 1. This ensures that compares against expected values will fail if the       //
26   //  code conversion did not occur as expected.                                        //
27   //                                                                                    //
28   //------------------------------------------------------------------------------------//
29 
30   class test_codecvt
31     : public std::codecvt< wchar_t, char, std::mbstate_t >
32   {
33   public:
test_codecvt()34     explicit test_codecvt()
35         : std::codecvt<wchar_t, char, std::mbstate_t>() {}
36   protected:
37 
do_always_noconv() const38     virtual bool do_always_noconv() const throw() { return false; }
39 
do_encoding() const40     virtual int do_encoding() const throw() { return 0; }
41 
do_in(std::mbstate_t &,const char * from,const char * from_end,const char * & from_next,wchar_t * to,wchar_t * to_end,wchar_t * & to_next) const42     virtual std::codecvt_base::result do_in(std::mbstate_t&,
43       const char* from, const char* from_end, const char*& from_next,
44       wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
45     {
46       for (; from != from_end && to != to_end; ++from, ++to)
47         *to = wchar_t(*from + 1);
48       if (to == to_end)
49         return error;
50       *to = L'\0';
51       from_next = from;
52       to_next = to;
53       return ok;
54    }
55 
do_out(std::mbstate_t &,const wchar_t * from,const wchar_t * from_end,const wchar_t * & from_next,char * to,char * to_end,char * & to_next) const56     virtual std::codecvt_base::result do_out(std::mbstate_t&,
57       const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
58       char* to, char* to_end, char*& to_next) const
59     {
60       for (; from != from_end && to != to_end; ++from, ++to)
61         *to = static_cast<char>(*from - 1);
62       if (to == to_end)
63         return error;
64       *to = '\0';
65       from_next = from;
66       to_next = to;
67       return ok;
68     }
69 
do_unshift(std::mbstate_t &,char *,char *,char * &) const70     virtual std::codecvt_base::result do_unshift(std::mbstate_t&,
71         char* /*from*/, char* /*to*/, char* & /*next*/) const  { return ok; }
72 
do_length(std::mbstate_t &,const char *,const char *,std::size_t) const73     virtual int do_length(std::mbstate_t&,
74       const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const  { return 0; }
75 
do_max_length() const76     virtual int do_max_length() const throw () { return 0; }
77   };
78 
79 #endif  // BOOST_FILESYSTEM3_TEST_CODECVT_HPP
80