1
2
3
4
5
6 #include <sngxml/xpath/XPathTokenValueParsers.hpp>
7 #include <soulng/util/Unicode.hpp>
8
9 namespace sngxml { namespace xpath {
10
11 std::u32string ParseDQString(const std::string& fileName, const soulng::lexer::Token& token)
12 {
13 std::u32string s;
14 const char32_t* p = token.match.begin;
15 const char32_t* e = token.match.end;
16 if (p != e && *p == '"')
17 {
18 ++p;
19 }
20 while (p != e && *p != '"')
21 {
22 s.append(1, *p);
23 ++p;
24 }
25 if (p != e && *p == '"')
26 {
27 ++p;
28 }
29 if (p != e)
30 {
31 throw std::runtime_error("invalid string literal at " + fileName + ":" + std::to_string(token.line) + ": " + soulng::unicode::ToUtf8(token.match.ToString()));
32 }
33 return s;
34 }
35
36 std::u32string ParseSQString(const std::string& fileName, const soulng::lexer::Token& token)
37 {
38 std::u32string s;
39 const char32_t* p = token.match.begin;
40 const char32_t* e = token.match.end;
41 if (p != e && *p == '\'')
42 {
43 ++p;
44 }
45 while (p != e && *p != '\'')
46 {
47 s.append(1, *p);
48 ++p;
49 }
50 if (p != e && *p == '\'')
51 {
52 ++p;
53 }
54 if (p != e)
55 {
56 throw std::runtime_error("invalid string literal at " + fileName + ":" + std::to_string(token.line) + ": " + soulng::unicode::ToUtf8(token.match.ToString()));
57 }
58 return s;
59 }
60
61 } }