Changeset 13917


Ignore:
Timestamp:
04/16/12 22:09:14 (10 years ago)
Author:
Mark Evenson
Message:

SYS:AVAILABLE-ENCODINGS returns a list of formats suitable for stream construction.

The implementation may actually accept additional synonyms, but they
will all be mapped to these underlying encodings native to the hosting
JVM.

The contents of this list are JVM implementation dependent.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Stream.java

    r13768 r13917  
    5151import java.util.BitSet;
    5252
     53import java.util.List;
     54import java.util.LinkedList;
     55import java.util.SortedMap;
     56import java.util.Set;
     57
    5358import org.armedbear.lisp.util.DecodingReader;
    5459
     
    143148        this(structureClass, inputStream, elementType, keywordDefault);
    144149    }
     150 
    145151
    146152
     
    330336            ((DecodingReader)reader).setCharset(Charset.forName(encoding));
    331337    }
     338
     339
     340  public static final Primitive AVAILABLE_ENCODINGS = new pf_available_encodings();
     341  @DocString(name="available-encodings",
     342             returns="encodings",
     343             doc="Returns all charset encodings suitable for passing to a stream constructor available at runtime.")
     344  private static final class pf_available_encodings extends Primitive {
     345    pf_available_encodings() {
     346      super("available-encodings", PACKAGE_SYS, true);
     347    }
     348    public LispObject execute() {
     349      LispObject result = NIL;
     350      for (Symbol encoding : availableEncodings()) {
     351        result = result.push(encoding);
     352      }
     353      return result.nreverse();
     354    }
     355  }
     356
     357  static public List<Symbol> availableEncodings() {
     358    List<Symbol> result = new LinkedList<Symbol>();
     359
     360    SortedMap<String, Charset> available = Charset.availableCharsets();
     361    Set<String> encodings = available.keySet();
     362    for (String charset : encodings) {
     363      result.add(new Symbol(charset));
     364    }
     365    return result;
     366  }
    332367
    333368    public boolean isOpen() {
Note: See TracChangeset for help on using the changeset viewer.