Skip to content

Commit

Permalink
Revert: Use std::map for converting escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Oct 25, 2024
1 parent 527ccc7 commit a4380f0
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,38 @@ auto&& add_option(Option&& e, options_type&& ob)
}

const auto convert_escape_seq(std::string_view escape_seq) {
const std::map<std::string_view, std::string_view> escapeMap = {
{R"_(\;)_", ";"},
{R"_(\n)_", "\n"},
{R"_(\r)_", "\r"},
{R"_(\\)_", "\\"}
};

const auto it = escapeMap.find(escape_seq);
if (it != escapeMap.end()) {
return it->second;
std::string_view retVal;
if (escape_seq == R"_(\;)_") {
retVal = ";";
} else if (escape_seq == R"_(\n)_") {
retVal = "\n";
} else if (escape_seq == R"_(\r)_") {
retVal = "\r";
} else if (escape_seq == R"_(\\)_") {
retVal = "\\";
} else {
throw OptionParserException(std::string("Internal parser error: Unexpected escape sequence " + std::string(escape_seq)));
}

return retVal;
}


const auto convert_whitespace_escape_seq(std::string_view escape_seq) {
const std::map<std::string_view, std::string_view> escapeMap = {
{R"_(\ )_", " "},
{R"_(\t)_", "\t"},
{R"_(\f)_", "\f"},
{R"_(\v)_", "\v"}
};

const auto it = escapeMap.find(escape_seq);
if (it != escapeMap.end()) {
return it->second;
std::string_view retVal;
if (escape_seq == R"_(\ )_") {
retVal = " ";
} else if (escape_seq == R"_(\t)_") {
retVal = "\t";
} else if (escape_seq == R"_(\f)_") {
retVal = "\f";
} else if (escape_seq == R"_(\v)_") {
retVal = "\v";
} else {
throw OptionParserException(std::string("Internal parser error: Unexpected white space escape sequence " + std::string(escape_seq)));
}

return retVal;
}


Expand Down

0 comments on commit a4380f0

Please sign in to comment.