internal static String SetDescription(String set) {
int mySetLength = set[SETLENGTH];
int myCategoryLength = set[CATEGORYLENGTH];
int myEndPosition = SETSTART + mySetLength + myCategoryLength;
StringBuilder desc = new StringBuilder("[");
int index = SETSTART;
char ch1;
char ch2;
if (IsNegated(set))
desc.Append('^');
while (index < SETSTART + set[SETLENGTH]) {
ch1 = set[index];
if (index + 1 < set.Length)
ch2 = (char)(set[index + 1] - 1);
else
ch2 = Lastchar;
desc.Append(CharDescription(ch1));
if (ch2 != ch1) {
if (ch1 + 1 != ch2)
desc.Append('-');
desc.Append(CharDescription(ch2));
}
index += 2;
}
while (index < SETSTART + set[SETLENGTH] + set[CATEGORYLENGTH]) {
ch1 = set[index];
if (ch1 == 0) {
bool found = false;
int lastindex = set.IndexOf(GroupChar, index+1);
string group = set.Substring(index,lastindex-index + 1);
IDictionaryEnumerator en = _definedCategories.GetEnumerator();
while(en.MoveNext()) {
if (group.Equals(en.Value)) {
if ((short) set[index+1] > 0)
desc.Append("\\p{" + en.Key + "}");
else
desc.Append("\\P{" + en.Key + "}");
found = true;
break;
}
}
if (!found) {
if (group.Equals(Word))
desc.Append("\\w");
else if (group.Equals(NotWord))
desc.Append("\\W");
else
Debug.Assert(false, "Couldn't find a goup to match '" + group + "'");
}
index = lastindex;
}
else {
desc.Append(CategoryDescription(ch1));
}
index++;
}
if (set.Length > myEndPosition) {
desc.Append('-');
desc.Append(SetDescription(set.Substring(myEndPosition)));
}
desc.Append(']');
return desc.ToString();
}