CheckMaxNesting() public method

public CheckMaxNesting ( int depth ) : void
depth int
return void
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
        }