[Ironruby-core] Forgetting MutableString

John Lam (IRONRUBY) jflam at microsoft.com
Thu May 8 12:22:53 EDT 2008


Peter Bacon Darwin:

> I keep forgetting to wrap up CLR strings in MutableStrings when
> returning strings retrieved from calls to .NET Framework library
> methods.

I finally understand what this is ... is this what you're looking for?

        public override bool Equals(object other) {
            if (other is MutableString)
                return Equals(other as MutableString);
            else if (other is string)
                return Equals(other as string);
            else
                return false;
        }

        public bool Equals(string other) {
            if (other == null) return false;
            if (_data.Length != other.Length) return false;

            for (int i = 0; i < _data.Length; ++i)
                if (_data[i] != other[i])
                    return false;

            return true;
        }

        public bool Equals(MutableString other) {
            if (ReferenceEquals(this, other)) return true;
            if (other == null) return false;
            if (_data.Length != other.Length) return false;

            for (int i = 0; i < _data.Length; ++i)
                if (_data[i] != other.Chars[i])
                    return false;

            return true;
        }

If so, it's coming in the next release.

Thanks,
-John



More information about the Ironruby-core mailing list