Ejemplo n.º 1
0
 inline StringT
 unescape_lit(StringT const &value)
 {
     StringT result;
     typename StringT::size_type pos = 0;
     typename StringT::size_type pos1 = value.find_first_of ("\\", 0);
     if (StringT::npos != pos1) {
         do {
             if ('\\' == value[pos1+1] || '\"' == value[pos1+1] || 
                 '?' == value[pos1+1])
             {
                 result = result + value.substr(pos, pos1-pos);
                 pos1 = value.find_first_of ("\\", (pos = pos1+1)+1);
             }
             else {
                 result = result + value.substr(pos, pos1-pos+1);
                 pos1 = value.find_first_of ("\\", pos = pos1+1);
             }
             
         } while (pos1 != StringT::npos);
         result = result + value.substr(pos);
     }
     else {
     // the string doesn't contain any escaped character sequences
         result = value;
     }
     return result;
 }
Ejemplo n.º 2
0
inline StringT
convert_trigraphs(StringT const &value)
{
    StringT result;
    typename StringT::size_type pos = 0;
    typename StringT::size_type pos1 = value.find_first_of ("?", 0);
    if (StringT::npos != pos1) {
        do {
            result += value.substr(pos, pos1-pos);
            StringT trigraph (value.substr(pos1)); 
            if (is_trigraph(trigraph)) {
                result += convert_trigraph(trigraph);
                pos1 = value.find_first_of ("?", pos = pos1+3);
            }
            else {
                result += value[pos1];
                pos1 = value.find_first_of ("?", pos = pos1+1);
            }
        } while (StringT::npos != pos1);
        result += value.substr(pos);
    }
    else {
        result = value;
    }
    return result;
}
 inline bool
 is_escaped_lit(StringT const &value)
 {
     typename StringT::size_type pos = value.find_first_of ("\\", 0);
     if (StringT::npos != pos) {
         do {
             if ('\\' == value[pos+1] || 
                 '\"' == value[pos+1] || 
                 '?' == value[pos+1])
             {
                 return true;
             }
             else {
                 pos = value.find_first_of ("\\", pos+1);
             }
         } while (pos != StringT::npos);
     }
     return false;
 }
Ejemplo n.º 4
0
 inline StringT
 escape_lit(StringT const &value)
 {
     StringT result;
     typename StringT::size_type pos = 0;
     typename StringT::size_type pos1 = value.find_first_of ("\"\\?", 0);
     if (StringT::npos != pos1) {
         do {
             result += value.substr(pos, pos1-pos) 
                         + StringT("\\") 
                         + StringT(1, value[pos1]);
             pos1 = value.find_first_of ("\"\\?", pos = pos1+1);
         } while (StringT::npos != pos1);
         result += value.substr(pos);
     }
     else {
         result = value;
     }
     return result;
 }
inline void
validate_identifier_name (StringT const &name, std::size_t line,
    std::size_t column, StringT const &file_name)
{
    using namespace std;    // some systems have strtoul in namespace std::

typename StringT::size_type pos = name.find_first_of('\\');

    while (StringT::npos != pos) {
    // the identifier name contains a backslash (must be universal char)
        BOOST_ASSERT('u' == name[pos+1] || 'U' == name[pos+1]);

    StringT uchar_val(name.substr(pos+2, ('u' == name[pos+1]) ? 4 : 8));
    universal_char_type type =
        classify_universal_char(strtoul(uchar_val.c_str(), 0, 16));

        if (universal_char_type_valid != type) {
        // an invalid char was found, so throw an exception
        StringT error_uchar(name.substr(pos, ('u' == name[pos+1]) ? 6 : 10));

            if (universal_char_type_invalid == type) {
                BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_invalid,
                    error_uchar, line, column, file_name.c_str());
            }
            else if (universal_char_type_base_charset == type) {
                BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_base_charset,
                    error_uchar, line, column, file_name.c_str());
            }
            else {
                BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_not_allowed,
                    error_uchar, line, column, file_name.c_str());
            }
        }

    // find next universal char (if appropriate)
        pos = name.find_first_of('\\', pos+2);
    }
}
Ejemplo n.º 6
0
 inline StringT
 unescape_lit(StringT const &value)
 {
     StringT result;
     typename StringT::size_type pos = 0;
     typename StringT::size_type pos1 = value.find_first_of ("\\", 0);
     if (StringT::npos != pos1) {
         do {
             switch (value[pos1+1]) {
             case '\\':
             case '\"':
             case '?':
                 result = result + value.substr(pos, pos1-pos);
                 pos1 = value.find_first_of ("\\", (pos = pos1+1)+1);
                 break;
                 
             case 'n':
                 result = result + value.substr(pos, pos1-pos) + "\n";
                 pos1 = value.find_first_of ("\\", pos = pos1+1);
                 ++pos;
                 break;
                 
             default:
                 result = result + value.substr(pos, pos1-pos+1);
                 pos1 = value.find_first_of ("\\", pos = pos1+1);
             }
             
         } while (pos1 != StringT::npos);
         result = result + value.substr(pos);
     }
     else {
     // the string doesn't contain any escaped character sequences
         result = value;
     }
     return result;
 }
