private static void WriteJsonArray(RavenJArray array, CountingWriter sw, int width, int numberOfLines) { sw.WriteLine("["); sw.PushIndent(); var isFirstItem = true; foreach (var token in array.Values()) { if (sw.LinesWritten >= numberOfLines) { break; } if (isFirstItem) { isFirstItem = false; } else { sw.WriteLine(","); } WriteValue(token, sw, width, numberOfLines); } sw.WriteLine(""); sw.PopIndent(); sw.Write("]"); }
private static void WriteValue(RavenJToken token, CountingWriter sw, int width, int numberOfLines) { switch (token.Type) { case JTokenType.Array: WriteJsonArray((RavenJArray)token, sw, width, numberOfLines); break; case JTokenType.Object: WriteJsonObject((RavenJObject)token, sw, width, numberOfLines); break; case JTokenType.Null: sw.Write("null"); break; case JTokenType.String: sw.Write("\""); sw.Write(token.ToString() .NormalizeWhitespace() .TrimmedViewOfString(width - sw.CharactersOnCurrentLine -1) ); sw.Write("\""); break; default: sw.Write(token.ToString().TrimmedViewOfString(width - sw.CharactersOnCurrentLine - 1)); break; } }
private static void WriteValue(RavenJToken token, CountingWriter sw, int width, int numberOfLines) { switch (token.Type) { case JTokenType.Array: WriteJsonArray((RavenJArray)token, sw, width, numberOfLines); break; case JTokenType.Object: WriteJsonObject((RavenJObject)token, sw, width, numberOfLines); break; case JTokenType.Null: sw.Write("null"); break; case JTokenType.String: sw.Write("\""); sw.Write(token.ToString() .NormalizeWhitespace() .TrimmedViewOfString(width - sw.CharactersOnCurrentLine - 1) ); sw.Write("\""); break; default: sw.Write(token.ToString().TrimmedViewOfString(width - sw.CharactersOnCurrentLine - 1)); break; } }
public int calcStoryboardCommandSize() { Writer cw = new CountingWriter(); new Sprite(this).fin(cw); return(cw.byteswritten); }
public static string GetContentTrimmedToDimensions(RavenJObject dataAsJson, int widthInCharacters, int heightInLines) { var sw = new CountingWriter(2); WriteJsonObject(dataAsJson, sw, widthInCharacters, heightInLines); return(sw.ToString()); }
private static void WriteJsonObject(RavenJObject ravenJObject, CountingWriter sw, int width, int numberOfLines) { sw.WriteLine("{"); sw.PushIndent(); foreach (var item in ravenJObject) { if (sw.LinesWritten > numberOfLines) break; sw.Write(item.Key); sw.Write(": "); WriteValue(item.Value, sw, width, numberOfLines); sw.WriteLine(""); } sw.PopIndent(); sw.Write("}"); }
private static void WriteJsonArray(RavenJArray array, CountingWriter sw, int width, int numberOfLines) { sw.WriteLine("["); sw.PushIndent(); var isFirstItem = true; foreach (var token in array.Values()) { if (sw.LinesWritten >= numberOfLines) break; if (isFirstItem) isFirstItem = false; else sw.WriteLine(","); WriteValue(token, sw, width, numberOfLines); } sw.WriteLine(""); sw.PopIndent(); sw.Write("]"); }
private static void WriteJsonObject(RavenJObject ravenJObject, CountingWriter sw, int width, int numberOfLines) { sw.WriteLine("{"); sw.PushIndent(); foreach (var item in ravenJObject) { if (sw.LinesWritten > numberOfLines) { break; } sw.Write(item.Key); sw.Write(": "); WriteValue(item.Value, sw, width, numberOfLines); sw.WriteLine(""); } sw.PopIndent(); sw.Write("}"); }
public static string GetContentTrimmedToDimensions(RavenJObject dataAsJson, int widthInCharacters, int heightInLines) { var sw = new CountingWriter(2); WriteJsonObject(dataAsJson, sw, widthInCharacters, heightInLines); return sw.ToString(); }