     1string utf8 encode
     [ CHAR: % , >hex >upper 2 CHAR: 0 pad-head % ] each ;
 
+: (url-encode) ( str quot: ( ch -- ? ) -- encoded )
+    '[ [ dup @ [ , ] [ push-utf8 ] if ] each ] "" make ; inline
+
 PRIVATE>
 
 : url-encode ( str -- encoded )
-    [
-        [ dup url-quotable? [ , ] [ push-utf8 ] if ] each
-    ] "" make ;
+    [ url-quotable? ] (url-encode) ;
 
 : url-encode-full ( str -- encoded )
-    [
-        [ dup unreserved? [ , ] [ push-utf8 ] if ] each
-    ] "" make ;
+    [ unreserved? ] (url-encode) ;
 
 <PRIVATE
 

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

: url-decode-% ( index str -- index str )
    2dup url-decode-hex ;

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

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

: query-decode ( str -- decoded )
    "+" split "%20" join url-decode ;

<PRIVATE