Ejemplo n.º 7
0
void CheckFind()
{
    StringT E = "";
    StringT X = "x";
    StringT Y = "y";
    StringT S = "xxx";

    EXPECT_EQ(E.find(E),                                0u);
    EXPECT_EQ(S.find(E),                                0u);
    EXPECT_EQ(E.find(E, 2),                             StringT::npos);
    EXPECT_EQ(S.find(E, 2),                             2u);
    EXPECT_EQ(E.find(E, 8),                             StringT::npos);
    EXPECT_EQ(S.find(E, 8),                             StringT::npos);
    EXPECT_EQ(E.find(E, StringT::npos),                 StringT::npos);
    EXPECT_EQ(S.find(E, StringT::npos),                 StringT::npos);

    EXPECT_EQ(E.find_first_of(E),                       StringT::npos);
    EXPECT_EQ(S.find_first_of(E),                       StringT::npos);
    EXPECT_EQ(E.find_first_of(E, 2),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(E, 2),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(E, 8),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(E, 8),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(E, StringT::npos),        StringT::npos);
    EXPECT_EQ(S.find_first_of(E, StringT::npos),        StringT::npos);
    EXPECT_EQ(E.find_first_of(X),                       StringT::npos);
    EXPECT_EQ(S.find_first_of(X),                       0u);
    EXPECT_EQ(E.find_first_of(X, 2),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(X, 2),                    2u);
    EXPECT_EQ(E.find_first_of(X, 8),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(X, 8),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(X, StringT::npos),        StringT::npos);
    EXPECT_EQ(S.find_first_of(X, StringT::npos),        StringT::npos);
    EXPECT_EQ(E.find_first_of(Y, 2),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(Y, 2),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(Y, 8),                    StringT::npos);
    EXPECT_EQ(S.find_first_of(Y, 8),                    StringT::npos);
    EXPECT_EQ(E.find_first_of(Y, StringT::npos),        StringT::npos);
    EXPECT_EQ(S.find_first_of(Y, StringT::npos),        StringT::npos);

    EXPECT_EQ(E.find_first_not_of(E),                   StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E),                   0u);
    EXPECT_EQ(E.find_first_not_of(E, 2),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E, 2),                2u);
    EXPECT_EQ(E.find_first_not_of(E, 8),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E, 8),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(E, StringT::npos),    StringT::npos);
    EXPECT_EQ(S.find_first_not_of(E, StringT::npos),    StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X),                   StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X),                   StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X, 2),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X, 2),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X, 8),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X, 8),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(X, StringT::npos),    StringT::npos);
    EXPECT_EQ(S.find_first_not_of(X, StringT::npos),    StringT::npos);
    EXPECT_EQ(E.find_first_not_of(Y, 2),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(Y, 2),                2u);
    EXPECT_EQ(E.find_first_not_of(Y, 8),                StringT::npos);
    EXPECT_EQ(S.find_first_not_of(Y, 8),                StringT::npos);
    EXPECT_EQ(E.find_first_not_of(Y, StringT::npos),    StringT::npos);
    EXPECT_EQ(S.find_first_not_of(Y, StringT::npos),    StringT::npos);

    EXPECT_EQ(E.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(S.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(E.find_last_of(E, 2),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(E, 2),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(E, 8),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(E, 8),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(E, 0),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(E, 0),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(S.find_last_of(E),                        StringT::npos);
    EXPECT_EQ(E.find_last_of(X, 2),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(X, 2),                     2u);
    EXPECT_EQ(E.find_last_of(X, 8),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(X, 8),                     2u);
    EXPECT_EQ(E.find_last_of(X, 0),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(X, 0),                     0u);
    EXPECT_EQ(E.find_last_of(Y, 2),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(Y, 2),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(Y, 8),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(Y, 8),                     StringT::npos);
    EXPECT_EQ(E.find_last_of(Y, 0),                     StringT::npos);
    EXPECT_EQ(S.find_last_of(Y, 0),                     StringT::npos);

    EXPECT_EQ(E.find_last_not_of(E),                    StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E),                    2u);
    EXPECT_EQ(E.find_last_not_of(E, 2),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E, 2),                 2u);
    EXPECT_EQ(E.find_last_not_of(E, 8),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E, 8),                 2u);
    EXPECT_EQ(E.find_last_not_of(E, 0),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E, 0),                 0u);
    EXPECT_EQ(E.find_last_not_of(E),                    StringT::npos);
    EXPECT_EQ(S.find_last_not_of(E),                    2u);
    EXPECT_EQ(E.find_last_not_of(X, 2),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(X, 2),                 StringT::npos);
    EXPECT_EQ(E.find_last_not_of(X, 8),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(X, 8),                 StringT::npos);
    EXPECT_EQ(E.find_last_not_of(X, 0),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(X, 0),                 StringT::npos);
    EXPECT_EQ(E.find_last_not_of(Y, 2),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(Y, 2),                 2u);
    EXPECT_EQ(E.find_last_not_of(Y, 8),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(Y, 8),                 2u);
    EXPECT_EQ(E.find_last_not_of(Y, 0),                 StringT::npos);
    EXPECT_EQ(S.find_last_not_of(Y, 0),                 0u);
}