|Anonymous | Login | Signup for a new account||2014-04-25 07:56 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0006088||OCaml||OCaml standard library||public||2013-07-26 15:22||2013-07-29 19:08|
|Status||resolved||Resolution||no change required|
|Target Version||Fixed in Version|
|Summary||0006088: Pervasives.input_line does'nt remove \r at end of lines|
|Description||Documentation says: "Return the string of all characters read, without the newline character at the end."|
Well, on Windows, the newline characters are two, "\r\n" ; one would expect that they are both removed, and that would avoid portability issues. Instead, the function returns strings ending with '\r'.
|Tags||No tags attached.|
|Did you open the file with open_in or open_in_bin? open_in will do newline translation (removing the \r as appropriate), but not open_in_bin. Do you have a complete code example as a repro case?|
Gasche is right: the Windows programming model (for OCaml and most other languages) is that for in-memory strings, lines are terminated by a single "\n" character. It's only within text files that "\r\n" is used, and the conversion happens when reading or writing to/from files. So, just open your text files with "open_in" and not "open_in_bin" and input_line will work fine.
Right, I suspected it was done that way for open_in (the documentation isn't completely explicit but mentions it), and I think that this is a good way to handle things. My issue then is that I was actually using "Unix.open_process_in" in that case, which has no "_bin" counterpart (and commands, typically ocaml, answer with Windows EOLs).
I am not sure what the correct behaviour would be in that case, but the current one isn't completely consistent.
(note: this is using the mingw32 version)
> I was actually using "Unix.open_process_in" in that case, which has no "_bin" counterpart
Right, the open_process_* functions default to binary mode, somewhat arbitrarily. It wouldn't hurt to document this fact.
You can, however, use "set_binary_mode_in" or "set_binary_mode_out" on the returned channel to put it into text mode. These operations are no-ops under non-Windows systems, so your code remains fully portable.
Seems like I somehow overlooked the "set_binary_mode_*" functions.
Thanks a lot !
|2013-07-26 15:22||AltGr||New Issue|
|2013-07-26 18:32||gasche||Note Added: 0009868|
|2013-07-29 16:29||xleroy||Note Added: 0009985|
|2013-07-29 16:29||xleroy||Status||new => resolved|
|2013-07-29 16:29||xleroy||Resolution||open => no change required|
|2013-07-29 18:26||AltGr||Note Added: 0009992|
|2013-07-29 18:57||xleroy||Note Added: 0009994|
|2013-07-29 19:08||AltGr||Note Added: 0009995|
|Copyright © 2000 - 2011 MantisBT Group|