Changeset 11407


Ignore:
Timestamp:
11/30/08 21:54:52 (13 years ago)
Author:
ehuelsmann
Message:

Allow for null ENCODING values: they mean "default".

Location:
branches/open-external-format/src/org/armedbear/lisp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/open-external-format/src/org/armedbear/lisp/socket.lisp

    r11391 r11407  
    3232(in-package "SYSTEM")
    3333
    34 (defun get-socket-stream (socket &key (element-type 'character))
     34(defun get-socket-stream (socket &key (element-type 'character) (external-format :default))
    3535  ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8); the default is CHARACTER."
    3636  (cond ((eq element-type 'character))
     
    4040                :format-control
    4141                ":ELEMENT-TYPE must be CHARACTER or (UNSIGNED-BYTE 8).")))
    42   (%socket-stream socket element-type))
     42  (%socket-stream socket element-type external-format))
    4343
    4444(defun make-socket (host port)
  • branches/open-external-format/src/org/armedbear/lisp/socket_stream.java

    r11391 r11407  
    4141    private socket_stream()
    4242    {
    43         super("%socket-stream", PACKAGE_SYS, false, "socket element-type");
     43        super("%socket-stream", PACKAGE_SYS, false, "socket element-type external-format");
    4444    }
    4545
    46     public LispObject execute(LispObject first, LispObject second)
     46    static final private Symbol keywordCodePage = Packages.internKeyword("CODE-PAGE");
     47
     48    public LispObject execute(LispObject first, LispObject second, LispObject third)
    4749        throws ConditionThrowable
    4850    {
    4951        Socket socket = (Socket) ((JavaObject)first).getObject();
    5052        LispObject elementType = second; // Checked by caller.
     53  LispObject externalFormat = third;
     54  String encoding = "ISO-8859-1"; // for default
     55  if (externalFormat != NIL) {
     56      if (externalFormat instanceof Symbol) {
     57    Symbol enc = (Symbol)externalFormat; //FIXME: class cast exception to be caught
     58    if (enc != NIL) {
     59        if (enc != keywordCodePage) {
     60      encoding = enc.getName();
     61        }
     62        //FIXME: the else for the keywordCodePage to be filled in
     63    }
     64    //FIXME: the else for the == NIL to be filled in: raise an error...
     65      } else if (externalFormat instanceof AbstractString) {
     66    AbstractString encName = (AbstractString) externalFormat;
     67    encoding = encName.getStringValue();
     68      }
     69  }
    5170        try {
    5271             Stream in =
    53                  new Stream(socket.getInputStream(), elementType);
     72                 new Stream(socket.getInputStream(), elementType, encoding);
    5473             Stream out =
    55                  new Stream(socket.getOutputStream(), elementType);
     74                 new Stream(socket.getOutputStream(), elementType, encoding);
    5675             return new SocketStream(socket, in, out);
    5776        }
  • branches/open-external-format/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java

    r11405 r11407  
    174174  fcnpos = fcn.position();
    175175  fcnsize = fcn.size();
    176    
    177   cset = Charset.forName(encoding);
     176 
     177  cset = (encoding == null) ? Charset.defaultCharset() : Charset.forName(encoding);
    178178  cdec = cset.newDecoder();
    179179  cenc = cset.newEncoder();
Note: See TracChangeset for help on using the changeset viewer.