problem in reading text files

Jaroslav Hajek highegg at gmail.com
Tue Sep 9 04:18:55 CDT 2008


On Mon, Sep 8, 2008 at 6:50 PM, John W. Eaton <jwe at bevo.che.wisc.edu> wrote:
> On  6-Sep-2008, Ben Abbott wrote:
>
> |
> | On Sep 5, 2008, at 3:11 PM, Yaping Zhou wrote:
> |
> | > Thank you all for looking at this.
> | >
> | > The text files I sent before were from Perl. After I read your
> | > discussion about line end characters, I used SciTE to change the
> | > line end characters to LF and CR. I wasn't able to load any of them
> | > ( see attachment). I was using 3.0.1 on Windows XP.
> | >
> | > Regards
> |
> | "load NotOK2_LF.txt" works for me ... I tried both Octave 3.0.1 and
> | 3.1.51.
>
> I checked in the follwoing changes to my sources.  These should
> probably also be applied to the 3.0.x branch.

Done.

> I think this should
> allow files containing any combination of LF, CR, or CRLF to be loaded
> properly.  It works for me on a GNU/Linux system and I think it should
> also work on OS X and Windows systems.  But I can't easily check that,
> so it would be helpful if someone could test this patch on those
> systems.
>
> Thanks,
>
> jwe
>
>
>
> # HG changeset patch
> # User John W. Eaton <jwe at octave.org>
> # Date 1220892353 14400
> # Node ID 7d19f4f70c613ca006e7062a4dba82b5a7c20a8d
> # Parent  83646120b54c9c69b831236c65e32e2fb37c03fd
> ls-oct-ascii.{h,cc} (extract_keyword): accept \r as line ending character
>
> diff --git a/src/ChangeLog b/src/ChangeLog
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,12 @@
> +2008-09-08  John W. Eaton  <jwe at octave.org>
> +
> +       * ls-oct-ascii.cc (std::string extract_keyword (std::istream&,
> +       const char *, const bool)): Also accept \r as line ending character.
> +       * ls-oct-ascii.h (template <class T> bool extract_keyword
> +       (std::istream&, const char *, T&, const bool)): Likewise.
> +       (template <class T> bool extract_keyword (std::istream&, const
> +       string_vector&, std::string&, T&, const bool)): Likewise.
> +
>  2008-09-03  Ben Abbott <bpabott at mac.com>
>
>        * mappers.cc: Use eps(single) as tolerance for single precesion test.
> diff --git a/src/ls-oct-ascii.cc b/src/ls-oct-ascii.cc
> --- a/src/ls-oct-ascii.cc
> +++ b/src/ls-oct-ascii.cc
> @@ -110,10 +110,10 @@
>              while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
>                ; // Skip whitespace and the colon.
>
> -             if (c != '\n')
> +             if (c != '\n' && c != '\r')
>                {
>                  value << c;
> -                 while (is.get (c) && c != '\n')
> +                 while (is.get (c) && c != '\n' && c != '\r')
>                    value << c;
>                }
>
> @@ -124,7 +124,7 @@
>            break;
>          else
>            {
> -             while (is.get (c) && c != '\n')
> +             while (is.get (c) && c != '\n' && c != '\r')
>                ; // Skip to end of line.
>            }
>        }
> diff --git a/src/ls-oct-ascii.h b/src/ls-oct-ascii.h
> --- a/src/ls-oct-ascii.h
> +++ b/src/ls-oct-ascii.h
> @@ -99,11 +99,11 @@
>                ; // Skip whitespace and the colon.
>
>              is.putback (c);
> -             if (c != '\n')
> +             if (c != '\n' && c != '\r')
>                is >> value;
>              if (is)
>                status = true;
> -             while (is.get (c) && c != '\n')
> +             while (is.get (c) && c != '\n' && c != '\r')
>                ; // Skip to beginning of next line;
>              break;
>            }
> @@ -161,11 +161,11 @@
>                    ; // Skip whitespace and the colon.
>
>                  is.putback (c);
> -                 if (c != '\n')
> +                 if (c != '\n' && c != '\r')
>                    is >> value;
>                  if (is)
>                    status = true;
> -                 while (is.get (c) && c != '\n')
> +                 while (is.get (c) && c != '\n' && c != '\r')
>                    ; // Skip to beginning of next line;
>                  return status;
>                }
>
>



-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


More information about the Bug-octave mailing list