From 7f21512826689df38678c4cb954e9c347c01df8b Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 5 Jun 2009 17:13:17 +0200 Subject: explicitly handle windows and mac9 line endings in practice, this matters only for backslashed line continuations Task-number: 255336 --- tools/linguist/shared/cpp.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/linguist/shared/cpp.cpp b/tools/linguist/shared/cpp.cpp index 2e137cf..0aab661 100644 --- a/tools/linguist/shared/cpp.cpp +++ b/tools/linguist/shared/cpp.cpp @@ -134,13 +134,28 @@ static uint getChar() if (yyInPos >= yyInStr.size()) return EOF; uint c = yyInStr[yyInPos++].unicode(); - if (c == '\\' && yyInPos < yyInStr.size() && yyInStr[yyInPos].unicode() == '\n') { - ++yyCurLineNo; - ++yyInPos; - continue; + if (c == '\\' && yyInPos < yyInStr.size()) { + if (yyInStr[yyInPos].unicode() == '\n') { + ++yyCurLineNo; + ++yyInPos; + continue; + } + if (yyInStr[yyInPos].unicode() == '\r') { + ++yyCurLineNo; + ++yyInPos; + if (yyInPos < yyInStr.size() && yyInStr[yyInPos].unicode() == '\n') + ++yyInPos; + continue; + } } - if (c == '\n') + if (c == '\r') { + if (yyInPos < yyInStr.size() && yyInStr[yyInPos].unicode() == '\n') + ++yyInPos; + c = '\n'; ++yyCurLineNo; + } else if (c == '\n') { + ++yyCurLineNo; + } return c; } } -- cgit v0.12