[m-rev.] Minor addition to string.m
Ralph Becket
rafe at cs.mu.OZ.AU
Wed Feb 5 12:15:06 AEDT 2003
Forgot about this one:
diff -u library/string.m library/string.m
--- library/string.m 30 Jan 2003 03:51:06 -0000
+++ library/string.m 31 Jan 2003 06:13:59 -0000
@@ -284,30 +284,29 @@
:- func string__chomp(string) = string.
% string__chomp(String):
-% `String' minus any trailing newline characters; equivalent
-% to string__strip__suffix(pred('\n'::in) is semidet, String).
+% `String' minus any single trailing newline character.
-:- func string__strip_whitespace_prefix(string) = string.
-% string__strip_whitespace_prefix(String):
+:- func string__lstrip(string) = string.
+% string__lstrip(String):
% `String' minus any initial whitespace characters.
-:- func string__strip_whitespace_suffix(string) = string.
-% string__strip_whitespace_suffix(String):
+:- func string__rstrip(string) = string.
+% string__rstrip(String):
% `String' minus any trailing whitespace characters.
-:- func string__strip_surrounding_whitespace(string) = string.
-% string__strip_surrounding_whitespace(String):
-% `String' minus any whitespace prefix and suffix characters.
-
-:- func string__strip_prefix(pred(char), string) = string.
-:- mode string__strip_prefix(pred(in) is semidet, in ) = out is det.
-% string__strip_prefix(Pred, String):
+:- func string__strip(string) = string.
+% string__strip(String):
+% `String' minus any initial and trailing whitespace characters.
+
+:- func string__lstrip(pred(char), string) = string.
+:- mode string__lstrip(pred(in) is semidet, in ) = out is det.
+% string__lstrip(Pred, String):
% `String' minus the maximal prefix consisting entirely of
% chars satisfying `Pred'.
-:- func string__strip_suffix(pred(char), string) = string.
-:- mode string__strip_suffix(pred(in) is semidet, in ) = out is det.
-% string__strip_suffix(Pred, String):
+:- func string__rstrip(pred(char), string) = string.
+:- mode string__rstrip(pred(in) is semidet, in ) = out is det.
+% string__rstrip(Pred, String):
% `String' minus the maximal suffix consisting entirely of
% chars satisfying `Pred'.
@@ -3855,30 +3854,30 @@
%-----------------------------------------------------------------------------%
-chomp(S) = strip_suffix(pred('\n'::in) is semidet, S).
+chomp(S) = ( if index(S, length(S), '\n') then left(S, length(S) - 1) else S ).
%-----------------------------------------------------------------------------%
-strip_whitespace_suffix(S) = strip_suffix(is_whitespace, S).
+rstrip(S) = rstrip(is_whitespace, S).
%-----------------------------------------------------------------------------%
-strip_whitespace_prefix(S) = strip_prefix(is_whitespace, S).
+lstrip(S) = lstrip(is_whitespace, S).
%-----------------------------------------------------------------------------%
-strip_surrounding_whitespace(S0) = S :-
+strip(S0) = S :-
L = prefix_length(is_whitespace, S0),
R = suffix_length(is_whitespace, S0),
S = substring(S0, L, length(S0) - L - R).
%-----------------------------------------------------------------------------%
-strip_suffix(P, S) = substring(S, 0, length(S) - suffix_length(P, S)).
+rstrip(P, S) = left(S, length(S) - suffix_length(P, S)).
%-----------------------------------------------------------------------------%
-strip_prefix(P, S) = substring(S, 0, prefix_length(P, S)).
+lstrip(P, S) = right(S, length(S) - prefix_length(P, S)).
%-----------------------------------------------------------------------------%
@@ -3889,8 +3888,11 @@
:- mode prefix_length_2(in, in, pred(in ) is semidet, in) = out is det.
prefix_length_2(I, N, P, S) =
- ( if I < N, P(S ^ elem(I)) then prefix_length_2(I + 1, N, P, S)
- else I
+ ( if I < N % XXX We need ordered conjunction.
+ then ( if P(S ^ unsafe_elem(I)) then prefix_length_2(I + 1, N, P, S)
+ else I
+ )
+ else I
).
%-----------------------------------------------------------------------------%
@@ -3902,8 +3904,11 @@
:- mode suffix_length_2(in, in, pred(in ) is semidet, in) = out is det.
suffix_length_2(I, N, P, S) =
- ( if 0 =< I, P(S ^ elem(I)) then suffix_length_2(I - 1, N, P, S)
- else N - (I + 1)
+ ( if 0 =< I % XXX We need ordered conjunction.
+ then ( if P(S ^ unsafe_elem(I)) then suffix_length_2(I - 1, N, P, S)
+ else N - (I + 1)
+ )
+ else N - (I + 1)
).
only in patch2:
--- NEWS 27 Jan 2003 09:20:42 -0000 1.298
+++ NEWS 5 Feb 2003 01:04:21 -0000
@@ -16,7 +16,9 @@
with `mmc --make'.
Changes to the Mercury standard library:
-* Nothing yet.
+* Several new functions have been added to the string module, namely
+ elem/2, unsafe_elem/2, chomp/1, lstrip/1, lstrip/2, rstrip/1, rstrip/2,
+ strip/1, prefix_length/2, and suffix_length/2.
Portability improvements:
* Nothing yet.
@@ -60,6 +62,10 @@
chapter of the Mercury Language Reference Manual.
Changes to the Mercury standard library:
+
+* Several new functions have been added to the string module, namely
+ elem/2, unsafe_elem/2, chomp/1, lstrip/1, lstrip/2, rstrip/1, rstrip/2,
+ strip/1, prefix_length/2, and suffix_length/2.
* We've added a new library module, `array2d'.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list