SLIB documentation: http://people.csail.mit.edu/jaffer/slib/URI.html
For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rs-libs
0.1. URIs: (import (slib uri))
A package for creating, decoding and testing various forms of URI.
0.1.1. absolute-path
absolute-path?
returns true if the given filename is an absolute
path, or false if it depends on the current directory.
> (absolute-path? "/usr/local/bin/scheme") #t > (absolute-path? "../filename") #f
0.1.2. absolute-uri?
absolute-uri?
returns true if the given uri is an absolute uri (containing
a complete description of the named resource), or false otherwise.
> (absolute-uri? "ftp://example.org/resource.txt") #t > (absolute-uri? "resource.txt") #f
0.1.3. glob-pattern?
glob-pattern?
returns true if the given string contains any symbol typically
used in a glob, i.e. * ? [ ]
> (glob-pattern? "/home/dir/*/file.txt") #t > (glob-pattern? "/home/dir/x/file?.txt") #t > (glob-pattern? "/home/dir/x/fil[e].txt") #t > (glob-pattern? "/home/dir/x/file.txt") #f
0.1.4. html syntax
The following four functions generate html text for different purposes:
-
html:anchor
creates a named location given a name as a string. -
html:base
returns a string representing the base of given uri. -
html:isindex
creates a string for a search prompt (now deprecated for html forms). -
html:link
takes a uri and title, and returns a link to uri displaying the title.
> (html:anchor "location") ;; <1> <A NAME="location"></A> > (html:base "http:peterlane.info") <BASE HREF="http:peterlane.info"> > (html:isindex "Search term: ") <ISINDEX PROMPT="Search term: "> > (html:link "http://peterlane.info" "home page") <A HREF="http://peterlane.info">home page</A>
-
Use "<A HREF=#location>" to link back to this location.
0.1.5. make-uri
make-uri
constructs a URI given from 0 to 5 arguments. These are: scheme, authority,
path, query, fragment. These are optional from the front, so a single argument will be treated as the
fragment; two arguments as a query and then a fragment, etc.
> (make-uri) ; <1> > (make-uri "xyz") ; <2> #xyz > (make-uri "query" "xyz") ; <3> ?query#xyz > (make-uri "http" "peterlane.info" "/files/location" "query" "xyz") ; <4> http://peterlane.info/files/location?query#xyz
-
Returns the empty string
-
Single argument is a Fragment
-
Query and Fragment
-
All components: the authority in this case is the web address, and the path the relative location of files
0.1.6. null-directory?
null-directory?
takes a string and returns true if the string
names the current directory (so changing to it would not make any change).
0.1.7. parse-ftp-address
parse-ftp-address
converts a string, representing an ftp address, into a list of up
to four values: the username, password, remote site, and remote directory. #f
is returned if any
of these values is not present, or #f
instead of a list if the string is not an ftp address.
> (parse-ftp-address "ftp://username@ftp.someplace.site/") ("username" #f "ftp.someplace.site" #f) > (parse-ftp-address "ftp://username:password@ftp.someplace.site/dir") ("username" "password" "ftp.someplace.site" "dir")
0.1.8. path→uri
path→uri
converts a given path (as a string) into a URI with an absolute address.
> (path->uri "filename.txt") file:/home/NAME/CURRENT-DIRECTORY/filename.txt > (path->uri "/usr/local/filename.txt") file:/usr/local/filename.txt
0.1.9. uri→tree
uri→tree
takes a URI and returns a list of five values corresponding to the scheme, authority, path, query, fragment:
> (uri->tree "file:/usr/local/filename.txt") (file #f ("" "usr" "local" "filename.txt") #f #f)
0.1.10. uri:decode-query
uri:decode-query
converts a given query string into an association list
of key-value pairs:
> (uri:decode-query "name=XXX&date=32") ((date "32") (name "XXX"))
0.1.11. uri:make-path
uri:make-path
takes a list of strings, and returns a path component by joining
the strings together with a suitable separator:
> (uri:make-path '("a" "b" "c")) "a/b/c"
0.1.12. uri:splitfields
uri:splitfields
splits a string at a given character.
> (uri:splitfields "some text to split" #\space) '("some" "text" "to" "split")
0.1.13. uric:decode/encode
uric:decode
and uric:encode
convert a string to and from a form
with certain characters rewritten using % octal values:
> (uric:decode "xxx%20yyy") "xxx yyy" > (uric:encode "xxx yyy") "xxx%20yyy"
An optional second argument to uric:encode
provides a string of characters to allow.