Brian Silverman | 8867871 | 2018-08-04 23:56:48 -0700 | [diff] [blame^] | 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
| 2 | // codecvt_null.cpp |
| 3 | |
| 4 | // Copyright (c) 2004 Robert Ramey, Indiana University (garcia@osl.iu.edu) |
| 5 | // Andrew Lumsdaine, Indiana University (lums@osl.iu.edu). |
| 6 | // Use, modification and distribution is subject to the Boost Software |
| 7 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | // http://www.boost.org/LICENSE_1_0.txt) |
| 9 | |
| 10 | #define BOOST_WARCHIVE_SOURCE |
| 11 | #include <boost/serialization/config.hpp> |
| 12 | #include <boost/archive/codecvt_null.hpp> |
| 13 | |
| 14 | // codecvt implementation for passing wchar_t objects to char output |
| 15 | // without any translation whatever. Used to implement binary output |
| 16 | // of wchar_t objects. |
| 17 | |
| 18 | namespace boost { |
| 19 | namespace archive { |
| 20 | |
| 21 | std::codecvt_base::result |
| 22 | codecvt_null<wchar_t>::do_out( |
| 23 | std::mbstate_t & /*state*/, |
| 24 | const wchar_t * first1, |
| 25 | const wchar_t * last1, |
| 26 | const wchar_t * & next1, |
| 27 | char * first2, |
| 28 | char * last2, |
| 29 | char * & next2 |
| 30 | ) const { |
| 31 | while(first1 != last1){ |
| 32 | // Per std::22.2.1.5.2/2, we can store no more that |
| 33 | // last2-first2 characters. If we need to more encode |
| 34 | // next internal char type, return 'partial'. |
| 35 | if(static_cast<int>(sizeof(wchar_t)) > (last2 - first2)){ |
| 36 | next1 = first1; |
| 37 | next2 = first2; |
| 38 | return std::codecvt_base::partial; |
| 39 | } |
| 40 | * reinterpret_cast<wchar_t *>(first2) = * first1++; |
| 41 | first2 += sizeof(wchar_t); |
| 42 | |
| 43 | } |
| 44 | next1 = first1; |
| 45 | next2 = first2; |
| 46 | return std::codecvt_base::ok; |
| 47 | } |
| 48 | |
| 49 | std::codecvt_base::result |
| 50 | codecvt_null<wchar_t>::do_in( |
| 51 | std::mbstate_t & /*state*/, |
| 52 | const char * first1, |
| 53 | const char * last1, |
| 54 | const char * & next1, |
| 55 | wchar_t * first2, |
| 56 | wchar_t * last2, |
| 57 | wchar_t * & next2 |
| 58 | ) const { |
| 59 | // Process input characters until we've run of them, |
| 60 | // or the number of remaining characters is not |
| 61 | // enough to construct another output character, |
| 62 | // or we've run out of place for output characters. |
| 63 | while(first2 != last2){ |
| 64 | // Have we converted all input characters? |
| 65 | // Return with 'ok', if so. |
| 66 | if (first1 == last1) |
| 67 | break; |
| 68 | // Do we have less input characters than needed |
| 69 | // for a single output character? |
| 70 | if(static_cast<int>(sizeof(wchar_t)) > (last1 - first1)){ |
| 71 | next1 = first1; |
| 72 | next2 = first2; |
| 73 | return std::codecvt_base::partial; |
| 74 | } |
| 75 | *first2++ = * reinterpret_cast<const wchar_t *>(first1); |
| 76 | first1 += sizeof(wchar_t); |
| 77 | } |
| 78 | next1 = first1; |
| 79 | next2 = first2; |
| 80 | return std::codecvt_base::ok; |
| 81 | } |
| 82 | |
| 83 | } // namespace archive |
| 84 | } // namespace boost |