Adding uri-has-scheme? utility.

This commit is contained in:
Alex Shinn 2014-05-27 06:50:55 +09:00
parent 24d22644d0
commit 5246763c8b
2 changed files with 10 additions and 2 deletions

View file

@ -170,7 +170,7 @@
(define (string->uri str . o)
(apply string->path-uri #f str o))
;;> Convert a URI object to a string.
;;> Convert a URI object to a string. Returns #f if the uri has no scheme.
(define (uri->string uri . o)
(define encode? (and (pair? o) (car o)))
@ -194,6 +194,14 @@
(if (pair? query) (uri-alist->query query) (or query ""))
(if fragment "#" "") (if fragment (encode fragment) "")))))
;;> Returns true iff the given URI string has a scheme.
(define uri-has-scheme?
(let ((no-scheme (list 'no-scheme)))
(lambda (url)
(and url
(eq? no-scheme (uri-scheme (string->path-uri no-scheme url)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; query encoding and decoding

View file

@ -1,6 +1,6 @@
(define-library (chibi uri)
(export uri? uri->string make-uri string->uri string->path-uri
(export uri? uri->string make-uri string->uri string->path-uri uri-has-scheme?
uri-scheme uri-user uri-host uri-port uri-path uri-query uri-fragment
uri-with-scheme uri-with-user uri-with-host uri-with-path
uri-with-query uri-with-fragment