Platform independent line terminators
Posted: Sun Sep 07, 2008 9:09 pm
If you're writing cobra code (output strings) for multiple platforms ( .Net and mono) say its painful ( not to mention ugly) to provide correct line terminators for the specific platform
( in fact its not just between platforms - this bites even within Windows - output to file and a Gui widget for e.g.)
i.e you have to do something like
rather than the more obvious
I propose adding another c'\?' metacharacter to the currently supported set ( '\n', \r', '\t', ...) for strings
that expands to Environment.newLine automatically
I'd suggest '\N'
(in an attempt to belabour the point, the first block of example code above has a deliberate mistake in it)
( in fact its not just between platforms - this bites even within Windows - output to file and a Gui widget for e.g.)
i.e you have to do something like
- Code: Select all
nl=Environment.newLine
...
string='\nline1...[nl]line2...[nl]....[nl]
...
rather than the more obvious
- Code: Select all
string='\nline1...\nline2...\n....\n\n
# or
string='\r\nline1...\r\nline2...\r\n....\r\n\r\n
I propose adding another c'\?' metacharacter to the currently supported set ( '\n', \r', '\t', ...) for strings
that expands to Environment.newLine automatically
I'd suggest '\N'
- Code: Select all
string='\Nline1...\Nline2...\N....\N\N
(in an attempt to belabour the point, the first block of example code above has a deliberate mistake in it)