[Mono-devel-list] Type.FilterName Fix
Jonathan Pryor
jonpryor at vt.edu
Wed Jan 19 07:15:34 EST 2005
On Wed, 2005-01-19 at 03:28 +0100, Willibald Krenn wrote:
> However, just as a quick hack:
>
> int filterLen = name.Length;
> if (name [filterLen] != "*")
> return name.Equals(m.Name);
> else
> return String.Compare (name, 0, m.Name, 0, filterLen-1, false,
> CultureInfo.InvariantCulture) == 0;
The problem with quick hacks is that they can be wrong. :-)
There's an off-by-one error: it should be ``name [filterLen-1] != '*'''.
And if the string is an empty string, you'll get an exception, so it
should really be:
if (name != null && name.Length > 0 &&
name [name.Length-1] != '*')
return name.Equals (m.Name);
return string.Compare (name, 0, m.Name, 0, name.Length-1, false,
CultureInfo.InvariantCulture) == 0;
And it may *still* be wrong (since I haven't actually tested it yet).
:-)
- Jon
More information about the Mono-devel-list
mailing list