// returns false if not a leaf or strlen(n.O)>maxlen public bool WriteLeaf(YNode n, int maxlen) { var o = n.O; if (o == null) { YAMLWriter.Write(n.Depth, "~"); return(true); } else if (n.IsLeaf) { var s = n.O.ToString(); if (s.Length > maxlen) { return(false); } if (n.O is string || n.O is char) { if (LineBreakp(s)) { var matches = LineBreaker.Matches(s); YAMLWriter.WriteLine(n.Depth, "|2"); var olddepth = YAMLWriter.Depth; YAMLWriter.Depth += " "; foreach (Match i in matches) { YAMLWriter.Lw.Column = 0; YAMLWriter.Write(n.Depth, i.Groups[0].Value); } YAMLWriter.Depth = olddepth; } else { YAMLWriter.Write(n.Depth, Escape(s)); } } else { YAMLWriter.Write(n.Depth, s); } return(true); } return(false); }
public static void Dump(string name, object o) { using (new WithInvariantCulture()) { lock (WriteLock) { Diag("dump of " + name + ": "); var yw = new YAMLWriter(Console.Out, 0, TAP.HorizontalThreshold, null); yw.Write(o); } } }
void WriteIsVal(bool leaf, OrderedDictionary dic, string label, string key, List <PathEntry> path, int side) { var val = dic[key]; if (leaf) { Tw.Write("{0}: '{1}'", label, SafeToString(val)); } else { Tw.WriteLine(" {0}:", label); var yw = new YAMLWriter(Tw, 4, TAP.HorizontalThreshold, BBD); yw.Annotate = (i, n) => { return(GetAnnotation(i, n, path, side, 0)); }; yw.Write(val); } }
public override void WriteComment(int nr, OrderedDictionary dic, List <PathEntry> path, string name) { if (path != null) { path.Insert(0, new PathEntry(-1)); } var yw = new YAMLWriter(Tw, 2, TAP.HorizontalThreshold, BBD); int rootidx = -1; int side = 0; yw.Annotate = (i, n) => { int depth = n.Depth; if (depth == 1) { var k = n.Key as string; if (k != null) { if (k == "actual") { side = 0; rootidx = i; } else if (k == "expected") { side = 1; rootidx = i; } } else { rootidx = -1; } } if (rootidx != -1) { return(GetAnnotation(i - rootidx, n, path, side, 1)); } return(null); }; yw.Write(dic); }
string RunWriter(int initialdepth,object o,int horizontalthreshold,IDictionary<Type,bool> bbt,Func<int,YNode,string> anno) { var w=new YAMLWriter(new StringWriter(),initialdepth,horizontalthreshold,bbt); w.Annotate=anno; return w.Write(o).ToString(); }