MCPcopy Index your code
hub / github.com/IBM/Project_CodeNet / normalize_newline

Function normalize_newline

tools/tokenizer/libtoken.c:296–316  ·  view source on GitHub ↗

Deal with DOS (\r \n) and classic Mac OS (\r) (physical) line endings. In case of CR LF skip (but count) the CR and return LF. In case of CR not followed by LF turns the CR into LF and returns that. All other chars are returned as is. Note: never returns a CR (\r). Line/column counts are not affected here. */

Source from the content-addressed store, hash-verified

294 Note: never returns a CR (\r). Line/column counts are not affected here.
295*/
296static int normalize_newline(void)
297{
298 /* No need to recognize Unicode code points here. */
299 int cc = getchar();
300
301 if (cc == '\r') {
302 // Maybe \r \n (CR NL) combination?
303 int nc = getchar();
304 if (nc == '\n') {
305 char_count++; // counts the carriage return
306 utf8_count++;
307 // No use incrementing column.
308 return nc; // return \n; effectively skipping the \r
309 }
310 // Mind nc not \n. ungetc(EOF) is Okay.
311 ungetc(nc, stdin);
312 // cc == '\r'; consider a newline as well, so turn into \n:
313 cc = '\n';
314 }
315 return cc;
316}
317
318/* Detects escaped newlines (line continuations) and signals them with the
319 special '\r' character (that otherwise is not used).

Callers 1

getFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected