public ToString ( IVocabulary vocabulary ) : string | ||
vocabulary | IVocabulary | |
Результат | 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();
}
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); }