File indexing completed on 2025-01-30 10:02:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
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
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
0057
0058
0059
0060
0061
0062
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
0090
0091
0092
0093
0094
0095
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 }
0128 }
0129 }
0130 }
0131
0132
0133 #ifdef BOOST_HAS_ABI_HEADERS
0134 #include BOOST_ABI_SUFFIX
0135 #endif
0136
0137 #endif
0138
0139