Forget() public method

public Forget ( RubyContext context, Object obj ) : bool
context RubyContext
obj Object
return bool
Beispiel #1
0
        public static MutableString ToJson(ConversionStorage <MutableString> toS, IDictionary self, GeneratorState state, int?depth)
        {
            MutableString result;
            RubyContext   context = toS.Context;

            if (state == null)
            {
                MutableString json;
                result = MutableString.CreateMutable(2 + Math.Max(self.Count * 12, 0), RubyEncoding.Default);

                result.Append('{');
                if (self.Count > 0)
                {
                    int i = 0;
                    foreach (DictionaryEntry kv in self)
                    {
                        // TODO: added state and depth
                        json = Generator.ToJson(context, Protocols.ConvertToString(toS, kv.Key), null, 0);
                        result.Append(json);
                        context.TaintObjectBy <Object>(result, json);

                        result.Append(':');

                        json = Generator.ToJson(context, kv.Value, null, 0);
                        result.Append(json);
                        context.TaintObjectBy <Object>(result, json);

                        if (++i < self.Count)
                        {
                            result.Append(',');
                        }
                    }
                }
                result.Append('}');
            }
            else
            {
                GeneratorState.Ensure(state);
                if (state.CheckCircular)
                {
                    if (state.Seen(context, self))
                    {
                        Helpers.ThrowCircularDataStructureException("circular data structures not supported!");
                    }
                    state.Remember(context, self);
                    result = Transform(toS, self, state, depth.HasValue ? depth.Value : 0);
                    state.Forget(context, self);
                }
                else
                {
                    result = Transform(toS, self, state, depth.HasValue ? depth.Value : 0);
                }
            }

            return(result);
        }
Beispiel #2
0
        public static MutableString ToJson(ConversionStorage<MutableString> toS, IDictionary self, GeneratorState state, int? depth)
        {
            MutableString result;
            RubyContext context = toS.Context;

            if (state == null) {
                MutableString json;
                result = MutableString.CreateMutable(2 + Math.Max(self.Count * 12, 0), RubyEncoding.Default);

                result.Append('{');
                if (self.Count > 0) {
                    int i = 0;
                    foreach (DictionaryEntry kv in self) {
                        // TODO: added state and depth
                        json = Generator.ToJson(context, Protocols.ConvertToString(toS, kv.Key), null, 0);
                        result.Append(json);
                        context.TaintObjectBy<Object>(result, json);

                        result.Append(':');

                        json = Generator.ToJson(context, kv.Value, null, 0);
                        result.Append(json);
                        context.TaintObjectBy<Object>(result, json);

                        if (++i < self.Count) {
                            result.Append(',');
                        }
                    }
                }
                result.Append('}');
            }
            else {
                GeneratorState.Ensure(state);
                if (state.CheckCircular) {
                    if (state.Seen(context, self)) {
                        Helpers.ThrowCircularDataStructureException("circular data structures not supported!");
                    }
                    state.Remember(context, self);
                    result = Transform(toS, self, state, depth.HasValue ? depth.Value : 0);
                    state.Forget(context, self);
                }
                else {
                    result = Transform(toS, self, state, depth.HasValue ? depth.Value : 0);
                }
            }

            return result;
        }
        private static MutableString Transform(RubyContext context, IList self, GeneratorState state, int depth)
        {
            MutableString result = MutableString.CreateMutable(2 + Math.Max(self.Count * 4, 0), RubyEncoding.UTF8);

            byte[] indentUnit = state.Indent.ToByteArray();
            byte[] shift      = Helpers.Repeat(indentUnit, depth + 1);
            byte[] arrayNl    = state.ArrayNl.ToByteArray();
            byte[] delim      = new byte[1 + arrayNl.Length];
            delim[0] = (byte)',';
            Array.Copy(arrayNl, 0, delim, 1, arrayNl.Length);

            state.CheckMaxNesting(depth + 1);
            context.TaintObjectBy <Object>(result, self);

            if (state.CheckCircular)
            {
                state.Remember(context, self);
                result.Append('[');
                result.Append(arrayNl);
                if (self.Count > 0)
                {
                    for (int i = 0; i < self.Count; i++)
                    {
                        Object element = self[i];
                        if (state.Seen(context, element))
                        {
                            Helpers.ThrowCircularDataStructureException("circular data structures not supported!");
                        }
                        context.TaintObjectBy <Object>(result, element);
                        if (i > 0)
                        {
                            result.Append(delim);
                        }
                        result.Append(shift);
                        result.Append(Generator.ToJson(context, element, state, depth + 1));
                    }

                    // TODO: this might be needed outside of the count check for compat
                    if (arrayNl.Length != 0)
                    {
                        result.Append(arrayNl);
                        result.Append(shift, 0, depth * indentUnit.Length);
                    }
                }
                result.Append(']');
                state.Forget(context, self);
            }
            else
            {
                result.Append('[');
                result.Append(arrayNl);
                if (self.Count > 0)
                {
                    for (int i = 0; i < self.Count; i++)
                    {
                        Object element = self[i];
                        context.TaintObjectBy <Object>(result, element);
                        if (i > 0)
                        {
                            result.Append(delim);
                        }
                        result.Append(shift);
                        result.Append(Generator.ToJson(context, element, state, depth + 1));
                    }

                    // TODO: this might be needed outside of the count check for compatibility
                    if (arrayNl.Length != 0)
                    {
                        result.Append(arrayNl);
                        result.Append(shift, 0, depth * indentUnit.Length);
                    }
                }
                result.Append(']');
            }

            return(result);
        }
