Changeset 13325 for trunk/abcl/src/org


Ignore:
Timestamp:
06/10/11 15:52:50 (10 years ago)
Author:
Mark Evenson
Message:

Fix the URI decoding algorithim in Pathname.

Provide EXT:URI-DECODE and EXT:URI-ENCODE for access to the routines
used by Pathname.

File:
1 edited

Legend:

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

    r13302 r13325  
    24302430    }
    24312431
     2432   
     2433    @DocString(name="uri-decode",
     2434               args="string => string",
     2435               doc="Decode percent escape sequences in the manner of URI encodings.")
     2436    private static final Primitive URI_DECODE = new pf_uri_decode();
     2437    private static final class pf_uri_decode extends Primitive {
     2438        pf_uri_decode() {
     2439            super("uri-decode", PACKAGE_EXT, true);
     2440        }
     2441        @Override
     2442        public LispObject execute(LispObject arg) {
     2443            if (!(arg instanceof AbstractString)) {
     2444                return error(new TypeError(arg, Symbol.STRING));
     2445            }
     2446            String result = uriDecode(((AbstractString)arg).toString());
     2447            return new SimpleString(result);
     2448        }
     2449    };
     2450
    24322451    static String uriDecode(String s) {
    24332452        try {
    2434             URI uri = new URI(null, null, null, s, null);
    2435             return uri.toASCIIString().substring(1);
     2453            URI uri = new URI("file://foo?" + s);
     2454            return uri.getQuery();
    24362455        } catch (URISyntaxException e) {}
    24372456        return null;  // Error
    24382457    }
     2458
     2459
     2460    @DocString(name="uri-encode",
     2461               args="string => string",
     2462               doc="Encode percent escape sequences in the manner of URI encodings.")
     2463    private static final Primitive URI_ENCODE = new pf_uri_encode();
     2464    private static final class pf_uri_encode extends Primitive {
     2465        pf_uri_encode() {
     2466            super("uri-encode", PACKAGE_EXT, true);
     2467        }
     2468        @Override
     2469        public LispObject execute(LispObject arg) {
     2470            if (!(arg instanceof AbstractString)) {
     2471                return error(new TypeError(arg, Symbol.STRING));
     2472            }
     2473            String result = uriEncode(((AbstractString)arg).toString());
     2474            return new SimpleString(result);
     2475        }
     2476    };
    24392477
    24402478    static String uriEncode(String s) {
Note: See TracChangeset for help on using the changeset viewer.