[Mono-list] String.Trim patch

Bob Smith bob@thestuff.net
Fri, 4 Jan 2002 14:38:35 -0500 (EST)


Yours fixes some of it, but my patch did two other things.
1. the matches check in the for loop happens after the end/begining is
incremented/decremented. This is not always correct.
2. I reworked it to be slightly faster.

I'll just put up the full file at:
http://www.thestuff.net/temp/String.cs

On 4 Jan 2002, Jeffrey Stedfast wrote:

> Bob,
>
> I wasn't able to apply your patch after several minutes of futzing
> around with it (apparently enough changed between 1.25 and 1.27 to make
> applying the patch a nightmare ;-)
>
> Anyways, I looked over the main differences that your code changed and
> think that the following patch fixes the same things that you were
> aiming to fix with your patch but also fixes the last of the brokenness
> that you were talking about that still existed after your patch had been
> applied (I hope?).
>
> I'm about to apply this to CVS because it certainly does fix some logic
> mistakes that I had made (shame on me!). Could you let me know if it
> also fixes the problems you were trying to fix?
>
> Thanks,
>
> Jeff
>
> Index: String.cs
> ===================================================================
> RCS file: /cvs/public/mcs/class/corlib/System/String.cs,v
> diff -u -r1.27 String.cs
> --- String.cs	2002/01/04 09:47:24	1.27
> +++ String.cs	2002/01/04 13:37:41
> @@ -1576,7 +1576,7 @@
>  			}
>
>  			matches = true;
> -			for (end = this.length-1; end > begin; end--) {
> +			for (end = this.length - 1; matches && end > begin; end--) {
>  				if (trimChars != null) {
>  					matches = false;
>  					foreach (char c in trimChars) {
> @@ -1589,7 +1589,7 @@
>  				}
>  			}
>
> -			if (begin == end)
> +			if (begin >= end)
>  				return String.Empty;
>
>  			return Substring (begin, end - begin);
>
>
> On Fri, 2002-01-04 at 04:00, Bob Smith wrote:
> > The Trim method contained bugs that prevent mcs from working from mint (it
> > still doesnt work with the patch, but it is closer to working) so I have
> > reworked the method so that it should work better. Could you have a look
> > at it and see if its commit worthy?
> >
> > http://www.thestuff.net/temp/String.diff
> >
> > Thanks,
> > Bob
> >
> >
> > _______________________________________________
> > Mono-list maillist  -  Mono-list@ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
> --
> Jeffrey Stedfast
> Evolution Hacker - Ximian, Inc.
> fejj@ximian.com  - www.ximian.com
>