Beispiel #4
0
        private static MutableString Transform(RubyContext context, IList self, GeneratorState state, int depth)
        {
            MutableString result = MutableString.CreateMutable(2 + Math.Max(self.Count * 4, 0), RubyEncoding.UTF8);

            byte[] indentUnit = state.Indent.ToByteArray();
            byte[] shift = Helpers.Repeat(indentUnit, depth + 1);
            byte[] arrayNl = state.ArrayNl.ToByteArray();
            byte[] delim = new byte[1 + arrayNl.Length];
            delim[0] = (byte)',';
            Array.Copy(arrayNl, 0, delim, 1, arrayNl.Length);

            state.CheckMaxNesting(depth + 1);
            context.TaintObjectBy<Object>(result, self);

            if (state.CheckCircular) {
                state.Remember(context, self);
                result.Append('[');
                result.Append(arrayNl);
                if (self.Count > 0) {
                    for (int i = 0; i < self.Count; i++) {
                        Object element = self[i];
                        if (state.Seen(context, element)) {
                            Helpers.ThrowCircularDataStructureException("circular data structures not supported!");
                        }
                        context.TaintObjectBy<Object>(result, element);
                        if (i > 0) {
                            result.Append(delim);
                        }
                        result.Append(shift);
                        result.Append(Generator.ToJson(context, element, state, depth + 1));
                    }

                    // TODO: this might be needed outside of the count check for compat
                    if (arrayNl.Length != 0) {
                        result.Append(arrayNl);
                        result.Append(shift, 0, depth * indentUnit.Length);
                    }
                }
                result.Append(']');
                state.Forget(context, self);
            }
            else {
                result.Append('[');
                result.Append(arrayNl);
                if (self.Count > 0) {
                    for (int i = 0; i < self.Count; i++) {
                        Object element = self[i];
                        context.TaintObjectBy<Object>(result, element);
                        if (i > 0) {
                            result.Append(delim);
                        }
                        result.Append(shift);
                        result.Append(Generator.ToJson(context, element, state, depth + 1));
                    }

                    // TODO: this might be needed outside of the count check for compatibility
                    if (arrayNl.Length != 0) {
                        result.Append(arrayNl);
                        result.Append(shift, 0, depth * indentUnit.Length);
                    }
                }
                result.Append(']');
            }

            return result;
        }
Beispiel #5
0
 public static Object AForget(RubyContext context, GeneratorState self, Object obj)
 {
     return self.Forget(context, obj) ? true : null as Object;
 }
 public static Object AForget(RubyContext context, GeneratorState self, Object obj)
 {
     return(self.Forget(context, obj) ? true : null as Object);
 }