string manipulation utilities for scripts.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2146 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
0e45f242d4
commit
54ceaa1f37
34
library/stringutils.yap
Normal file
34
library/stringutils.yap
Normal file
@ -0,0 +1,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).
|
||||
|
Reference in New Issue
Block a user