Skip to content

Commit

Permalink
Got it compiling under Clojure 1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtetzner committed May 5, 2012
1 parent 34e97f9 commit 633f7db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
:description "URI library that defines a UniformResourceIdentifier
protocol, and implements it on a custom Uri class, as well as
java.net.URI, java.net.URL, and java.lang.String."
:dependencies [[org.clojure/clojure "1.3.0"]])
:dependencies [[org.clojure/clojure "1.3.0"]]
:aot :all)
32 changes: 16 additions & 16 deletions src/org/bovinegenius/uri.clj
Original file line number Diff line number Diff line change
Expand Up @@ -315,44 +315,44 @@ another Uri object."

(defn query-list
"Returns a list from the query string of the given URI."
[^UniformResourceIdentifier uri]
[uri]
(-> uri query query-string->list))

(defn query-pairs
"Returns an alist of the query params matching the given key. If no
key is given, an alist of all the query params is returned."
([^UniformResourceIdentifier uri key]
([uri key]
(->> uri query-pairs
(filter (fn [[param-key value]]
(= param-key key)))
vec))
([^UniformResourceIdentifier uri]
([uri]
(-> uri query query-string->alist)))

(defn query-params
"Returns an alist of the query values whose key matches the given key. If no
key is given, all values are returned."
([^UniformResourceIdentifier uri key]
([uri key]
(->> uri query-pairs
(filter (fn [[param-key value]]
(= param-key key)))
(map second)
vec))
([^UniformResourceIdentifier uri]
([uri]
(->> uri query query-string->alist (map second) vec)))

(defn query-param-raw
"Get the last param value that matches the given key. If 3 args are
given, set the first param value that matches the given key, and
remove the remaining params that match the given key. If 4 args are
given, set the nth param value that matches the given key."
([^UniformResourceIdentifier uri key]
([uri key]
(-> uri (query-params key) last))
([^UniformResourceIdentifier uri key value]
([uri key value]
(query uri (-> uri query-pairs
(alist-replace key value)
alist->query-string)))
([^UniformResourceIdentifier uri key value index]
([uri key value index]
(query uri (-> uri query-pairs
(alist-replace key value index)
alist->query-string))))
Expand All @@ -376,39 +376,39 @@ given, set the nth param value that matches the given key."
given, set the first param value that matches the given key, and
remove the remaining params that match the given key. If 4 args are
given, set the nth param value that matches the given key."
([^UniformResourceIdentifier uri key]
([uri key]
(let [param (-> uri (query-params key) last)]
(decode-param param)))
([^UniformResourceIdentifier uri key value]
([uri key value]
(query uri (-> uri query-pairs
(alist-replace (encode-param key) (encode-param value))
alist->query-string)))
([^UniformResourceIdentifier uri key value index]
([uri key value index]
(query uri (-> uri query-pairs
(alist-replace (encode-param key) (encode-param value) index)
alist->query-string))))

(defn query-map
"Returns a map of the query string parameters for the given URI."
[^UniformResourceIdentifier uri]
[uri]
(->> uri query-pairs (into {})))

(defn query-keys
"Returns a list of the query string keys of the given URI."
[^UniformResourceIdentifier uri]
[uri]
(->> uri query-pairs (map first) vec))

(defn normalize-path
"Normalize the path of the given uri."
[^UniformResourceIdentifier uri]
[uri]
(->> (path uri) path/normalize (path uri)))

(defn resolve-path
"Resolve the given path against the given uri."
[^UniformResourceIdentifier uri the-path]
[uri the-path]
(path uri (-> (path uri) (path/resolve-path the-path))))

(defn absolute?
"Returns true if the given uri is absolute."
[^UniformResourceIdentifier uri]
[uri]
(-> uri path path/absolute?))
2 changes: 1 addition & 1 deletion src/org/bovinegenius/uri/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parts."
query (if (.contains ssp "?") query nil)
auth-path (last (re-find #"^//(.*)$" front))
[_ authority path] (re-find #"^(.*?)(?=\./|\.\./|/|$)(.*)" auth-path)
path (if (empty? path) nil path the )]
path (if (empty? path) nil path)]
{:authority authority :path path :query query})
{:authority nil :path nil :query nil}))

Expand Down

0 comments on commit 633f7db

Please sign in to comment.