Improve escaped character parsing
This commit is contained in:
parent
63584525f2
commit
c4837ca9b0
@ -17,6 +17,25 @@ static bool iswhitespace(char& character) {
|
|||||||
static std::optional<char> get_escaped(std::string_view inspected) {
|
static std::optional<char> get_escaped(std::string_view inspected) {
|
||||||
if (inspected == "n")
|
if (inspected == "n")
|
||||||
return '\n';
|
return '\n';
|
||||||
|
if (inspected == "r")
|
||||||
|
return '\r';
|
||||||
|
if (inspected == "t")
|
||||||
|
return '\t';
|
||||||
|
if (inspected.size() <= 3) {
|
||||||
|
for (char c : inspected) {
|
||||||
|
std::cout << c << std::endl;
|
||||||
|
if (!std::isdigit(c))
|
||||||
|
return {};
|
||||||
|
if (std::stoi(std::string{ c }) > 8)
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
unsigned int x;
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::oct << inspected;
|
||||||
|
ss >> x;
|
||||||
|
|
||||||
|
return static_cast<char>(x);
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,15 +181,15 @@ namespace token {
|
|||||||
std::string escaped_content{};
|
std::string escaped_content{};
|
||||||
if ((i + 1) >= text_length) break;
|
if ((i + 1) >= text_length) break;
|
||||||
auto potential = get_escaped(escaped_content + text[++i]);
|
auto potential = get_escaped(escaped_content + text[++i]);
|
||||||
std::cout << "\"" << escaped_content << "\"" << std::endl;
|
|
||||||
while (potential.has_value() && (i + 1) < text_length) {
|
while (potential.has_value() && (i + 1) < text_length) {
|
||||||
escaped_content += text[i];
|
escaped_content += text[i];
|
||||||
std::cout << "\"" << escaped_content << "\"" << std::endl;
|
|
||||||
potential = get_escaped(escaped_content + text[++i]);
|
potential = get_escaped(escaped_content + text[++i]);
|
||||||
}
|
}
|
||||||
|
if (escaped_content.size() > 0) {
|
||||||
auto escaped = get_escaped(escaped_content);
|
auto escaped = get_escaped(escaped_content);
|
||||||
if (escaped.has_value())
|
if (escaped.has_value())
|
||||||
content += *escaped;
|
content += *escaped;
|
||||||
|
}
|
||||||
|
|
||||||
c = text[i];
|
c = text[i];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user