MCPcopy Create free account
hub / github.com/IBM/Project_CodeNet / normalize_newline

Function normalize_newline

tools/tokenizer/token_common.c:108–128  ·  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). */

Source from the content-addressed store, hash-verified

106 Note: never returns a CR (\r).
107*/
108static int normalize_newline(void)
109{
110 /* No need to recognize Unicode code points here. */
111 int cc = getchar();
112
113 if (cc == '\r') {
114 // Maybe \r \n (CR NL) combination?
115 int nc = getchar();
116 if (nc == '\n') {
117 char_count++; // counts the carriage return
118 utf8_count++;
119 // No use incrementing column.
120 return nc; // effectively skip the \r
121 }
122 // Mind nc not \n.
123 if (nc != EOF) ungetc(nc, stdin);
124 // cc == '\r'; consider a newline as well, so turn into \n:
125 cc = '\n';
126 }
127 return cc;
128}
129
130/* Detects escaped newlines (line continuations) and signals them with the
131 special '\r' character (that otherwise is not used).

Callers 1

getFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected