[m-rev.] diff: string splitting routines to string.m
Ondrej Bojar
obo at cuni.cz
Fri Feb 2 10:55:19 AEDT 2007
(May I commit this one?)
Estimated hours taken: 1.5
A few handy functions for splitting a string added.
library/string.m:
Added chomp/2, split_at_separator, split_at_char, split_at_string
tests/hard_coded/string_split.m:
A simple test of split_at_* functions.
tests/hard_coded/string_split.exp:
Expected results of the tests of split_at_* functions.
tests/hard_coded/string_strip.m:
Added testcase for chomp/2
tests/hard_coded/string_strip.exp:
Added results for chomp/2
tests/hard_coded/string_strip.exp2:
Removed the alternative expected result. (Don't know how to regenerate
this one.)
Index: library/string.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.254
diff -u -r1.254 string.m
--- library/string.m 18 Jan 2007 07:33:03 -0000 1.254
+++ library/string.m 1 Feb 2007 07:32:18 -0000
@@ -367,6 +367,11 @@
%
:- func string.chomp(string) = string.
+ % string.chomp(Tail, String):
+ % `String' minus `Tail' if `String' ends with `Tail', `String'
otherwise
+ %
+:- func string.chomp(string, string) = string.
+
% string.lstrip(String):
% `String' minus any initial whitespace characters.
%
@@ -555,6 +560,8 @@
% string.words_separator(char.is_whitespace, " the cat sat on the
mat") =
% ["the", "cat", "sat", "on", "the", "mat"]
%
+ % Note the difference to string.split_at_separator
+ %
:- func string.words_separator(pred(char), string) = list(string).
:- mode string.words_separator(pred(in) is semidet, in) = out is det.
@@ -563,6 +570,33 @@
%
:- func string.words(string) = list(string).
+ % string.split_at_separator(SepP, String) returns the list of
+ % substrings of String (in first to last order) that are delimited
+ % by chars matched by SepP. For example,
+ %
+ % string.split_at_separator(char.is_whitespace, " the cat sat on
the mat")
+ % = ["", "the", "cat", "", "sat", "on", "the", "", "mat"]
+ %
+ % Note the difference to string.words_separator
+ %
+:- func string.split_at_separator(pred(char), string) = list(string).
+:- mode string.split_at_separator(pred(in) is semidet, in) = out is det.
+
+ % string.split_at_char(Char, String) returns the list of substrings
+ % ("fields") of String as delimited by Char. For example,
+ %
+ % string.split_at_char('|', "|fld2|fld3") = ["", "fld2", [fld3"]
+ %
+:- func string.split_at_char(char, string) = list(string).
+
+ % string.split_at_string(Separator, String) returns the list of
substrings
+ % of String that are delimited by Separator. For example,
+ %
+ % string.split_at_string("|||", "|||fld2|||fld3")
+ % = ["", "fld2", [fld3"]
+ %
+:- func string.split_at_string(string, string) = list(string).
+
% string.split(String, Count, LeftSubstring, RightSubstring):
% `LeftSubstring' is the left-most `Count' characters of `String',
% and `RightSubstring' is the remainder of `String'.
@@ -4108,6 +4142,62 @@
%------------------------------------------------------------------------------%
+string.split_at_separator(DelimPred, InStr) = OutStrs :-
+ Count = string.length(InStr),
+ split_at_separator2(DelimPred, InStr, Count, Count, [], OutStrs).
+
+:- pred split_at_separator2(pred(char), string, int, int,
+ list(string), list(string)).
+:- mode split_at_separator2(pred(in) is semidet, in, in, in, in, out)
is det.
+split_at_separator2(DelimPred, Str, I, ThisSegEnd, ITail, OTail) :-
+ % walk Str backwards extending accumulated list of chunks as chars
+ % matching DelimPred are found
+ (
+ if I < 0
+ then % we're at the beginning
+ (
+ if ThisSegEnd<0
+ then OTail = ["" | ITail]
+ else
+ ThisSeg = string.unsafe_substring(Str, 0, ThisSegEnd+1),
+ OTail = [ThisSeg | ITail]
+ )
+ else
+ C = string.unsafe_index(Str, I),
+ (
+ if DelimPred(C)
+ then % chop here
+ ThisSeg = string.unsafe_substring(Str, I+1, ThisSegEnd-I),
+ TTail = [ ThisSeg | ITail ],
+ split_at_separator2(DelimPred, Str, I-1, I-1, TTail, OTail)
+ else % extend current segment
+ split_at_separator2(DelimPred, Str, I-1, ThisSegEnd, ITail,
OTail)
+ )
+ ).
+
+%------------------------------------------------------------------------------%
+
+string.split_at_char(C, String)
+ = string.split_at_separator((pred(X::in)is semidet:-X=C), String).
+
+%------------------------------------------------------------------------------%
+
+split_at_string(Needle, Total)
+ = split_at_string(0, length(Needle), Needle, Total).
+
+:- func split_at_string(int, int, string, string) = list(string).
+split_at_string(StartAt, NeedleLen, Needle, Total) = Out :-
+ if sub_string_search_start(Total, Needle, StartAt, NeedlePos)
+ then
+ BeforeNeedle = substring(Total, StartAt, NeedlePos-StartAt),
+ Tail = split_at_string(NeedlePos+NeedleLen, NeedleLen, Needle,
Total),
+ Out = [BeforeNeedle | Tail]
+ else
+ string__split(Total, StartAt, _skip, Last),
+ Out = [Last].
+
+%------------------------------------------------------------------------------%
+
% preceding_boundary(SepP, String, I) returns the largest index J =< I
% in String of the char that is SepP and min(-1, I) if there is no
such J.
% preceding_boundary/3 is intended for finding (in reverse)
consecutive
@@ -4154,6 +4244,13 @@
%-----------------------------------------------------------------------------%
+chomp(Suffix, In) = Out :-
+ if string__remove_suffix(In, Suffix, Prefix)
+ then Out = Prefix
+ else Out = In.
+
+%-----------------------------------------------------------------------------%
+
rstrip(S) = rstrip_pred(is_whitespace, S).
%-----------------------------------------------------------------------------%
Index: tests/hard_coded/string_split.exp
===================================================================
RCS file: tests/hard_coded/string_split.exp
diff -N tests/hard_coded/string_split.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/string_split.exp 1 Feb 2007 23:38:38 -0000
@@ -0,0 +1,4 @@
+hello:world:how:are:you!
+hello<tab>world<tab>how<tab>are<tab><tab>you!
+user<tab>group<tab>id1<tab>id2
+col1<tab>col2:val2<tab>col3<tab>
Index: tests/hard_coded/string_split.m
===================================================================
RCS file: tests/hard_coded/string_split.m
diff -N tests/hard_coded/string_split.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/string_split.m 1 Feb 2007 23:36:04 -0000
@@ -0,0 +1,28 @@
+:- module string_split.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module string, char.
+
+main(!IO) :-
+ io__write_list(
+ split_at_separator(char__is_upper, "helloXworldXhowXareYyou!"),
+ ":", io__write_string, !IO),
+ io__nl(!IO),
+ io__write_list(
+ split_at_separator(char__is_whitespace, "hello world\thow
are\t\tyou!"),
+ "<tab>", io__write_string, !IO),
+ io__nl(!IO),
+ io__write_list(
+ split_at_char(':', "user:group:id1:id2"),
+ "<tab>", io__write_string, !IO),
+ io__nl(!IO),
+ io__write_list(
+ split_at_string(":::", "col1:::col2:val2:::col3:::"),
+ "<tab>", io__write_string, !IO),
+ io__nl(!IO),
+ true.
Index: tests/hard_coded/string_strip.exp
===================================================================
RCS file:
/home/mercury/mercury1/repository/tests/hard_coded/string_strip.exp,v
retrieving revision 1.3
diff -u -r1.3 string_strip.exp
--- tests/hard_coded/string_strip.exp 20 Sep 2006 09:42:28 -0000 1.3
+++ tests/hard_coded/string_strip.exp 1 Feb 2007 07:06:47 -0000
@@ -46,6 +46,54 @@
chomp("\ \ foo") = "\ \ foo"
chomp("foo\ \ ") = "foo\ \ "
chomp("\ \ foo\ \ ") = "\ \ foo\ \ "
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\tfoo") = "\tfoo"
+chomp("\t\t")("foo\t") = "foo\t"
+chomp("\t\t")("\tfoo\t") = "\tfoo\t"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\nfoo") = "\nfoo"
+chomp("\t\t")("foo\n") = "foo\n"
+chomp("\t\t")("\nfoo\n") = "\nfoo\n"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\ foo") = "\ foo"
+chomp("\t\t")("foo\ ") = "foo\ "
+chomp("\t\t")("\ foo\ ") = "\ foo\ "
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\t\tfoo") = "\t\tfoo"
+chomp("\t\t")("foo\t\t") = "foo"
+chomp("\t\t")("\t\tfoo\t\t") = "\t\tfoo"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\t\nfoo") = "\t\nfoo"
+chomp("\t\t")("foo\t\n") = "foo\t\n"
+chomp("\t\t")("\t\nfoo\t\n") = "\t\nfoo\t\n"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\t\ foo") = "\t\ foo"
+chomp("\t\t")("foo\t\ ") = "foo\t\ "
+chomp("\t\t")("\t\ foo\t\ ") = "\t\ foo\t\ "
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\n\tfoo") = "\n\tfoo"
+chomp("\t\t")("foo\n\t") = "foo\n\t"
+chomp("\t\t")("\n\tfoo\n\t") = "\n\tfoo\n\t"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\n\nfoo") = "\n\nfoo"
+chomp("\t\t")("foo\n\n") = "foo\n\n"
+chomp("\t\t")("\n\nfoo\n\n") = "\n\nfoo\n\n"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\n\ foo") = "\n\ foo"
+chomp("\t\t")("foo\n\ ") = "foo\n\ "
+chomp("\t\t")("\n\ foo\n\ ") = "\n\ foo\n\ "
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\ \tfoo") = "\ \tfoo"
+chomp("\t\t")("foo\ \t") = "foo\ \t"
+chomp("\t\t")("\ \tfoo\ \t") = "\ \tfoo\ \t"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\ \nfoo") = "\ \nfoo"
+chomp("\t\t")("foo\ \n") = "foo\ \n"
+chomp("\t\t")("\ \nfoo\ \n") = "\ \nfoo\ \n"
+chomp("\t\t")("foo") = "foo"
+chomp("\t\t")("\ \ foo") = "\ \ foo"
+chomp("\t\t")("foo\ \ ") = "foo\ \ "
+chomp("\t\t")("\ \ foo\ \ ") = "\ \ foo\ \ "
lstrip("foo") = "foo"
lstrip("\tfoo") = "foo"
lstrip("foo\t") = "foo\t"
Index: tests/hard_coded/string_strip.exp2
===================================================================
RCS file: tests/hard_coded/string_strip.exp2
diff -N tests/hard_coded/string_strip.exp2
--- tests/hard_coded/string_strip.exp2 26 Oct 2003 12:43:33 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,384 +0,0 @@
-chomp("foo") = "foo"
-chomp("\ foo") = "\ foo"
-chomp("foo\ ") = "foo\ "
-chomp("\ foo\ ") = "\ foo\ "
-chomp("foo") = "foo"
-chomp("\tfoo") = "\tfoo"
-chomp("foo\t") = "foo\t"
-chomp("\tfoo\t") = "\tfoo\t"
-chomp("foo") = "foo"
-chomp("\nfoo") = "\nfoo"
-chomp("foo\n") = "foo"
-chomp("\nfoo\n") = "\nfoo"
-chomp("foo") = "foo"
-chomp("\ \ foo") = "\ \ foo"
-chomp("foo\ \ ") = "foo\ \ "
-chomp("\ \ foo\ \ ") = "\ \ foo\ \ "
-chomp("foo") = "foo"
-chomp("\ \tfoo") = "\ \tfoo"
-chomp("foo\ \t") = "foo\ \t"
-chomp("\ \tfoo\ \t") = "\ \tfoo\ \t"
-chomp("foo") = "foo"
-chomp("\ \nfoo") = "\ \nfoo"
-chomp("foo\ \n") = "foo\ "
-chomp("\ \nfoo\ \n") = "\ \nfoo\ "
-chomp("foo") = "foo"
-chomp("\t\ foo") = "\t\ foo"
-chomp("foo\t\ ") = "foo\t\ "
-chomp("\t\ foo\t\ ") = "\t\ foo\t\ "
-chomp("foo") = "foo"
-chomp("\t\tfoo") = "\t\tfoo"
-chomp("foo\t\t") = "foo\t\t"
-chomp("\t\tfoo\t\t") = "\t\tfoo\t\t"
-chomp("foo") = "foo"
-chomp("\t\nfoo") = "\t\nfoo"
-chomp("foo\t\n") = "foo\t"
-chomp("\t\nfoo\t\n") = "\t\nfoo\t"
-chomp("foo") = "foo"
-chomp("\n\ foo") = "\n\ foo"
-chomp("foo\n\ ") = "foo\n\ "
-chomp("\n\ foo\n\ ") = "\n\ foo\n\ "
-chomp("foo") = "foo"
-chomp("\n\tfoo") = "\n\tfoo"
-chomp("foo\n\t") = "foo\n\t"
-chomp("\n\tfoo\n\t") = "\n\tfoo\n\t"
-chomp("foo") = "foo"
-chomp("\n\nfoo") = "\n\nfoo"
-chomp("foo\n\n") = "foo\n"
-chomp("\n\nfoo\n\n") = "\n\nfoo\n"
-lstrip("foo") = "foo"
-lstrip("\ foo") = "foo"
-lstrip("foo\ ") = "foo\ "
-lstrip("\ foo\ ") = "foo\ "
-lstrip("foo") = "foo"
-lstrip("\tfoo") = "foo"
-lstrip("foo\t") = "foo\t"
-lstrip("\tfoo\t") = "foo\t"
-lstrip("foo") = "foo"
-lstrip("\nfoo") = "foo"
-lstrip("foo\n") = "foo\n"
-lstrip("\nfoo\n") = "foo\n"
-lstrip("foo") = "foo"
-lstrip("\ \ foo") = "foo"
-lstrip("foo\ \ ") = "foo\ \ "
-lstrip("\ \ foo\ \ ") = "foo\ \ "
-lstrip("foo") = "foo"
-lstrip("\ \tfoo") = "foo"
-lstrip("foo\ \t") = "foo\ \t"
-lstrip("\ \tfoo\ \t") = "foo\ \t"
-lstrip("foo") = "foo"
-lstrip("\ \nfoo") = "foo"
-lstrip("foo\ \n") = "foo\ \n"
-lstrip("\ \nfoo\ \n") = "foo\ \n"
-lstrip("foo") = "foo"
-lstrip("\t\ foo") = "foo"
-lstrip("foo\t\ ") = "foo\t\ "
-lstrip("\t\ foo\t\ ") = "foo\t\ "
-lstrip("foo") = "foo"
-lstrip("\t\tfoo") = "foo"
-lstrip("foo\t\t") = "foo\t\t"
-lstrip("\t\tfoo\t\t") = "foo\t\t"
-lstrip("foo") = "foo"
-lstrip("\t\nfoo") = "foo"
-lstrip("foo\t\n") = "foo\t\n"
-lstrip("\t\nfoo\t\n") = "foo\t\n"
-lstrip("foo") = "foo"
-lstrip("\n\ foo") = "foo"
-lstrip("foo\n\ ") = "foo\n\ "
-lstrip("\n\ foo\n\ ") = "foo\n\ "
-lstrip("foo") = "foo"
-lstrip("\n\tfoo") = "foo"
-lstrip("foo\n\t") = "foo\n\t"
-lstrip("\n\tfoo\n\t") = "foo\n\t"
-lstrip("foo") = "foo"
-lstrip("\n\nfoo") = "foo"
-lstrip("foo\n\n") = "foo\n\n"
-lstrip("\n\nfoo\n\n") = "foo\n\n"
-rstrip("foo") = "foo"
-rstrip("\ foo") = "\ foo"
-rstrip("foo\ ") = "foo"
-rstrip("\ foo\ ") = "\ foo"
-rstrip("foo") = "foo"
-rstrip("\tfoo") = "\tfoo"
-rstrip("foo\t") = "foo"
-rstrip("\tfoo\t") = "\tfoo"
-rstrip("foo") = "foo"
-rstrip("\nfoo") = "\nfoo"
-rstrip("foo\n") = "foo"
-rstrip("\nfoo\n") = "\nfoo"
-rstrip("foo") = "foo"
-rstrip("\ \ foo") = "\ \ foo"
-rstrip("foo\ \ ") = "foo"
-rstrip("\ \ foo\ \ ") = "\ \ foo"
-rstrip("foo") = "foo"
-rstrip("\ \tfoo") = "\ \tfoo"
-rstrip("foo\ \t") = "foo"
-rstrip("\ \tfoo\ \t") = "\ \tfoo"
-rstrip("foo") = "foo"
-rstrip("\ \nfoo") = "\ \nfoo"
-rstrip("foo\ \n") = "foo"
-rstrip("\ \nfoo\ \n") = "\ \nfoo"
-rstrip("foo") = "foo"
-rstrip("\t\ foo") = "\t\ foo"
-rstrip("foo\t\ ") = "foo"
-rstrip("\t\ foo\t\ ") = "\t\ foo"
-rstrip("foo") = "foo"
-rstrip("\t\tfoo") = "\t\tfoo"
-rstrip("foo\t\t") = "foo"
-rstrip("\t\tfoo\t\t") = "\t\tfoo"
-rstrip("foo") = "foo"
-rstrip("\t\nfoo") = "\t\nfoo"
-rstrip("foo\t\n") = "foo"
-rstrip("\t\nfoo\t\n") = "\t\nfoo"
-rstrip("foo") = "foo"
-rstrip("\n\ foo") = "\n\ foo"
-rstrip("foo\n\ ") = "foo"
-rstrip("\n\ foo\n\ ") = "\n\ foo"
-rstrip("foo") = "foo"
-rstrip("\n\tfoo") = "\n\tfoo"
-rstrip("foo\n\t") = "foo"
-rstrip("\n\tfoo\n\t") = "\n\tfoo"
-rstrip("foo") = "foo"
-rstrip("\n\nfoo") = "\n\nfoo"
-rstrip("foo\n\n") = "foo"
-rstrip("\n\nfoo\n\n") = "\n\nfoo"
-strip("foo") = "foo"
-strip("\ foo") = "foo"
-strip("foo\ ") = "foo"
-strip("\ foo\ ") = "foo"
-strip("foo") = "foo"
-strip("\tfoo") = "foo"
-strip("foo\t") = "foo"
-strip("\tfoo\t") = "foo"
-strip("foo") = "foo"
-strip("\nfoo") = "foo"
-strip("foo\n") = "foo"
-strip("\nfoo\n") = "foo"
-strip("foo") = "foo"
-strip("\ \ foo") = "foo"
-strip("foo\ \ ") = "foo"
-strip("\ \ foo\ \ ") = "foo"
-strip("foo") = "foo"
-strip("\ \tfoo") = "foo"
-strip("foo\ \t") = "foo"
-strip("\ \tfoo\ \t") = "foo"
-strip("foo") = "foo"
-strip("\ \nfoo") = "foo"
-strip("foo\ \n") = "foo"
-strip("\ \nfoo\ \n") = "foo"
-strip("foo") = "foo"
-strip("\t\ foo") = "foo"
-strip("foo\t\ ") = "foo"
-strip("\t\ foo\t\ ") = "foo"
-strip("foo") = "foo"
-strip("\t\tfoo") = "foo"
-strip("foo\t\t") = "foo"
-strip("\t\tfoo\t\t") = "foo"
-strip("foo") = "foo"
-strip("\t\nfoo") = "foo"
-strip("foo\t\n") = "foo"
-strip("\t\nfoo\t\n") = "foo"
-strip("foo") = "foo"
-strip("\n\ foo") = "foo"
-strip("foo\n\ ") = "foo"
-strip("\n\ foo\n\ ") = "foo"
-strip("foo") = "foo"
-strip("\n\tfoo") = "foo"
-strip("foo\n\t") = "foo"
-strip("\n\tfoo\n\t") = "foo"
-strip("foo") = "foo"
-strip("\n\nfoo") = "foo"
-strip("foo\n\n") = "foo"
-strip("\n\nfoo\n\n") = "foo"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\ foo") = "\ foo"
-lstrip(is_alpha)("foo\ ") = "\ "
-lstrip(is_alpha)("\ foo\ ") = "\ foo\ "
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\tfoo") = "\tfoo"
-lstrip(is_alpha)("foo\t") = "\t"
-lstrip(is_alpha)("\tfoo\t") = "\tfoo\t"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\nfoo") = "\nfoo"
-lstrip(is_alpha)("foo\n") = "\n"
-lstrip(is_alpha)("\nfoo\n") = "\nfoo\n"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\ \ foo") = "\ \ foo"
-lstrip(is_alpha)("foo\ \ ") = "\ \ "
-lstrip(is_alpha)("\ \ foo\ \ ") = "\ \ foo\ \ "
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\ \tfoo") = "\ \tfoo"
-lstrip(is_alpha)("foo\ \t") = "\ \t"
-lstrip(is_alpha)("\ \tfoo\ \t") = "\ \tfoo\ \t"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\ \nfoo") = "\ \nfoo"
-lstrip(is_alpha)("foo\ \n") = "\ \n"
-lstrip(is_alpha)("\ \nfoo\ \n") = "\ \nfoo\ \n"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\t\ foo") = "\t\ foo"
-lstrip(is_alpha)("foo\t\ ") = "\t\ "
-lstrip(is_alpha)("\t\ foo\t\ ") = "\t\ foo\t\ "
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\t\tfoo") = "\t\tfoo"
-lstrip(is_alpha)("foo\t\t") = "\t\t"
-lstrip(is_alpha)("\t\tfoo\t\t") = "\t\tfoo\t\t"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\t\nfoo") = "\t\nfoo"
-lstrip(is_alpha)("foo\t\n") = "\t\n"
-lstrip(is_alpha)("\t\nfoo\t\n") = "\t\nfoo\t\n"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\n\ foo") = "\n\ foo"
-lstrip(is_alpha)("foo\n\ ") = "\n\ "
-lstrip(is_alpha)("\n\ foo\n\ ") = "\n\ foo\n\ "
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\n\tfoo") = "\n\tfoo"
-lstrip(is_alpha)("foo\n\t") = "\n\t"
-lstrip(is_alpha)("\n\tfoo\n\t") = "\n\tfoo\n\t"
-lstrip(is_alpha)("foo") = ""
-lstrip(is_alpha)("\n\nfoo") = "\n\nfoo"
-lstrip(is_alpha)("foo\n\n") = "\n\n"
-lstrip(is_alpha)("\n\nfoo\n\n") = "\n\nfoo\n\n"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\ foo") = "\ "
-rstrip(is_alpha)("foo\ ") = "foo\ "
-rstrip(is_alpha)("\ foo\ ") = "\ foo\ "
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\tfoo") = "\t"
-rstrip(is_alpha)("foo\t") = "foo\t"
-rstrip(is_alpha)("\tfoo\t") = "\tfoo\t"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\nfoo") = "\n"
-rstrip(is_alpha)("foo\n") = "foo\n"
-rstrip(is_alpha)("\nfoo\n") = "\nfoo\n"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\ \ foo") = "\ \ "
-rstrip(is_alpha)("foo\ \ ") = "foo\ \ "
-rstrip(is_alpha)("\ \ foo\ \ ") = "\ \ foo\ \ "
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\ \tfoo") = "\ \t"
-rstrip(is_alpha)("foo\ \t") = "foo\ \t"
-rstrip(is_alpha)("\ \tfoo\ \t") = "\ \tfoo\ \t"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\ \nfoo") = "\ \n"
-rstrip(is_alpha)("foo\ \n") = "foo\ \n"
-rstrip(is_alpha)("\ \nfoo\ \n") = "\ \nfoo\ \n"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\t\ foo") = "\t\ "
-rstrip(is_alpha)("foo\t\ ") = "foo\t\ "
-rstrip(is_alpha)("\t\ foo\t\ ") = "\t\ foo\t\ "
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\t\tfoo") = "\t\t"
-rstrip(is_alpha)("foo\t\t") = "foo\t\t"
-rstrip(is_alpha)("\t\tfoo\t\t") = "\t\tfoo\t\t"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\t\nfoo") = "\t\n"
-rstrip(is_alpha)("foo\t\n") = "foo\t\n"
-rstrip(is_alpha)("\t\nfoo\t\n") = "\t\nfoo\t\n"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\n\ foo") = "\n\ "
-rstrip(is_alpha)("foo\n\ ") = "foo\n\ "
-rstrip(is_alpha)("\n\ foo\n\ ") = "\n\ foo\n\ "
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\n\tfoo") = "\n\t"
-rstrip(is_alpha)("foo\n\t") = "foo\n\t"
-rstrip(is_alpha)("\n\tfoo\n\t") = "\n\tfoo\n\t"
-rstrip(is_alpha)("foo") = ""
-rstrip(is_alpha)("\n\nfoo") = "\n\n"
-rstrip(is_alpha)("foo\n\n") = "foo\n\n"
-rstrip(is_alpha)("\n\nfoo\n\n") = "\n\nfoo\n\n"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\ foo") = "1"
-prefix_length(is_whitespace)("foo\ ") = "0"
-prefix_length(is_whitespace)("\ foo\ ") = "1"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\tfoo") = "1"
-prefix_length(is_whitespace)("foo\t") = "0"
-prefix_length(is_whitespace)("\tfoo\t") = "1"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\nfoo") = "1"
-prefix_length(is_whitespace)("foo\n") = "0"
-prefix_length(is_whitespace)("\nfoo\n") = "1"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\ \ foo") = "2"
-prefix_length(is_whitespace)("foo\ \ ") = "0"
-prefix_length(is_whitespace)("\ \ foo\ \ ") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\ \tfoo") = "2"
-prefix_length(is_whitespace)("foo\ \t") = "0"
-prefix_length(is_whitespace)("\ \tfoo\ \t") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\ \nfoo") = "2"
-prefix_length(is_whitespace)("foo\ \n") = "0"
-prefix_length(is_whitespace)("\ \nfoo\ \n") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\t\ foo") = "2"
-prefix_length(is_whitespace)("foo\t\ ") = "0"
-prefix_length(is_whitespace)("\t\ foo\t\ ") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\t\tfoo") = "2"
-prefix_length(is_whitespace)("foo\t\t") = "0"
-prefix_length(is_whitespace)("\t\tfoo\t\t") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\t\nfoo") = "2"
-prefix_length(is_whitespace)("foo\t\n") = "0"
-prefix_length(is_whitespace)("\t\nfoo\t\n") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\n\ foo") = "2"
-prefix_length(is_whitespace)("foo\n\ ") = "0"
-prefix_length(is_whitespace)("\n\ foo\n\ ") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\n\tfoo") = "2"
-prefix_length(is_whitespace)("foo\n\t") = "0"
-prefix_length(is_whitespace)("\n\tfoo\n\t") = "2"
-prefix_length(is_whitespace)("foo") = "0"
-prefix_length(is_whitespace)("\n\nfoo") = "2"
-prefix_length(is_whitespace)("foo\n\n") = "0"
-prefix_length(is_whitespace)("\n\nfoo\n\n") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\ foo") = "0"
-suffix_length(is_whitespace)("foo\ ") = "1"
-suffix_length(is_whitespace)("\ foo\ ") = "1"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\tfoo") = "0"
-suffix_length(is_whitespace)("foo\t") = "1"
-suffix_length(is_whitespace)("\tfoo\t") = "1"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\nfoo") = "0"
-suffix_length(is_whitespace)("foo\n") = "1"
-suffix_length(is_whitespace)("\nfoo\n") = "1"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\ \ foo") = "0"
-suffix_length(is_whitespace)("foo\ \ ") = "2"
-suffix_length(is_whitespace)("\ \ foo\ \ ") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\ \tfoo") = "0"
-suffix_length(is_whitespace)("foo\ \t") = "2"
-suffix_length(is_whitespace)("\ \tfoo\ \t") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\ \nfoo") = "0"
-suffix_length(is_whitespace)("foo\ \n") = "2"
-suffix_length(is_whitespace)("\ \nfoo\ \n") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\t\ foo") = "0"
-suffix_length(is_whitespace)("foo\t\ ") = "2"
-suffix_length(is_whitespace)("\t\ foo\t\ ") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\t\tfoo") = "0"
-suffix_length(is_whitespace)("foo\t\t") = "2"
-suffix_length(is_whitespace)("\t\tfoo\t\t") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\t\nfoo") = "0"
-suffix_length(is_whitespace)("foo\t\n") = "2"
-suffix_length(is_whitespace)("\t\nfoo\t\n") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\n\ foo") = "0"
-suffix_length(is_whitespace)("foo\n\ ") = "2"
-suffix_length(is_whitespace)("\n\ foo\n\ ") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\n\tfoo") = "0"
-suffix_length(is_whitespace)("foo\n\t") = "2"
-suffix_length(is_whitespace)("\n\tfoo\n\t") = "2"
-suffix_length(is_whitespace)("foo") = "0"
-suffix_length(is_whitespace)("\n\nfoo") = "0"
-suffix_length(is_whitespace)("foo\n\n") = "2"
-suffix_length(is_whitespace)("\n\nfoo\n\n") = "2"
Index: tests/hard_coded/string_strip.m
===================================================================
RCS file:
/home/mercury/mercury1/repository/tests/hard_coded/string_strip.m,v
retrieving revision 1.4
diff -u -r1.4 string_strip.m
--- tests/hard_coded/string_strip.m 20 Sep 2006 09:42:28 -0000 1.4
+++ tests/hard_coded/string_strip.m 1 Feb 2007 07:03:02 -0000
@@ -56,6 +56,9 @@
"chomp" -
chomp,
+ "chomp(""\\t\\t"")" -
+ chomp("\t\t"),
+
"lstrip" -
lstrip,
--
Ondrej Bojar (mailto:obo at cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list