-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhtml_escape.pro
More file actions
29 lines (22 loc) · 814 Bytes
/
Copy pathhtml_escape.pro
File metadata and controls
29 lines (22 loc) · 814 Bytes
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
%% code_html(+Code:integer, -Html:string) is det.
% Html is the result of escaping the character whose code is Code.
code_html(0'&, "&") :- !.
code_html(0'<, "<") :- !.
code_html(0'>, ">") :- !.
code_html(0'", """) :- !.
code_html(C, H) :- string_codes(H, [C]).
%% codes_html(+Codes:list, -Html:string) is det.
% Html is the result of escaping the string whose codes are Codes.
codes_html([], "") :- !.
codes_html([A|B], H) :- var(H), !,
code_html(A, HA),
codes_html(B, HB),
string_concat(HA, HB, H).
codes_html([A|B], H) :- string(H), !,
string_concat(HA, HB, H),
HA \= "",
code_html(A, HA),
codes_html(B, HB).
%% string_html(String:string, Html:string) is det.
% Html is HTML-escaped String.
string_html(S, H) :- string_codes(S, Cs), codes_html(Cs, H).