Пример #1
0
		Token parse_constant(StringIteratorT begin, StringIteratorT end, const StringT & constant) {
			StringIteratorT s = begin;
			StringIteratorT c = constant.begin();
			
			while (s != end && c != constant.end() && *c == *s) s++, c++;
			
			if (c == constant.end()) {
				return Token(begin, s);
			} else {
				return Token();
			}
		}
Пример #2
0
		StringT unescape_string (const StringT & value) {
			StringStreamT buffer;
			
			StringT::const_iterator i = value.begin(), end = value.end();
			
			// Skip enclosing quotes
			++i;
			--end;
			
			for (; i < end; ++i) {
				if (*i == '\\') {
					++i;
					
					switch (*i) {
						case 't':
							buffer << '\t';
							continue;
						case 'r':
							buffer << '\r';
							continue;
						case 'n':
							buffer << '\n';
							continue;
						case '\\':
							buffer << '\\';
							continue;
						case '"':
							buffer << '"';
							continue;
						case '\'':
							buffer << '\'';
							continue;
						case 'x':
							if ((end - i) >= 2) {
								StringT::value_type value = Math::convert_to_digit(*(++i)) << 4;
								value |= Math::convert_to_digit(*(++i));
								buffer << (StringT::value_type)value;
								continue;
							} else {
								break;
							}
						case '.':
							continue;
					}
					
					throw std::runtime_error("Could not parse string escape!");
				} else {
					buffer << *i;
				}
			}
		
			return buffer.str();
		}
Пример #3
0
		StringT escape_string (const StringT & value) {
			StringStreamT buffer;
			
			StringT::const_iterator i = value.begin(), end = value.end();
			buffer << '"';
			
			for (; i != end; ++i) {
				if (*i == '"') {
					buffer << "\\\"";
				} else {
					buffer << *i;
				}
			}
			
			buffer << '"';
			return buffer.str();
		}
Пример #4
0
 static bool matches(StringT const& str, std::basic_regex< CharT, ReTraitsT > const& expr, std::regex_constants::match_flag_type flags = std::regex_constants::match_default)
 {
     return std::regex_match(str.begin(), str.end(), expr, flags);
 }
Пример #5
0
 static bool matches(StringT const& str, compiled_type const& expr)
 {
     typedef typename StringT::const_iterator const_iterator;
     const_iterator it = str.begin(), end = str.end();
     return (spirit::qi::parse(it, end, expr) && it == end);
 }