[IronPython] In fix for strings
Brian Quinlan
brian at sweetapp.com
Sun Oct 10 13:52:08 CEST 2004
IronPython 0.6.0 doesn't support the "in" operator correctly for string
types. To demonstrate:
>>> 'abc' in 'abcd'
False
Here is my fix (sorry for the lack of a diff - I don't have access to
the original source right now).
Add to StringOps class:
public static bool Contains(string s, object o) {
if (o is string)
return s.IndexOf((string) o) != -1;
else
throw Ops.TypeError("requires string as left operand");
}
Add to Ops.In:
public static object In(object x, object y) {
if (y is string) {
return bool2object(StringOps.Contains((string) y, x));
} else if (y is IDictionary) {
...
Cheers,
Brian
More information about the Ironpython-users
mailing list