From 650ea3bd3bac1fa50f9c8566d5def774c5eb2fee Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 16 Jan 2016 12:28:50 +0200 Subject: Handle newline-only lines in documentation string parser --- cli/parser.cxx | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/cli/parser.cxx b/cli/parser.cxx index b63efcb..b10cb0e 100644 --- a/cli/parser.cxx +++ b/cli/parser.cxx @@ -1016,36 +1016,39 @@ doc_string (const char* l, size_t n) more = false; } - // In the pre mode we only remove up to m leading whitespaces. - // + if (b != e) // Unless this is just a single newline. { - size_t i (0); - while (b < e && - (t1[b] == 0x20 || t1[b] == 0x0D || t1[b] == 0x09) && - (!pre || i != m)) + // In the pre mode we only remove up to m leading whitespaces. + // { - ++b; - ++i; - } + size_t i (0); + while (b < e && + (t1[b] == 0x20 || t1[b] == 0x0D || t1[b] == 0x09) && + (!pre || i != m)) + { + ++b; + ++i; + } - if (!pre) - m = i; - } + if (!pre) + m = i; + } - --e; - while (e > b && (t1[e] == 0x20 || t1[e] == 0x0D || t1[e] == 0x09)) --e; + while (e > b && (t1[e] == 0x20 || t1[e] == 0x0D || t1[e] == 0x09)) + --e; - if (b == e && t1[b] == '\\') - { - // Use Start of Text (0x02) and End of Text (0x03) special - // characters as pre-formatted fragment markers. - // - pre = !pre; - t2 += (pre ? 0x02 : 0x03); + if (b == e && t1[b] == '\\') + { + // Use Start of Text (0x02) and End of Text (0x03) special + // characters as pre-formatted fragment markers. + // + pre = !pre; + t2 += (pre ? 0x02 : 0x03); + } + else if (b <= e) + t2.append (t1, b, e - b + 1); } - else if (b <= e) - t2.append (t1, b, e - b + 1); if (more) { -- cgit v1.1