Re: readln() returns new line charater

2013-12-31 Thread Jeroen Bollen
On Monday, 30 December 2013 at 02:59:23 UTC, Marco Leise wrote: Am Sun, 29 Dec 2013 22:03:14 + schrieb Jeroen Bollen jbin...@gmail.com: On Sunday, 29 December 2013 at 18:13:30 UTC, Jakob Ovrum wrote: On Sunday, 29 December 2013 at 17:25:39 UTC, Jeroen Bollen wrote: Wouldn't byline

Re: readln() returns new line charater

2013-12-31 Thread Marco Leise
Am Tue, 31 Dec 2013 13:09:34 + schrieb Jeroen Bollen jbin...@gmail.com: On Monday, 30 December 2013 at 02:59:23 UTC, Marco Leise wrote: Am Sun, 29 Dec 2013 22:03:14 + schrieb Jeroen Bollen jbin...@gmail.com: On Sunday, 29 December 2013 at 18:13:30 UTC, Jakob Ovrum wrote: On

Re: readln() returns new line charater

2013-12-31 Thread Stewart Gordon
On 31/12/2013 14:45, Marco Leise wrote: snip I guess I just don't see what an immutable string buys you. The mutable part in a string is just a pointer and length pair. Just write: immutable s = readln()[0 .. $-1]; and you have an immutable string at no cost. What if the line is at EOF

Re: readln() returns new line charater

2013-12-31 Thread Marco Leise
Am Tue, 31 Dec 2013 16:21:14 + schrieb Stewart Gordon smjg_1...@yahoo.com: On 31/12/2013 14:45, Marco Leise wrote: snip I guess I just don't see what an immutable string buys you. The mutable part in a string is just a pointer and length pair. Just write: immutable s =

Re: readln() returns new line charater

2013-12-31 Thread bearophile
Stewart Gordon: I'd be inclined to define a function like string stripLineBreak(string s) { while (s.length != 0 s[$-1] != '\n' s[$-1] != '\r') { s = s[0..$-1]; } return s; } See the chop and chomp functions in std.string. Bye, bearophile

Re: readln() returns new line charater

2013-12-31 Thread Stewart Gordon
On 28/12/2013 16:49, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off? The newline character needs to be read - how else will it know when it's got to the end of the line? :) Of

Re: readln() returns new line charater

2013-12-30 Thread Regan Heath
On Sat, 28 Dec 2013 17:42:23 -, Jakob Ovrum jakobov...@gmail.com wrote: On Saturday, 28 December 2013 at 17:23:30 UTC, Jeroen Bollen wrote: Usually if you're working with a console though the input stream won't exhaust and thus the blocking 'readln' would be a better option, no? The

Re: readln() returns new line charater

2013-12-30 Thread Jakob Ovrum
On Monday, 30 December 2013 at 12:36:15 UTC, Regan Heath wrote: Cue empty vs null theme music.. Empty vs null is not a factor here. It returns a string containing the line terminator(s) for an empty line, but an empty string (incidentally non-null) if the file is closed.

Re: readln() returns new line charater

2013-12-30 Thread Regan Heath
On Mon, 30 Dec 2013 13:51:46 -, Jakob Ovrum jakobov...@gmail.com wrote: On Monday, 30 December 2013 at 12:36:15 UTC, Regan Heath wrote: Cue empty vs null theme music.. Empty vs null is not a factor here. It returns a string containing the line terminator(s) for an empty line, but an

Re: readln() returns new line charater

2013-12-29 Thread Jeroen Bollen
On Saturday, 28 December 2013 at 17:42:26 UTC, Jakob Ovrum wrote: On Saturday, 28 December 2013 at 17:23:30 UTC, Jeroen Bollen wrote: Usually if you're working with a console though the input stream won't exhaust and thus the blocking 'readln' would be a better option, no? The blocking

Re: readln() returns new line charater

2013-12-29 Thread Jakob Ovrum
On Sunday, 29 December 2013 at 17:25:39 UTC, Jeroen Bollen wrote: Wouldn't byline return an empty string if the inputstream is exhausted but not closed? No, both `readln` and `byLine` will block until either EOL or EOF. They differ in their handling of EOF - `readln` returns an empty string,

Re: readln() returns new line charater

2013-12-29 Thread Dmitry Olshansky
28-Dec-2013 21:13, Vladimir Panteleev пишет: On Saturday, 28 December 2013 at 17:07:58 UTC, Andrei Alexandrescu wrote: On 12/28/13 8:50 AM, Jeroen Bollen wrote: On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read

Re: readln() returns new line charater

2013-12-29 Thread Vladimir Panteleev
On Sunday, 29 December 2013 at 18:45:36 UTC, Dmitry Olshansky wrote: I've come to conclusion that the only sane line ending behavior is to do what Unicode standard says, and detect the following pattern as line separator: \r\n | \r | \f | \v | \n | \u0085 | \u2028 | \u2029 This includes

Re: readln() returns new line charater

