[m-rev.] diff: add string.is_all_alnum/1
Julien Fischer
jfischer at opturion.com
Wed Oct 29 11:37:16 AEDT 2014
Add string.is_all_alnum/1.
library/string.m:
Add a predicate for testing whether a string contains
only alphabetic chracters or digits.
Avoid excessive module qualification.
NEWS:
Annouce the addition.
Julien.
diff --git a/NEWS b/NEWS
index 7e0f548..bd96059 100644
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,10 @@ Changes to the Mercury standard library:
- infinity/0
+* The following predicate has been added to the string module:
+
+ - is_all_alnum/1
+
Changes to the Mercury compiler:
* We have enabled stricter checking of non-ground final insts to reject more
diff --git a/library/string.m b/library/string.m
index 9a1f080..bbf1817 100644
--- a/library/string.m
+++ b/library/string.m
@@ -425,6 +425,11 @@
%
:- pred is_all_alpha(string::in) is semidet.
+ % True if string contains only alphabetic characters [A-Za-z] and digits
+ % [0-9].
+ %
+:- pred is_all_alnum(string::in) is semidet.
+
% True if string contains only alphabetic characters [A-Za-z] and
% underscores.
%
@@ -2130,22 +2135,22 @@ string.uncapitalize_first(S0, S) :-
S = S0
).
-string.all_match(P, String) :-
+all_match(P, String) :-
all_match_2(P, String, 0).
:- pred all_match_2(pred(char)::in(pred(in) is semidet), string::in, int::in)
is semidet.
-string.all_match_2(P, String, I) :-
+all_match_2(P, String, I) :-
( string.unsafe_index_next(String, I, J, Char) ->
P(Char),
- string.all_match_2(P, String, J)
+ all_match_2(P, String, J)
;
true
).
-string.is_all_alpha(S) :-
- string.all_match(char.is_alpha, S).
+is_all_alpha(S) :-
+ all_match(char.is_alpha, S).
% The C version is faster than the Mercury version.
:- pragma foreign_proc("C",
@@ -2180,8 +2185,11 @@ string.is_all_alpha(S) :-
}
").
-string.is_all_alpha_or_underscore(S) :-
- string.all_match(char.is_alpha_or_underscore, S).
+is_all_alnum(S) :-
+ all_match(char.is_alnum, S).
+
+is_all_alpha_or_underscore(S) :-
+ all_match(char.is_alpha_or_underscore, S).
% The C version is faster than the Mercury version.
:- pragma foreign_proc("C",
@@ -2218,8 +2226,8 @@ string.is_all_alpha_or_underscore(S) :-
}
").
-string.is_all_alnum_or_underscore(S) :-
- string.all_match(char.is_alnum_or_underscore, S).
+is_all_alnum_or_underscore(S) :-
+ all_match(char.is_alnum_or_underscore, S).
% The C version is faster than the Mercury version.
:- pragma foreign_proc("C",
@@ -2259,8 +2267,8 @@ string.is_all_alnum_or_underscore(S) :-
}
").
-string.is_all_digits(S) :-
- string.all_match(char.is_digit, S).
+is_all_digits(S) :-
+ all_match(char.is_digit, S).
% The C version is faster than the Mercury version.
:- pragma foreign_proc("C",
More information about the reviews
mailing list