1 // sequence_conv.hh 2 // This file is part of libpbe; see http://anyterm.org/ 3 // (C) 2008 Philip Endecott 4 5 // Distributed under the Boost Software License, Version 1.0: 6 // 7 // Permission is hereby granted, free of charge, to any person or organization 8 // obtaining a copy of the software and accompanying documentation covered by 9 // this license (the "Software") to use, reproduce, display, distribute, 10 // execute, and transmit the Software, and to prepare derivative works of the 11 // Software, and to permit third-parties to whom the Software is furnished to 12 // do so, all subject to the following: 13 // 14 // The copyright notices in the Software and this entire statement, including 15 // the above license grant, this restriction and the following disclaimer, 16 // must be included in all copies of the Software, in whole or in part, and 17 // all derivative works of the Software, unless such copies or derivative 18 // works are solely in the form of machine-executable object code generated by 19 // a source language processor. 20 // 21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 // DEALINGS IN THE SOFTWARE. 28 29 #ifndef libpbe_charset_sequence_conv_hh 30 #define libpbe_charset_sequence_conv_hh 31 32 #include "charset_t.hh" 33 #include "charset_traits.hh" 34 #include "char_conv.hh" 35 #include "error_policy.hh" 36 37 38 namespace pbe { 39 40 // Conversion of strings between character sets 41 // ----------------------------------------------- 42 // 43 // This file provides facilites to convert sequences of characters, including 44 // strings and other sequences, from one character set to another. Essentially 45 // this just involves repeated application of the character-at-a-time 46 // char_conv template, and that is the default strategy implemented below. 47 // However for some iterators and some character set pairs, optimised 48 // implementations are possible and these can be provided by specialisation 49 // of sequence_conv. 50 51 // Base template, with default implementation using char_conv: 52 53 template< charset_t from_cs, charset_t to_cs, typename error_policy, 54 typename InputIterator, typename OutputIterator, typename Enable = void > 55 struct sequence_conv { 56 OutputIterator operator ()pbe::sequence_conv57 operator() ( InputIterator first, const InputIterator& last, 58 OutputIterator result, 59 typename charset_traits<from_cs>::state_t& from_state, 60 typename charset_traits<to_cs>::state_t& to_state) 61 { 62 for (; first != last; ++first) { 63 *(result++) = char_conv<from_cs,to_cs,error_policy>()(*first,from_state,to_state); 64 } 65 return result; 66 } 67 }; 68 69 70 71 72 }; 73 74 #endif 75