2013-12-29 Thread Dmitry Olshansky
29-Dec-2013 23:28, Vladimir Panteleev пишет: On Sunday, 29 December 2013 at 18:45:36 UTC, Dmitry Olshansky wrote: I've come to conclusion that the only sane line ending behavior is to do what Unicode standard says, and detect the following pattern as line separator: \r\n | \r | \f | \v | \n |

Re: readln() returns new line charater

2013-12-29 Thread Jeroen Bollen
On Sunday, 29 December 2013 at 18:13:30 UTC, Jakob Ovrum wrote: On Sunday, 29 December 2013 at 17:25:39 UTC, Jeroen Bollen wrote: Wouldn't byline return an empty string if the inputstream is exhausted but not closed? No, both `readln` and `byLine` will block until either EOL or EOF. They

Re: readln() returns new line charater

2013-12-29 Thread Marco Leise
Am Sun, 29 Dec 2013 22:03:14 + schrieb Jeroen Bollen jbin...@gmail.com: On Sunday, 29 December 2013 at 18:13:30 UTC, Jakob Ovrum wrote: On Sunday, 29 December 2013 at 17:25:39 UTC, Jeroen Bollen wrote: Wouldn't byline return an empty string if the inputstream is exhausted but not

Re: readln() returns new line charater

2013-12-29 Thread Marco Leise
Am Sat, 28 Dec 2013 17:08:38 + schrieb Vladimir Panteleev vladi...@thecybershadow.net: On Saturday, 28 December 2013 at 17:07:23 UTC, Andrei Alexandrescu wrote: On 12/28/13 8:49 AM, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't

Re: readln() returns new line charater

2013-12-29 Thread Vladimir Panteleev
On Monday, 30 December 2013 at 03:03:37 UTC, Marco Leise wrote: Am Sat, 28 Dec 2013 17:08:38 + schrieb Vladimir Panteleev vladi...@thecybershadow.net: On Saturday, 28 December 2013 at 17:07:23 UTC, Andrei Alexandrescu wrote: On 12/28/13 8:49 AM, Jeroen Bollen wrote: Why is when you do

readln() returns new line charater

2013-12-28 Thread Jeroen Bollen
Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off?

Re: readln() returns new line charater

2013-12-28 Thread Jeroen Bollen
On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off? I just want to add to this, that it makes it really annoying to work with the command

Re: readln() returns new line charater

2013-12-28 Thread bearophile
Jeroen Bollen: it makes it really annoying to work with the command line, as you kinda have to strip off the last character and thus cannot make the string immutable. void main() { import std.stdio, std.string; immutable txt = readln.chomp; writeln(, txt, ); } Bye, bearophile

Re: readln() returns new line charater

2013-12-28 Thread Andrei Alexandrescu
On 12/28/13 8:49 AM, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off? So you know that if it returns an empty string the file is done. Andrei

Re: readln() returns new line charater

2013-12-28 Thread Jakob Ovrum
On Saturday, 28 December 2013 at 16:50:21 UTC, Jeroen Bollen wrote: On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off? I just want to add

Re: readln() returns new line charater

2013-12-28 Thread Andrei Alexandrescu
On 12/28/13 8:50 AM, Jeroen Bollen wrote: On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off? I just want to add to this, that it makes it

Re: readln() returns new line charater

2013-12-28 Thread Vladimir Panteleev
On Saturday, 28 December 2013 at 17:07:23 UTC, Andrei Alexandrescu wrote: On 12/28/13 8:49 AM, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that character to be stripped off? So you know that if it returns an empty

Re: readln() returns new line charater

2013-12-28 Thread Ali Çehreli
On 12/28/2013 08:50 AM, Jeroen Bollen wrote: On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Because it is possible to remove but hard or expensive or even impossible (was there a newline?) to add back

Re: readln() returns new line charater

2013-12-28 Thread Vladimir Panteleev
On Saturday, 28 December 2013 at 17:07:58 UTC, Andrei Alexandrescu wrote: On 12/28/13 8:50 AM, Jeroen Bollen wrote: On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote: Why is when you do readln() the newline character (\n) gets read too? Wouldn't it make more sense for that

Re: readln() returns new line charater

2013-12-28 Thread Jakob Ovrum
On Saturday, 28 December 2013 at 16:59:51 UTC, bearophile wrote: void main() { import std.stdio, std.string; immutable txt = readln.chomp; writeln(, txt, ); } Bye, bearophile These examples are cute, but I think in real programs it's usually important to handle `stdin` being

Re: readln() returns new line charater

2013-12-28 Thread Jeroen Bollen
On Saturday, 28 December 2013 at 17:15:17 UTC, Jakob Ovrum wrote: On Saturday, 28 December 2013 at 16:59:51 UTC, bearophile wrote: void main() { import std.stdio, std.string; immutable txt = readln.chomp; writeln(, txt, ); } Bye, bearophile These examples are cute, but I think in

Re: readln() returns new line charater

2013-12-28 Thread Jakob Ovrum
On Saturday, 28 December 2013 at 17:23:30 UTC, Jeroen Bollen wrote: Usually if you're working with a console though the input stream won't exhaust and thus the blocking 'readln' would be a better option, no? The blocking behaviour of `stdin` by default is fine. The issue is that `readln`