From ae8437d87e4fab1085b9d080aa17d76d82ad701a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Chocholat=C3=BD?= Date: Wed, 24 Jun 2026 10:23:44 +0200 Subject: [PATCH] nfa (fix): Properly format symbols when printed to DOT format --- src/nfa/nfa.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/nfa/nfa.cc b/src/nfa/nfa.cc index a352765a8..490a93a5f 100644 --- a/src/nfa/nfa.cc +++ b/src/nfa/nfa.cc @@ -477,29 +477,38 @@ bool Nfa::is_flat() const { return flat; } -std::string Nfa::print_to_dot(const bool decode_ascii_chars, const bool use_intervals, const int max_label_length, const Alphabet* alphabet) const { +std::string Nfa::print_to_dot( + const bool decode_ascii_chars, const bool use_intervals, const int max_label_length, + const Alphabet* alphabet) const { std::stringstream output; print_to_dot(output, decode_ascii_chars, use_intervals, max_label_length, alphabet); return output.str(); } -void Nfa::print_to_dot(std::ostream &output, const bool decode_ascii_chars, const bool use_intervals, const int max_label_length, const Alphabet* alphabet) const { +void Nfa::print_to_dot( + std::ostream& output, const bool decode_ascii_chars, const bool use_intervals, const int max_label_length, + const Alphabet* alphabet) const { auto to_ascii = [&](const Symbol symbol) -> std::string { // Translate only printable ASCII characters. if (symbol < 33 || symbol >= 127) { return "<" + std::to_string(symbol) + ">"; } switch (symbol) { - case '"': return "\\\""; - case '\\': return "\\\\"; - default: return { 1, static_cast(symbol) }; + case '"': + return "\\\""; + case '\\': + return "\\\\"; + default: + return std::string(1, static_cast(symbol)); } }; auto translate_symbol = [&](const Symbol symbol) -> std::string { switch (symbol) { - case EPSILON: return ""; - default: break; + case EPSILON: + return ""; + default: + break; } if (decode_ascii_chars) { return to_ascii(symbol);