[m-rev.] diff: .NET back-end: fix string__sub_string_search
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Feb 14 04:22:06 AEDT 2003
Estimated hours taken: 6
Branches: main
library/string.m:
Fix a bug in the MC++ definition of string__sub_string_search:
it was not setting SUCCESS_INDICATOR.
Also fix a bug in the Mercury definition of string__sub_string_search:
it was trying to match against the same position (the start of
the string) at every iteration of the loop.
Workspace: /home/fjh/ws/hermes
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.190
diff -u -d -r1.190 string.m
--- library/string.m 29 Nov 2002 13:25:56 -0000 1.190
+++ library/string.m 13 Feb 2003 17:19:28 -0000
@@ -463,7 +463,8 @@
:- mode string__sub_string_search(in, in, out) is semidet.
% string__sub_string_search(String, SubString, Index).
% `Index' is the position in `String' where the first occurrence of
-% `SubString' begins.
+% `SubString' begins. Indices start at zero, so if `SubString'
+% is a prefix of `String', this will return Index = 0.
:- func string__format(string, list(string__poly_type)) = string.
:- pred string__format(string, list(string__poly_type), string).
@@ -1262,25 +1263,35 @@
[will_not_call_mercury, promise_pure, thread_safe],
"{
Index = WholeString->IndexOf(SubString);
+ SUCCESS_INDICATOR = (Index >= 0);
}").
+% This is only used if there is no matching foreign_proc definition
string__sub_string_search(String, SubString, Index) :-
- sub_string_search_2(String, SubString, 0, length(String), Index).
+ sub_string_search_2(String, SubString, 0, length(String),
+ length(SubString), Index).
% Brute force string searching. For short Strings this is
% good; for longer strings Boyer-Moore is much better.
%
-:- pred sub_string_search_2(string::in, string::in, int::in, int::in,
+:- pred sub_string_search_2(string::in, string::in, int::in, int::in, int::in,
int::out) is semidet.
-sub_string_search_2(String, SubString, I, Length, Index) :-
+sub_string_search_2(String, SubString, I, Length, SubLength, Index) :-
( if
I < Length,
- string__prefix(String, SubString)
+ % XXX This is inefficient --
+ % there is no (in, in, in) = in is semidet
+ % mode of string__substring, so this ends up
+ % calling the (in, in, in) = out mode and then
+ % doing the unification. This will create a lot
+ % of unnecessary garbage.
+ string__substring(String, I, SubLength) = SubString
then
Index = I
else
- sub_string_search_2(String, SubString, I + 1, Length, Index)
+ sub_string_search_2(String, SubString, I + 1,
+ Length, SubLength, Index)
).
%-----------------------------------------------------------------------------%
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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