public static MutableString ToJson(RubyContext context, IList self, GeneratorState state, int? depth) { MutableString result; if (state == null) { result = MutableString.CreateMutable(2 + Math.Max(self.Count * 4, 0), RubyEncoding.UTF8); result.Append('['); context.TaintObjectBy<Object>(result, self); if (self.Count > 0) { for (int i = 0; i < self.Count; i++) { Object element = self[i]; result.Append(Generator.ToJson(context, element, null, 0)); context.TaintObjectBy<Object>(result, element); if (i < self.Count - 1) { result.Append(','); } } } result.Append(']'); } else { result = Transform(context, self, state, depth.HasValue ? depth.Value : 0); } return context.TaintObjectBy<MutableString>(result, self); }
public static MutableString ToJson(RubyContext context, IList self, GeneratorState state, int?depth) { MutableString result; if (state == null) { result = MutableString.CreateMutable(2 + Math.Max(self.Count * 4, 0), RubyEncoding.UTF8); result.Append('['); context.TaintObjectBy <Object>(result, self); if (self.Count > 0) { for (int i = 0; i < self.Count; i++) { Object element = self[i]; result.Append(Generator.ToJson(context, element, null, 0)); context.TaintObjectBy <Object>(result, element); if (i < self.Count - 1) { result.Append(','); } } } result.Append(']'); } else { result = Transform(context, self, state, depth.HasValue ? depth.Value : 0); } return(context.TaintObjectBy <MutableString>(result, self)); }
public static GeneratorState Reinitialize(RubyContext context, GeneratorState self, Hash configuration) { if (configuration != null) { GeneratorState.Configure(context, self, configuration); } return(self); }
public static GeneratorState CreateGeneratorState(RubyClass/*!*/ self, [Optional]Hash configuration) { GeneratorState state = new GeneratorState(); if (configuration != null) { Reinitialize(self.Context, state, configuration); } return state; }
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); }
public static GeneratorState /*!*/ CreateGeneratorState(RubyClass /*!*/ self, [Optional] Hash configuration) { GeneratorState state = new GeneratorState(); if (configuration != null) { Reinitialize(self.Context, state, configuration); } return(state); }
private static MutableString Transform(ConversionStorage<MutableString> toS, IDictionary self, GeneratorState state, int depth) { byte[] objectNl = state.ObjectNl.ToByteArray(); byte[] indent = Helpers.Repeat(state.Indent.ToByteArray(), depth + 1); byte[] spaceBefore = state.SpaceBefore.ToByteArray(); byte[] space = state.Space.ToByteArray(); int subDepth = depth + 1; MutableString result = MutableString.CreateBinary(2 + self.Count * (12 + indent.Length + spaceBefore.Length + space.Length)); RubyContext context = toS.Context; result.Append((byte)'{'); result.Append(objectNl); if (self.Count > 0) { MutableString json; int i = 0; foreach (DictionaryEntry kv in self) { if (i > 0) { result.Append(objectNl); } if (objectNl.Length != 0) { result.Append(indent); } json = Generator.ToJson(context, Protocols.ConvertToString(toS, kv.Key), state, subDepth); result.Append(json); context.TaintObjectBy<Object>(result, json); result.Append(spaceBefore); result.Append((byte)':'); result.Append(space); json = Generator.ToJson(context, kv.Value, state, subDepth); result.Append(json); context.TaintObjectBy<Object>(result, json); if (++i < self.Count) { result.Append(','); } } if (objectNl.Length != 0) { result.Append(objectNl); if (indent.Length != 0) { for (int n = 0; n < depth; n++) { result.Append(indent); } } } } result.Append((byte)'}'); return result; }
public static MutableString ToJson(Double self, GeneratorState state) { if (Double.IsInfinity(self) || Double.IsNaN(self)) { if (state != null && state.AllowNaN == false) { Helpers.ThrowGenerateException(String.Format("{0} not allowed in JSON", self)); } return MutableString.CreateAscii(self.ToString(NumberFormatInfo.InvariantInfo)); } else { return MutableString.CreateAscii(self.ToString(NumberFormatInfo.InvariantInfo)); } }
public static Hash ToHash(RubyContext /*!*/ context, GeneratorState /*!*/ self) { // TODO: vOpts.respondsTo("to_hash") Hash configurationHash = new Hash(context); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "indent"), self.Indent); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "space"), self.Space); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "space_before"), self.SpaceBefore); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "object_nl"), self.ObjectNl); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "array_nl"), self.ArrayNl); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "check_circular"), self.CheckCircular); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "allow_nan"), self.AllowNaN); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "max_nesting"), self.MaxNesting); return(configurationHash); }
public static MutableString ToJson(Double self, GeneratorState state) { if (Double.IsInfinity(self) || Double.IsNaN(self)) { if (state != null && state.AllowNaN == false) { Helpers.ThrowGenerateException(String.Format("{0} not allowed in JSON", self)); } return(MutableString.CreateAscii(self.ToString(NumberFormatInfo.InvariantInfo))); } else { return(MutableString.CreateAscii(self.ToString(NumberFormatInfo.InvariantInfo))); } }
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; }
public static void Configure(RubyContext /*!*/ context, GeneratorState /*!*/ self, Hash /*!*/ configuration) { if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "indent"))) { self.Indent = configuration[Helpers.GetGeneratorStateKey(context, "indent")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "space"))) { self.Space = configuration[Helpers.GetGeneratorStateKey(context, "space")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "space_before"))) { self.SpaceBefore = configuration[Helpers.GetGeneratorStateKey(context, "space_before")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "array_nl"))) { self.ArrayNl = configuration[Helpers.GetGeneratorStateKey(context, "array_nl")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "object_nl"))) { self.ObjectNl = configuration[Helpers.GetGeneratorStateKey(context, "object_nl")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "check_circular"))) { Object cc = configuration[Helpers.GetGeneratorStateKey(context, "check_circular")]; self.CheckCircular = cc is bool?(bool)cc : false; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "max_nesting"))) { Object mn = configuration[Helpers.GetGeneratorStateKey(context, "max_nesting")]; self.MaxNesting = (mn is int) ? (int)mn : 0; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "allow_nan"))) { Object an = configuration[Helpers.GetGeneratorStateKey(context, "allow_nan")]; self.AllowNaN = an is bool?(bool)an : false; } }
public static Int32 GetMaxNesting(GeneratorState self) { return self.MaxNesting; }
public static Boolean GetCheckCircular(GeneratorState self) { return self.CheckCircular; }
public static Object ASeen(RubyContext context, GeneratorState self, Object obj) { return self.Seen(context, obj) ? true : null as Object; }
public static Hash ToHash(RubyContext/*!*/ context, GeneratorState/*!*/ self) { // TODO: vOpts.respondsTo("to_hash") Hash configurationHash = new Hash(context); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "indent"), self.Indent); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "space"), self.Space); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "space_before"), self.SpaceBefore); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "object_nl"), self.ObjectNl); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "array_nl"), self.ArrayNl); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "check_circular"), self.CheckCircular); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "allow_nan"), self.AllowNaN); configurationHash.Add(Helpers.GetGeneratorStateKey(context, "max_nesting"), self.MaxNesting); return configurationHash; }
public static void SetObjectNl(GeneratorState self, MutableString value) { self.ObjectNl = value; }
public static void SetIndent(GeneratorState self, MutableString value) { self.Indent = value; }
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); }
public static void SetMaxNesting(GeneratorState self, Int32 value) { self.MaxNesting = value; }
public static Int32 GetMaxNesting(GeneratorState self) { return(self.MaxNesting); }
public static Boolean GetCheckCircular(GeneratorState self) { return(self.CheckCircular); }
public static void SetArrayNl(GeneratorState self, MutableString value) { self.ArrayNl = value; }
public static MutableString GetArrayNl(GeneratorState self) { return(self.ObjectNl); }
public static MutableString GetSpace(GeneratorState self) { return self.Space; }
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; }
public static MutableString ToJson(ConversionStorage <MutableString> /*!*/ toS, Object /*!*/ self, [Optional] GeneratorState state, [Optional] Int32 depth) { return(Generator.ToJson(Protocols.ConvertToString(toS, self))); }
public static void SetSpaceBefore(GeneratorState self, MutableString value) { self.SpaceBefore = value; }
public static GeneratorState Reconfigure(RubyContext context, GeneratorState /*!*/ self, Hash /*!*/ configuration) { GeneratorState.Configure(context, self, configuration); return(self); }
private static MutableString Transform(ConversionStorage <MutableString> toS, IDictionary self, GeneratorState state, int depth) { byte[] objectNl = state.ObjectNl.ToByteArray(); byte[] indent = Helpers.Repeat(state.Indent.ToByteArray(), depth + 1); byte[] spaceBefore = state.SpaceBefore.ToByteArray(); byte[] space = state.Space.ToByteArray(); int subDepth = depth + 1; MutableString result = MutableString.CreateBinary(2 + self.Count * (12 + indent.Length + spaceBefore.Length + space.Length)); RubyContext context = toS.Context; result.Append((byte)'{'); result.Append(objectNl); if (self.Count > 0) { MutableString json; int i = 0; foreach (DictionaryEntry kv in self) { if (i > 0) { result.Append(objectNl); } if (objectNl.Length != 0) { result.Append(indent); } json = Generator.ToJson(context, Protocols.ConvertToString(toS, kv.Key), state, subDepth); result.Append(json); context.TaintObjectBy <Object>(result, json); result.Append(spaceBefore); result.Append((byte)':'); result.Append(space); json = Generator.ToJson(context, kv.Value, state, subDepth); result.Append(json); context.TaintObjectBy <Object>(result, json); if (++i < self.Count) { result.Append(','); } } if (objectNl.Length != 0) { result.Append(objectNl); if (indent.Length != 0) { for (int n = 0; n < depth; n++) { result.Append(indent); } } } } result.Append((byte)'}'); return(result); }
public static bool ARemember(RubyContext context, GeneratorState self, Object obj) { self.Remember(context, obj); return(true); }
public static bool ARemember(RubyContext context, GeneratorState self, Object obj) { self.Remember(context, obj); return true; }
public static MutableString ToJson(ConversionStorage <MutableString> toS, Hash self, [Optional] GeneratorState state, [Optional] Int32 depth) { return(Generator.ToJson(toS, self, state, depth)); }
public static void Configure(RubyContext/*!*/ context, GeneratorState/*!*/ self, Hash/*!*/ configuration) { if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "indent"))) { self.Indent = configuration[Helpers.GetGeneratorStateKey(context, "indent")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "space"))) { self.Space = configuration[Helpers.GetGeneratorStateKey(context, "space")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "space_before"))) { self.SpaceBefore = configuration[Helpers.GetGeneratorStateKey(context, "space_before")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "array_nl"))) { self.ArrayNl = configuration[Helpers.GetGeneratorStateKey(context, "array_nl")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "object_nl"))) { self.ObjectNl = configuration[Helpers.GetGeneratorStateKey(context, "object_nl")] as MutableString; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "check_circular"))) { Object cc = configuration[Helpers.GetGeneratorStateKey(context, "check_circular")]; self.CheckCircular = cc is bool ? (bool)cc : false; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "max_nesting"))) { Object mn = configuration[Helpers.GetGeneratorStateKey(context, "max_nesting")]; self.MaxNesting = (mn is int) ? (int)mn : 0; } if (configuration.ContainsKey(Helpers.GetGeneratorStateKey(context, "allow_nan"))) { Object an = configuration[Helpers.GetGeneratorStateKey(context, "allow_nan")]; self.AllowNaN = an is bool ? (bool)an : false; } }
public static MutableString GetIndent(GeneratorState self) { return(self.Indent); }
public static MutableString GetIndent(GeneratorState self) { return self.Indent; }
public static MutableString ToJson(String self, [Optional] GeneratorState state, [Optional] Int32 depth) { return(Generator.ToJson(MutableString.Create(self, RubyEncoding.Binary))); }
public static MutableString GetObjectNl(GeneratorState self) { return self.ObjectNl; }
public static MutableString ToJson(Boolean self, [Optional] GeneratorState state, [Optional] Int32 depth) { return(Generator.ToJson(self)); }
public static GeneratorState Reconfigure(RubyContext context, GeneratorState/*!*/ self, Hash/*!*/ configuration) { GeneratorState.Configure(context, self, configuration); return self; }
public static GeneratorState Reinitialize(RubyContext context, GeneratorState self, Hash configuration) { if (configuration != null) { GeneratorState.Configure(context, self, configuration); } return self; }
public static MutableString ToJson(RubyContext /*!*/ context, RubyArray self, [Optional] GeneratorState state, [Optional] Int32 depth) { return(Generator.ToJson(context, self, state, depth)); }
public static Object ASeen(RubyContext context, GeneratorState self, Object obj) { return(self.Seen(context, obj) ? true : null as Object); }
public static MutableString GetSpaceBefore(GeneratorState self) { return(self.SpaceBefore); }