@@ -196,33 +196,51 @@ static void skipString(const char *&First, const char *const End) {
196
196
++First; // Finish off the string.
197
197
}
198
198
199
- static void skipNewline (const char *&First, const char *End) {
200
- assert (isVerticalWhitespace (*First));
201
- ++First;
199
+ // Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n)
200
+ static unsigned isEOL (const char *First, const char *const End) {
202
201
if (First == End)
203
- return ;
202
+ return 0 ;
203
+ if (End - First > 1 && isVerticalWhitespace (First[0 ]) &&
204
+ isVerticalWhitespace (First[1 ]) && First[0 ] != First[1 ])
205
+ return 2 ;
206
+ return !!isVerticalWhitespace (First[0 ]);
207
+ }
204
208
205
- // Check for "\n\r" and "\r\n".
206
- if (LLVM_UNLIKELY (isVerticalWhitespace (*First) && First[-1 ] != First[0 ]))
207
- ++First;
209
+ // Returns the length of the skipped newline
210
+ static unsigned skipNewline (const char *&First, const char *End) {
211
+ if (First == End)
212
+ return 0 ;
213
+ assert (isVerticalWhitespace (*First));
214
+ unsigned Len = isEOL (First, End);
215
+ assert (Len && " expected newline" );
216
+ First += Len;
217
+ return Len;
218
+ }
219
+
220
+ static bool wasLineContinuation (const char *First, unsigned EOLLen) {
221
+ return *(First - (int )EOLLen - 1 ) == ' \\ ' ;
208
222
}
209
223
210
224
static void skipToNewlineRaw (const char *&First, const char *const End) {
211
225
for (;;) {
212
226
if (First == End)
213
227
return ;
214
228
215
- if (isVerticalWhitespace (*First))
229
+ unsigned Len = isEOL (First, End);
230
+ if (Len)
216
231
return ;
217
232
218
- while (! isVerticalWhitespace (*First))
233
+ do {
219
234
if (++First == End)
220
235
return ;
236
+ Len = isEOL (First, End);
237
+ } while (!Len);
221
238
222
239
if (First[-1 ] != ' \\ ' )
223
240
return ;
224
241
225
- ++First; // Keep going...
242
+ First += Len;
243
+ // Keep skipping lines...
226
244
}
227
245
}
228
246
@@ -277,7 +295,7 @@ static bool isQuoteCppDigitSeparator(const char *const Start,
277
295
}
278
296
279
297
static void skipLine (const char *&First, const char *const End) {
280
- do {
298
+ for (;;) {
281
299
assert (First <= End);
282
300
if (First == End)
283
301
return ;
@@ -322,9 +340,10 @@ static void skipLine(const char *&First, const char *const End) {
322
340
return ;
323
341
324
342
// Skip over the newline.
325
- assert (isVerticalWhitespace (*First));
326
- skipNewline (First, End);
327
- } while (First[-2 ] == ' \\ ' ); // Continue past line-continuations.
343
+ unsigned Len = skipNewline (First, End);
344
+ if (!wasLineContinuation (First, Len)) // Continue past line-continuations.
345
+ break ;
346
+ }
328
347
}
329
348
330
349
static void skipDirective (StringRef Name, const char *&First,
@@ -379,6 +398,8 @@ void Minimizer::printToNewline(const char *&First, const char *const End) {
379
398
// Print out the string.
380
399
if (Last == End || Last == First || Last[-1 ] != ' \\ ' ) {
381
400
append (First, reverseOverSpaces (First, Last));
401
+ First = Last;
402
+ skipNewline (First, End);
382
403
return ;
383
404
}
384
405
0 commit comments