File: stringutils.yap

package info (click to toggle)
yap 5.1.3-6
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 19,796 kB
  • sloc: ansic: 146,224; perl: 53,318; java: 2,638; sh: 2,578; makefile: 2,040; tcl: 352; python: 101; awk: 9; cpp: 6
file content (34 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (4)
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
33
34
:- module(string_utils,
	  [string/1,
	   upcase_string/2,
	   downcase_string/2,
	   string_length/2,
	   concat_strings/3
	  ]).

:- use_module(library(lists),
	      [append/3]).

string([]).
string([A|Cs]) :-
	integer(A),
	A > 0, % no EOF allowed
	A < 0x3ffffff, % UNICODE characters, strictly not yet required.
	string(Cs).

upcase_string([], []).
upcase_string([C|Cs], [NC|NCs]) :-
	code_type(C,to_lower(NC)),
	upcase_string(Cs, NCs).

downcase_string([], []).
downcase_string([C|Cs], [NC|NCs]) :-
	code_type(C,to_upper(NC)),
	downcase_string(Cs, NCs).

string_length(S, Length) :-
	length(S, Length).

concat_strings(S1, S2, New) :-
	append(S1, S2, New).