|
From: Per W. <pw...@ia...> - 2003-06-30 02:10:06
|
When a file/stream is opened in text mode, the eol sequence is always \n
and then the underlying subsystem will perform the mapping to/from the
native format.
Notethat the underlying subsystem assumes that any read files are in the
native format, and might be confused if the file isn't. Most (all?)
dos/win libraries supports reading of both unix and dos/win files, but a
number of them gets confused for Mac files.
When reading in binary mode:
DOS/Win: \r\n
Unix: \n
Mac: \r
Unicode: U+2028
/Per W
On Mon, 30 Jun 2003, Ioannis Vranos wrote:
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of David McKen
> > Sent: Monday, June 30, 2003 2:31 AM
> > To: Dev-Cpp Mailing List
> > Subject: [Dev-C++] Portable End-of-Line
> >
> >
> > Is there a portable way of finding out the end-of line
> > sequence for the
> > current operating system? I hope to make my program
> > portable to both Win +
> > *NIX and would like something more (what word could go
> > here?) than:
> >
> > #ifdef WIN32
> > const char DIR_SEP = '\\';
> > const char eoln[] = "\n";
> > #else
> > const char DIR_SEP = '/';
> > const char eoln[] = "\n\r";
>
>
> "\n\r" also applies at least to .NET text boxes.
>
>
> In any case only '\n' is portable.
>
>
> > #endif
> >
> > Same applies to the directory separator. Is there a way I
> > can detect which
> > one is used? As I said portability is of utmost importance
> > so it must be C++
> > ANSI compliant (my program uses classes so it cant be a C
> > compliant program.
>
>
> >From my limited experience those "\n\r" etc sequences apply only to GUI
> programs.
>
> Any way, about line change since '\n' exists in all cases you can detect it
> by reading character by character. If you want to display it consider it as
> a system extension and you can handle it as all system extensions by
> encapsulating it to a small portion of your program:
>
>
> Example:
>
> // Unportable encapsulations
> namespace uenc
> {
> const string eol="\n";
>
> inline void clearscr()
> {
> system("cls");
> }
>
> // ...
> }
>
>
> So when you want to compile the program in another platform you have only to
> change those encapsulations.
>
>
> And try to forget the ancient C style stuff where C++ provides superior
> alternatives.
>
>
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL 1: http://run.to/noicys
> * Alternative URL 2: http://www.noicys.cjb.net
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|