www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - encoding of EOL in string literals

reply BCS <ao pathlink.com> writes:
I'm not complaining , just wondering if this is correct.

This code produces the exact same output regardless of the type of end-of-line 
(\n, \n\r or \r) used

import std.stdio;
void main()
{
	foreach(char c; "hello
world
")
	writef("%s\n", cast(ubyte) c);
}

On linux for all three cases the output is:

104
101
108
111
10
119
111
114
108
100
10

This indicates that the EOLs are all handled before the parsing of the string.
Feb 11 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"BCS" <ao pathlink.com> wrote in message 
news:ce0a334372708c91c2ef2178e6e news.digitalmars.com...
 I'm not complaining , just wondering if this is correct.

 This code produces the exact same output regardless of the type of 
 end-of-line (\n, \n\r or \r) used

 import std.stdio;
 void main()
 {
 foreach(char c; "hello
 world
 ")
 writef("%s\n", cast(ubyte) c);
 }

 On linux for all three cases the output is:

 104
 101
 108
 111
 10
 119
 111
 114
 108
 100
 10

 This indicates that the EOLs are all handled before the parsing of the 
 string.
In the "Lexical" section of the spec, it says "EndOfLine is regarded as a single \n character" with regards to multiline strings. So there you go.
Feb 11 2007
parent BCS <BCS pathlink.com> writes:
Jarrett Billingsley wrote:
 "BCS" <ao pathlink.com> wrote in message 
 news:ce0a334372708c91c2ef2178e6e news.digitalmars.com...
 
I'm not complaining , just wondering if this is correct.

This code produces the exact same output regardless of the type of 
end-of-line (\n, \n\r or \r) used

import std.stdio;
void main()
{
foreach(char c; "hello
world
")
writef("%s\n", cast(ubyte) c);
}

On linux for all three cases the output is:

104
101
108
111
10
119
111
114
108
100
10

This indicates that the EOLs are all handled before the parsing of the 
string.
In the "Lexical" section of the spec, it says "EndOfLine is regarded as a single \n character" with regards to multiline strings. So there you go.
Thanks. And lucky me, (That's what I was doing <g>)
Feb 12 2007