[8cce80b4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2017 Jaroslav Jindrak
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #ifndef LIBCPP_INTERNAL_LOCALE_CODECVT
|
---|
| 30 | #define LIBCPP_INTERNAL_LOCALE_CODECVT
|
---|
| 31 |
|
---|
| 32 | #include <intetnal/locale.hpp>
|
---|
| 33 | #include <string>
|
---|
| 34 |
|
---|
| 35 | namespace std
|
---|
| 36 | {
|
---|
| 37 | /**
|
---|
| 38 | * 22.4.1.4, class template codecvt:
|
---|
| 39 | */
|
---|
| 40 |
|
---|
| 41 | class codecvt_base
|
---|
| 42 | {
|
---|
| 43 | public:
|
---|
| 44 | enum result
|
---|
| 45 | {
|
---|
| 46 | ok, partial, error, noconv
|
---|
| 47 | };
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | template<class Intern, class Extern, class State>
|
---|
| 51 | class codecvt: public codecvt_base
|
---|
| 52 | {
|
---|
| 53 | public:
|
---|
| 54 | using intern_type = Intern;
|
---|
| 55 | using extern_type = Extern;
|
---|
| 56 | using state_type = State;
|
---|
| 57 |
|
---|
| 58 | explicit codecvt(size_t = 0)
|
---|
| 59 | { /* DUMMY BODY */ }
|
---|
| 60 |
|
---|
| 61 | result out(state_type& state, const intern_type* from, const intern_type* from_end,
|
---|
| 62 | const intern_type*& from_next, extern_type* to, extern_type* to_end,
|
---|
| 63 | extern_type*& to_next) const
|
---|
| 64 | {
|
---|
| 65 | return do_out(state, from, from_end, from_next, to, to_end, to_next);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | result unshift(state_type& state, extern_type* to, extern_type* to_end,
|
---|
| 69 | extern_type*& to_next) const
|
---|
| 70 | {
|
---|
| 71 | return do_unshift(state, to, to_end, to_next);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | result in(state_type& state, const extern_type* from, const extern_type* from_end,
|
---|
| 75 | const extern_type*& from_next, intern_type* to, intern_type* to_end,
|
---|
| 76 | intern_type*& to_next) const
|
---|
| 77 | {
|
---|
| 78 | return do_in(state, from, from_end, from_next, to, to_end, to_next);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | int encoding() const noexcept
|
---|
| 82 | {
|
---|
| 83 | return do_encoding();
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | bool always_noconv() const noexcept
|
---|
| 87 | {
|
---|
| 88 | return do_always_noconv();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | int length(state_type& state, const extern_type* from, const extern_type* end,
|
---|
| 92 | size_t max) const
|
---|
| 93 | {
|
---|
| 94 | return do_length(state, from, end, max);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | int max_length() const noexcept
|
---|
| 98 | {
|
---|
| 99 | return do_max_length();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | static locale::id id;
|
---|
| 103 |
|
---|
| 104 | ~codecvt() = default;
|
---|
| 105 |
|
---|
| 106 | protected:
|
---|
| 107 | virtual result do_out(state_type& state, const intern_type* from, const intern_type* from_end,
|
---|
| 108 | const intern_type*& from_next, extern_type* to, extern_type* to_end,
|
---|
| 109 | extern_type*& to_next) const
|
---|
| 110 | {
|
---|
| 111 | // TODO: implement
|
---|
| 112 | return error;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | virtual result do_unshift(state_type& state, extern_type* to, extern_type* to_end,
|
---|
| 116 | extern_type*& to_next) const
|
---|
| 117 | {
|
---|
| 118 | // TODO: implement
|
---|
| 119 | return error;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | virtual result do_in(state_type& state, const extern_type* from, const extern_type* from_end,
|
---|
| 123 | const extern_type*& from_next, intern_type* to, intern_type* to_end,
|
---|
| 124 | intern_type*& to_next) const
|
---|
| 125 | {
|
---|
| 126 | // TODO: implement
|
---|
| 127 | return error;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | virtual int do_encoding() const noexcept
|
---|
| 131 | {
|
---|
| 132 | // TODO: implement
|
---|
| 133 | return 0;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | virtual bool do_always_noconv() const noexcept
|
---|
| 137 | {
|
---|
| 138 | // TODO: implement
|
---|
| 139 | return false;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | virtual int do_length(state_type& state, const extern_type* from, const extern_type* end,
|
---|
| 143 | size_t max) const
|
---|
| 144 | {
|
---|
| 145 | // TODO: implement
|
---|
| 146 | return 0;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | virtual int do_max_length() const noexcept
|
---|
| 150 | {
|
---|
| 151 | // TODO: implement
|
---|
| 152 | return 0;
|
---|
| 153 | }
|
---|
| 154 | };
|
---|
| 155 |
|
---|
| 156 | template<class Intern, class Extern, class State>
|
---|
| 157 | locale::id codecvt<Intern, Extern, State>::id{};
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * 22.4.1.5, class template codecvt_byname:
|
---|
| 161 | * Note: Dummy, TODO: implement.
|
---|
| 162 | */
|
---|
| 163 |
|
---|
| 164 | template<class Intern, class Extern, class State>
|
---|
| 165 | class codecvt_byname: public codecvt<Intern, Extern, State>
|
---|
| 166 | {
|
---|
| 167 | public:
|
---|
| 168 | explicit codecvt_byname(const char*, size_t = 0)
|
---|
| 169 | { /* DUMMY BODY */ }
|
---|
| 170 |
|
---|
| 171 | explicit codecvt_byname(const string&, size_t = 0)
|
---|
| 172 | { /* DUMMY BODY */ }
|
---|
| 173 |
|
---|
| 174 | ~codecvt_byname() = default;
|
---|
| 175 | };
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | #endif
|
---|