Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:17

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     Grammar for universal character validation (see C++ standard: Annex E)
0005 
0006     http://www.boost.org/
0007 
0008     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0009     Software License, Version 1.0. (See accompanying file
0010     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0011 =============================================================================*/
0012 #if !defined(BOOST_CONVERT_TRIGRAPHS_HK050403_INCLUDED)
0013 #define BOOST_CONVERT_TRIGRAPHS_HK050403_INCLUDED
0014 
0015 #include <boost/wave/wave_config.hpp>
0016 #include <boost/wave/cpplexer/cpplexer_exceptions.hpp>
0017 
0018 // this must occur after all of the includes and before any code appears
0019 #ifdef BOOST_HAS_ABI_HEADERS
0020 #include BOOST_ABI_PREFIX
0021 #endif
0022 
0023 ///////////////////////////////////////////////////////////////////////////////
0024 namespace boost {
0025 namespace wave {
0026 namespace cpplexer {
0027 namespace impl {
0028 
0029 ///////////////////////////////////////////////////////////////////////////////
0030 //
0031 //  Test, whether the given string represents a valid trigraph sequence
0032 //
0033 ///////////////////////////////////////////////////////////////////////////////
0034 template <typename StringT>
0035 inline bool
0036 is_trigraph(StringT const& trigraph)
0037 {
0038     if (trigraph.size() < 3 || '?' != trigraph[0] || '?' != trigraph[1])
0039         return false;
0040 
0041     switch (trigraph[2]) {
0042     case '\'': case '=': case '/': case '(':
0043     case ')':  case '<': case '>': case '!':
0044     case '-':
0045         break;
0046 
0047     default:
0048         return false;
0049     }
0050 
0051     return true;
0052 }
0053 
0054 ///////////////////////////////////////////////////////////////////////////////
0055 //
0056 //  convert_trigraph
0057 //
0058 //    The function convert_trigraph() converts a single trigraph character
0059 //    sequence into the corresponding character.
0060 //
0061 //    If the given character sequence doesn't form a valid trigraph sequence
0062 //    no conversion is performed.
0063 //
0064 ///////////////////////////////////////////////////////////////////////////////
0065 template <typename StringT>
0066 inline StringT
0067 convert_trigraph(StringT const &trigraph)
0068 {
0069 StringT result (trigraph);
0070 
0071     if (is_trigraph(trigraph)) {
0072         switch (trigraph[2]) {
0073         case '\'':  result = "^"; break;
0074         case '=':   result = "#"; break;
0075         case '/':   result = "\\"; break;
0076         case '(':   result = "["; break;
0077         case ')':   result = "]"; break;
0078         case '<':   result = "{"; break;
0079         case '>':   result = "}"; break;
0080         case '!':   result = "|"; break;
0081         case '-':   result = "~"; break;
0082         }
0083     }
0084     return result;
0085 }
0086 
0087 ///////////////////////////////////////////////////////////////////////////////
0088 //
0089 //  convert_trigraphs
0090 //
0091 //    The function convert_trigraph() converts all trigraphs in the given
0092 //    string into the corresponding characters.
0093 //
0094 //    If one of the given character sequences doesn't form a valid trigraph
0095 //    sequence no conversion is performed.
0096 //
0097 ///////////////////////////////////////////////////////////////////////////////
0098 template <typename StringT>
0099 inline StringT
0100 convert_trigraphs(StringT const &value)
0101 {
0102     StringT result;
0103     typename StringT::size_type pos = 0;
0104     typename StringT::size_type pos1 = value.find_first_of ("?", 0);
0105     if (StringT::npos != pos1) {
0106         do {
0107             result += value.substr(pos, pos1-pos);
0108             StringT trigraph (value.substr(pos1));
0109             if (is_trigraph(trigraph)) {
0110                 result += convert_trigraph(trigraph);
0111                 pos1 = value.find_first_of ("?", pos = pos1+3);
0112             }
0113             else {
0114                 result += value[pos1];
0115                 pos1 = value.find_first_of ("?", pos = pos1+1);
0116             }
0117         } while (StringT::npos != pos1);
0118         result += value.substr(pos);
0119     }
0120     else {
0121         result = value;
0122     }
0123     return result;
0124 }
0125 
0126 ///////////////////////////////////////////////////////////////////////////////
0127 }   // namespace impl
0128 }   // namespace cpplexer
0129 }   // namespace wave
0130 }   // namespace boost
0131 
0132 // the suffix header occurs after all of the code
0133 #ifdef BOOST_HAS_ABI_HEADERS
0134 #include BOOST_ABI_SUFFIX
0135 #endif
0136 
0137 #endif // !defined(BOOST_CONVERT_TRIGRAPHS_HK050403_INCLUDED)
0138 
0139