[armedbear-devel] EXTERNAL-FORMAT support r11409 - branches/open-external-format/

Erik Huelsmann ehuels at gmail.com
Mon Dec 1 09:23:33 UTC 2008


With the commit below, there's infrastructure for general streams to
do character encoding and generate a specified line-ending style.

It behaves like this:

* output:
  '\n' is translated into
    - '\r' if :EOL-STYLE is :CR
    - "\r\n" if :EOL-STYLE is :CRLF
    - '\n' if :EOL-STYLE is :LF, :RAW

* input:
  '\r" is translated to '\n' for :EOL-STYLE :CR
  "\r\n" is translated to '\n' for :EOL-STYLE :CRLF
  '\n' untouched for :EOL-STYLE :LF or :RAW


As you see we don't detect \r\n, \r, \n all as end-of-lines, recoding
them when required. This is inconsistent with what Subversion does;
however, I'm modelling our EXTERNAL-FORMAT support after
flexi-streams, so, it needs some investigation to see whether we're
actually compatible in that area.


Bye,

Erik.


On Mon, Dec 1, 2008 at 12:05 AM, Erik Huelsmann
<ehuelsmann at common-lisp.net> wrote:
> Author: ehuelsmann
> Date: Sun Nov 30 23:05:51 2008
> New Revision: 11409
>
> Log:
> End-of-line translation for generic streams.
>
> Modified:
>   branches/open-external-format/src/org/armedbear/lisp/Stream.java
>
> Modified: branches/open-external-format/src/org/armedbear/lisp/Stream.java
> ==============================================================================
> --- branches/open-external-format/src/org/armedbear/lisp/Stream.java    (original)
> +++ branches/open-external-format/src/org/armedbear/lisp/Stream.java    Sun Nov 30 23:05:51 2008
> @@ -1760,13 +1760,19 @@
>       {
>         int n = reader.read();
>         ++offset;
> -        if (n == '\r')
> -          {
> -            if (interactive && Utilities.isPlatformWindows)
> -              return _readChar();
> -          }
> -        if (n == '\n')
> +        if (eolStyle == EolStyle.CRLF && n == '\r') {
> +            n = _readChar();
> +            if (n != '\n') {
> +                _unreadChar(n);
> +                return '\r';
> +            }
> +        }
> +
> +        if (n == eolChar) {
>           ++lineNumber;
> +          return '\n';
> +        }
> +
>         return n;
>       }
>     catch (NullPointerException e)
> @@ -1793,7 +1799,7 @@
>       {
>         reader.unread(n);
>         --offset;
> -        if (n == '\n')
> +        if (n == eolChar)
>           --lineNumber;
>       }
>     catch (NullPointerException e)
> @@ -1841,14 +1847,16 @@
>   {
>     try
>       {
> -        writer.write(c);
> -        if (c == '\n')
> -          {
> -            writer.flush();
> -            charPos = 0;
> -          }
> -        else
> +        if (c == '\n') {
> +          if (eolStyle == EolStyle.CRLF)
> +              writer.write('\r');
> +          writer.write(eolChar);
> +          writer.flush();
> +          charPos = 0;
> +        } else {
> +          writer.write(c);
>           ++charPos;
> +        }
>       }
>     catch (NullPointerException e)
>       {
> @@ -1874,6 +1882,13 @@
>   {
>     try
>       {
> +        if (eolStyle != EolStyle.RAW) {
> +          for (int i = start; i++ < end;)
> +            //###FIXME: the number of writes can be greatly reduced by
> +            // writing the space between newlines as chunks.
> +            _writeChar(chars[i]);
> +        }
> +
>         writer.write(chars, start, end - start);
>         int index = -1;
>         for (int i = end; i-- > start;)
> @@ -1918,15 +1933,10 @@
>   {
>     try
>       {
> -        writer.write(s);
> -        int index = s.lastIndexOf('\n');
> -        if (index < 0)
> -          charPos += s.length();
> -        else
> -          {
> -            charPos = s.length() - (index + 1);
> -            writer.flush();
> -          }
> +        for (int i = 0; i++ < s.length();)
> +          //###FIXME: the number of writes can be greatly reduced by
> +          // writing the space between newlines as chunks.
> +          _writeChar(s.charAt(i));
>       }
>     catch (NullPointerException e)
>       {
> @@ -1935,10 +1945,6 @@
>         else
>           throw e;
>       }
> -    catch (IOException e)
> -      {
> -        error(new StreamError(this, e));
> -      }
>   }
>
>   /** Writes a string to the underlying stream, appending
> @@ -1951,20 +1957,14 @@
>   {
>     try
>       {
> -        writer.write(s);
> -        writer.write('\n');
> -        writer.flush();
> -        charPos = 0;
> +        _writeString(s);
> +        _writeChar('\n');
>       }
>     catch (NullPointerException e)
>       {
>         // writer is null
>         streamNotCharacterOutputStream();
>       }
> -    catch (IOException e)
> -      {
> -        error(new StreamError(this, e));
> -      }
>   }
>
>   // Reads an 8-bit byte.
>
> _______________________________________________
> armedbear-cvs mailing list
> armedbear-cvs at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-cvs
>




More information about the armedbear-devel mailing list