 ! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel ascii combinators combinators.short-circuit
-sequences splitting fry namespaces make assocs arrays strings
-io.encodings.string io.encodings.utf8 math math.parser accessors
-hashtables present ;
+USING: arrays ascii assocs combinators combinators.short-circuit
+fry io.encodings.string io.encodings.utf8 kernel make math
+math.parser present sequences splitting strings ;
 IN: urls.encoding
 
 : url-quotable? ( ch -- ? )

    [ 0 swap url-decode-iter ] "" make utf8 decode ;

: query-decode ( str -- decoded )
    [ dup CHAR: + = [ drop "%20" ] [ 1string ] if ] { } map-as
    concat url-decode ;

<PRIVATE


    2dup length 2 - >= [
        2drop
    ] [
        [ 1 + dup 2 + ] dip subseq hex> [ , ] when*
    ] if ;

: url-decode-iter ( index str -- )
    2dup length >= [
        2drop
    ] [
        2dup nth dup CHAR: % = [
            drop 2dup url-decode-hex [ 3 + ] dip
        ] [
            , [ 1 + ] dip
        ] if url-decode-iter
