@@ -1953,9 +1953,16 @@ class Lexer
19531953 {
19541954 const length = p - 1 - pstart;
19551955 if (supportInterpolation)
1956- result.appendInterpolatedPart(pstart[0 .. length]);
1956+ {
1957+ normalizeCRLF(pstart[0 .. length]);
1958+ result.appendInterpolatedPart(stringbuffer[]);
1959+ }
19571960 else
1958- result.setString(pstart[0 .. length]);
1961+ {
1962+ normalizeCRLF(pstart[0 .. length]);
1963+ result.setString(stringbuffer[]);
1964+ }
1965+
19591966 stringPostfix(result);
19601967 return ;
19611968 }
@@ -1964,8 +1971,7 @@ class Lexer
19641971 if (! supportInterpolation)
19651972 goto default ;
19661973
1967- stringbuffer.setsize(0 );
1968- stringbuffer.write(pstart, p - 1 - pstart);
1974+ normalizeCRLF(pstart[0 .. p - 1 - pstart]);
19691975 if (! handleInterpolatedSegment(result, start))
19701976 goto default ;
19711977
@@ -1984,6 +1990,23 @@ class Lexer
19841990 }
19851991 }
19861992
1993+ // Normalize CRLF to LF in raw source bytes and write into stringbuffer
1994+ private void normalizeCRLF (const (char )[] src)
1995+ {
1996+ stringbuffer.setsize(0 );
1997+ foreach (i, char c; src)
1998+ {
1999+ if (c == ' \r ' )
2000+ {
2001+ if (i + 1 < src.length && src[i + 1 ] == ' \n ' )
2002+ continue ;
2003+ stringbuffer.writeByte(' \n ' );
2004+ }
2005+ else
2006+ stringbuffer.writeByte(c);
2007+ }
2008+ }
2009+
19872010 // returns true if it got special treatment as an interpolated segment
19882011 // otherwise returns false, indicating to treat it as just part of a normal string
19892012 private bool handleInterpolatedSegment (Token * token, Loc start)
0 commit comments