Пример #1
0
 void WriteDepthSpace(int depth)
 {
     if (Lw.Sameline)
     {
         return;
     }
     Lw.Write(Depth);
     // all docs except the ones containing a single scalar
     // have a root node that is not printed and shouldn't
     // contribute to the indent
     if (depth > 0)
     {
         depth--;
     }
     Lw.Write(new string(' ', depth * 2));
 }
Пример #2
0
        bool WriteHorizontalCollection(ref int idx, string open, string close, Func <YNode, bool> write)
        {
            if (!List[idx].IsLeaf)
            {
                return(false);
            }
            int           i           = idx;
            int           childdepth  = List[i].Depth;
            List <string> annotations = null;
            var           tmp         = Lw;
            string        res;

            try {
                var sw = new StringWriter();
                Lw = new LineWriter(sw, 0);
                var sb = sw.GetStringBuilder();
                Lw.Write(open); // to avoid WriteDepthSpace
                var sep = "";
                do
                {
                    var r = List[i];
                    if (!r.IsLeaf)
                    {
                        return(false);
                    }
                    Write(0, sep);
                    sep = ", ";
                    string s = GetAnnotation(i, r);
                    if (s != null)
                    {
                        int len = sb.Length;
                        if (annotations == null)
                        {
                            annotations = new List <string>();
                        }
                        annotations.Add(string.Concat("#", new string(' ', len - 1), "^", s));
                    }
                    if (!write(r))
                    {
                        return(false);
                    }
                    if (sb.Length >= HorizontalThresh)
                    {
                        return(false);
                    }
                    ++i;
                } while(HasDepth(i, childdepth));
                Write(0, close);
                idx = i;
                res = sb.ToString();
            }
            finally  {
                Lw = tmp;
            }
            WriteDepthSpace(childdepth);
            int curcolumn = Lw.Column;

            Write(childdepth, res);
            if (annotations != null)
            {
                foreach (string s in annotations)
                {
                    EndLine();
                    Lw.Write(new string(' ', curcolumn));
                    Lw.Write(s);
                }
            }
            return(true);
        }
Пример #3
0
 bool WriteHorizontalCollection(ref int idx,string open,string close,Func<YNode,bool> write) {
     if(!List[idx].IsLeaf) return false;
     int i=idx;
     int childdepth=List[i].Depth;
     List<string> annotations=null;
     var tmp=Lw;
     string res;
     try {
         var sw=new StringWriter();
         Lw=new LineWriter(sw,0);
         var sb=sw.GetStringBuilder();
         Lw.Write(open); // to avoid WriteDepthSpace
         var sep="";
         do {
             var r=List[i];
             if(!r.IsLeaf) return false;
             Write(0,sep);
             sep=", ";
             string s=GetAnnotation(i,r);
             if(s!=null) {
                 int len=sb.Length;
                 if(annotations==null) annotations=new List<string>();
                 annotations.Add(string.Concat("#",new string(' ',len-1),"^",s));
             }
             if(!write(r)) return false;
             if(sb.Length>=HorizontalThresh) return false;
             ++i;
         } while(HasDepth(i,childdepth));
         Write(0,close);
         idx=i;
         res=sb.ToString();
     }
     finally  {
         Lw=tmp;
     }
     WriteDepthSpace(childdepth);
     int curcolumn=Lw.Column;
     Write(childdepth,res);
     if(annotations!=null) {
         foreach(string s in annotations) {
             EndLine();
             Lw.Write(new string(' ',curcolumn));
             Lw.Write(s);
         }
     }
     return true;
 }