From affa61ff04bec7a9289443b37585c2ef3a959975 Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Sun, 2 May 2004 11:17:44 +0000 Subject: [PATCH] Merging patch by bz (from mozilla/htmlparser). ReadWhitespace should convert lone \r to \r\n so callers see it as a newline. Bug 103833, r=choess, sr=peterv git-svn-id: svn://10.0.0.236/trunk@155823 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/parser/htmlparser/src/nsScanner.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mozilla/parser/htmlparser/src/nsScanner.cpp b/mozilla/parser/htmlparser/src/nsScanner.cpp index bf63e2fb331..1e0430749d4 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.cpp +++ b/mozilla/parser/htmlparser/src/nsScanner.cpp @@ -936,19 +936,27 @@ nsresult nsScanner::ReadWhitespace(nsString& aString, while(!done && current != end) { switch(theChar) { case '\n': - case '\r': ++aNewlinesSkipped; - case ' ' : - case '\b': - case '\t': + case '\r': { + ++aNewlinesSkipped; PRUnichar thePrevChar = theChar; theChar = (++current != end) ? *current : '\0'; if ((thePrevChar == '\r' && theChar == '\n') || (thePrevChar == '\n' && theChar == '\r')) { theChar = (++current != end) ? *current : '\0'; // CRLF == LFCR => LF + } else if (thePrevChar == '\r') { + // Lone CR becomes CRLF; callers should know to remove extra CRs + AppendUnicodeTo(origin, current, aString); + aString.Append(PRUnichar('\n')); + origin = current; } } break; + case ' ' : + case '\b': + case '\t': + theChar = (++current != end) ? *current : '\0'; + break; default: done = PR_TRUE; AppendUnicodeTo(origin, current, aString); @@ -965,6 +973,8 @@ nsresult nsScanner::ReadWhitespace(nsString& aString, return result; } +//XXXbz callers of this have to manage their lone '\r' themselves if they want +//it to work. Good thing they're all in view-source and it deals. nsresult nsScanner::ReadWhitespace(nsScannerIterator& aStart, nsScannerIterator& aEnd, PRInt32& aNewlinesSkipped) {