From 4ed0fe15d139748784adb40841028b36704b2f4f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 22 Jan 2025 11:08:00 +0200 Subject: Treat CRLF as single delimiter when scanning lines with next_word() --- libbuild2/parser.cxx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'libbuild2/parser.cxx') diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 4242b96..cb1bccc 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -2385,9 +2385,16 @@ namespace build2 // size_t b (0), e (0); for (size_t m (0), n (text.size ()); - next_word (text, n, b, e, m, '\n', '\r'), b != n; - sloc.line++) + next_word (text, n, b, e, m, '\n', '\r'), b != n; ) { + // Treat consecutive \r\n (CRLF) as if they were a single + // delimiter. + // + if (b != 0 && text[b - 1] == '\r' && + e != n && text[e] == '\n' && + m != 2) + continue; + s.assign (text, b, e - b); if (!trim (s).empty ()) @@ -2401,6 +2408,8 @@ namespace build2 break; } } + + sloc.line++; } if (b == e) -- cgit v1.1