Antlr4.Runtime.Misc.IntervalSet.ToString C# (CSharp) Method

ToString() public method

public ToString ( IVocabulary vocabulary ) : string
vocabulary IVocabulary
return string
        public virtual string ToString(IVocabulary vocabulary)
        {
            StringBuilder buf = new StringBuilder();
            if (this.intervals == null || this.intervals.Count == 0)
            {
                return "{}";
            }
            if (this.Count > 1)
            {
                buf.Append("{");
            }

            bool first = true;
            foreach (Interval I in intervals)
            {
                if (!first)
                    buf.Append(", ");

                first = false;
                int a = I.a;
                int b = I.b;
                if (a == b)
                {
                    buf.Append(ElementName(vocabulary, a));
                }
                else
                {
                    for (int i = a; i <= b; i++)
                    {
                        if (i > a)
                        {
                            buf.Append(", ");
                        }
                        buf.Append(ElementName(vocabulary, i));
                    }
                }
            }
            if (this.Count > 1)
            {
                buf.Append("}");
            }
            return buf.ToString();
        }

Same methods

IntervalSet::ToString ( ) : string
IntervalSet::ToString ( bool elemAreChar ) : string

Usage Example

 public void TestIsolatedElements()
 {
     IntervalSet s = new IntervalSet();
     s.Add(1);
     s.Add('z');
     s.Add('\uFFF0');
     String expecting = "{1, 122, 65520}";
     Assert.AreEqual(s.ToString(), expecting);
 }
All Usage Examples Of Antlr4.Runtime.Misc.IntervalSet::ToString