Commits

camlspotter committed 3ef0495

added URL

  • Participants
  • Parent commits 770a393

Comments (0)

Files changed (5)

 - Unix.mkdir is overridden
 * Renamed Unix.find to Added Unix.Find.find with poly record interface
 - Added Format.to_string
+- Added URL
 
 2.1.2
 ------------

File lib/OMakefile

    dllist
 #   channel
    tuple
+   URL
    spot
 
 LIB = spotlib
+open Base
+
+let encode s =
+  let len = String.length s in
+  let b = Buffer.create & len * 2 in
+  for i = 0 to len - 1 do
+    match String.unsafe_get s i with
+    | 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' | '.' | '_' | '~' as c -> Buffer.add_char b c
+    | c -> Buffer.add_string b & Printf.sprintf "%%%02x" (Char.code c)
+  done;
+  Buffer.contents b
+
+let make_query kvs =
+  String.concat "&" 
+  & List.map (fun (k,v) ->
+      let b = Buffer.create 100 in
+      Buffer.add_string b & encode k; 
+      Buffer.add_char b '=';
+      Buffer.add_string b & encode v;
+      Buffer.contents b) kvs
+val encode : string -> string
+(** encode "Today's special" = "Today%27s%20special" *)
+
+val make_query : (string * string) list -> string
+(** make_query ["k", "v"; "k2", "v2"] = "k=v&k2=v2" *)
   include Printexc
   include Xprintexc
 end
+
+module URL = URL