-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuri-parse.pl
32 lines (31 loc) · 1021 Bytes
/
uri-parse.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
:- use_module(schemeMachine).
:- use_module(uriMachine).
/**
* uri_parse(++String:string, -Uri:uri) is nondet.
*
* True when the given string represents a valid URI.
*/
uri_parse(String, uri(Scheme, Userinfo, Host, Port, Path, Query, Fragment)) :-
string_chars(String, Chars),
schemeMachine(Chars, Scheme, Leftover),
downcase_atom(Scheme, LoweredScheme),
uriMachine(
Leftover,
uri(LoweredScheme, Userinfo, Host, Port, Path, Query, Fragment)
).
/**
* uri_display(+Uri:uri, ++Stream:stream) is det.
*
* Always true, writes the given URI to the specified Stream.
*/
uri_display(uri(Scheme, Userinfo, Host, Port, Path, Query, Frag), Stream) :-
write(Stream, uri(Scheme, Userinfo, Host, Port, Path, Query, Frag)),
nl(Stream).
/**
* uri_display(+Uri:uri) is det.
*
* Always true, writes the given URI to current output stream.
*/
uri_display(uri(Scheme, Userinfo, Host, Port, Path, Query, Frag)) :-
current_output(Stream),
uri_display(uri(Scheme, Userinfo, Host, Port, Path, Query, Frag), Stream).