Restrict cast types
This commit is contained in:
@ -76,4 +76,49 @@ namespace elna::boot
|
||||
return escape_invalid_char;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> escape_string(const char *escape)
|
||||
{
|
||||
std::string result;
|
||||
const char *current_position = escape + 1;
|
||||
|
||||
while (*current_position != '\0')
|
||||
{
|
||||
if (*current_position == '\\' && *(current_position + 1) == 'x')
|
||||
{
|
||||
current_position += 2;
|
||||
|
||||
std::size_t processed;
|
||||
char character = static_cast<char>(std::stoi(current_position, &processed, 16));
|
||||
if (processed == 0)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_position += processed - 1;
|
||||
result.push_back(character);
|
||||
}
|
||||
}
|
||||
else if (*current_position == '\\')
|
||||
{
|
||||
++current_position;
|
||||
|
||||
char escape = escape_char(*current_position);
|
||||
if (escape == escape_invalid_char)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
result.push_back(escape);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back(*current_position);
|
||||
}
|
||||
++current_position;
|
||||
}
|
||||
result.pop_back();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user