From 418792e491764cc0e11e86522d43835a3da82fa6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 13 Nov 2015 15:30:55 +0200 Subject: Add support for man formatting --- cli/parser.cxx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'cli/parser.cxx') diff --git a/cli/parser.cxx b/cli/parser.cxx index faac290..164a3c0 100644 --- a/cli/parser.cxx +++ b/cli/parser.cxx @@ -946,25 +946,34 @@ option_def (token& t) string parser:: doc_string (const char* l, size_t n) { - // Get rid of '"'. + // Get rid of '"', convert '\"' to just '"'. // string t1, t2, t3; char p ('\0'); for (size_t i (0); i < n; ++i) { - if (l[i] == '"' && p != '\\') + char c (l[i]); + + if (c == '"') + { + if (p == '\\') + { + t1[t1.size () - 1] = '"'; // Replace '\' with '"'. + p = c; + } continue; + } // We need to keep track of \\ escapings so we don't confuse // them with \", as in "\\". // - if (l[i] == '\\' && p == '\\') + if (c == '\\' && p == '\\') p = '\0'; else - p = l[i]; + p = c; - t1 += l[i]; + t1 += c; } // Get rid of leading and trailing spaces in each line. Also handle -- cgit v1.1