Use optionals more wisely in line-numbers

This commit is contained in:
hss 2021-03-20 02:48:33 -04:00
parent f16783b0a8
commit 8df2bb8bd5

View File

@ -1107,14 +1107,13 @@ struct LineNumbersHighlighter : Highlighter
throw runtime_error("separator length is limited to 10 bytes");
Optional<StringView> separator_cursor = parser.get_switch("separator-cursor");
if (separator_cursor.value_or(separator).length() != separator.length()) {
if (separator_cursor && (*separator_cursor).length() != separator.length()) {
// Throw runtime error instead?
write_to_debug_buffer("line-numbers: Separator for active line should have the same length as seperator");
write_to_debug_buffer("number-lines: Separator for active line should have the same length as `separator`");
separator_cursor.reset();
}
// Effectively separator_cursor?.str(), except idk how to code in C++
Optional<String> separator_cursor_str = separator_cursor ? separator_cursor->str() : Optional<String>{};
auto separator_cursor_str = separator_cursor.map([](auto&& t){ return t.str(); });
int min_digits = parser.get_switch("min-digits").map(str_to_int).value_or(2);
if (min_digits < 0)