[Gd-chatter] r11696 - trunk/libraries/uri

turbo24prg at gwydiondylan.org turbo24prg at gwydiondylan.org
Sun Feb 24 01:17:12 CET 2008


Author: turbo24prg
Date: Sun Feb 24 01:17:11 2008
New Revision: 11696

Modified:
   trunk/libraries/uri/library.dylan
   trunk/libraries/uri/uri.dylan
Log:
Job: 7370
implement replacement (eg. for http's '+' => ' ')


Modified: trunk/libraries/uri/library.dylan
==============================================================================
--- trunk/libraries/uri/library.dylan	(original)
+++ trunk/libraries/uri/library.dylan	Sun Feb 24 01:17:11 2008
@@ -33,4 +33,5 @@
     split-path, split-query;
   export absolute?, relative?;
   export print-message;
+  export percent-decode;
 end module;

Modified: trunk/libraries/uri/uri.dylan
==============================================================================
--- trunk/libraries/uri/uri.dylan	(original)
+++ trunk/libraries/uri/uri.dylan	Sun Feb 24 01:17:11 2008
@@ -108,14 +108,25 @@
   split(path, "/", remove-empty-items: #f);
 end;
 
-define method split-query (query :: <string>) => (parts :: <string-table>);
+define method split-query
+    (query :: <string>, #key replacements :: false-or(<sequence>))
+ => (parts :: <string-table>);
   let parts = split(query, "&");
   let table = make(<string-table>); 
   for (part in parts)
-    let (key, value) = apply(values, split(part, "=", remove-empty-items: #f));
-    unless (value)
+    let (key, value) = apply(values, 
+      split(part, "=", remove-empty-items: #f));
+    if (value)
+      if (replacements)
+        for (replacement in replacements)
+          value := regex-replace(value,
+            head(replacement), tail(replacement));
+        end for;
+      end if;
+      value := percent-decode(value);
+    else
       value := #t;
-    end unless;
+    end if;
     table[key] := value;
   end for;
   table;
@@ -324,6 +335,8 @@
 
 begin
 /*
+  format-out("%s\n", split-query("foo=bar+blub&baz", replacements: list(pair("\\+", " ")))["foo"]);
+
   let uri = parse-uri("http://foo:bar@baz.blub:23/path/test/../page?fo%20=ba+r&q1=q2&q3=&q4#extra");
   let url = parse-url("http://foo:bar@baz.blub:23/path/test/../page?fo%20o=b+r&q1=q2&q3=&q4#extra");
   format-out("%=\n", uri.uri-query);
@@ -337,6 +350,7 @@
 */
 end;
 
+
 /*
 let uri = parse-uri("http://foo:bar@baz.blub:23/path/test/../page?foo=bar&q1=q2#extra");
 format-out("%s\n", build-uri(uri)); 



More information about the chatter mailing list