From 8df2bb8bd574ead9ff9a0e8ba610c1a2a044d027 Mon Sep 17 00:00:00 2001 From: hss Date: Sat, 20 Mar 2021 02:48:33 -0400 Subject: [PATCH] Use optionals more wisely in line-numbers --- src/highlighters.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 6309b0b7..45008d6a 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1107,14 +1107,13 @@ struct LineNumbersHighlighter : Highlighter throw runtime_error("separator length is limited to 10 bytes"); Optional 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 separator_cursor_str = separator_cursor ? separator_cursor->str() : Optional{}; + 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)