[m-rev.] diff: .NET back-end: another string__to_float fix

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Oct 22 16:15:13 AEST 2002


Estimated hours taken: 0.75
Branches: main

library/string.m:
	Fix another bug with the .NET version of string__to_float:
	fail if there is whitespace at the start or end of the string.

	(The test case tests/general/string_to_float still doesn't pass,
	but the remaining bug is a problem with string__format rather than
	string__to_float.)

Workspace: /home/ceres/fjh/mercury
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.179
diff -u -d -r1.179 string.m
--- library/string.m	21 Oct 2002 17:42:07 -0000	1.179
+++ library/string.m	22 Oct 2002 06:11:01 -0000
@@ -1862,14 +1862,21 @@
 :- pragma foreign_proc("MC++",
 	string__to_float(FloatString::in, FloatVal::out),
 		[will_not_call_mercury, promise_pure, thread_safe], "{
-	/*
-	** XXX should we also catch System::OverflowException?
-	*/
-	SUCCESS_INDICATOR = MR_TRUE;
-	try {
-	    FloatVal = System::Convert::ToDouble(FloatString);
-	} catch (System::FormatException *e) {
-	     SUCCESS_INDICATOR = MR_FALSE;
+	// leading or trailing whitespace is not allowed
+	if (System::Char::IsWhiteSpace(FloatString, 0) ||
+	    System::Char::IsWhiteSpace(FloatString, FloatString->Length - 1))
+	{
+	    SUCCESS_INDICATOR = MR_FALSE;
+	} else {
+	    /*
+	    ** XXX should we also catch System::OverflowException?
+	    */
+	    try {
+	        FloatVal = System::Convert::ToDouble(FloatString);
+	        SUCCESS_INDICATOR = MR_TRUE;
+	    } catch (System::FormatException *e) {
+	        SUCCESS_INDICATOR = MR_FALSE;
+	    }
 	}
 }").
 

-- 
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