Esempio n. 1
0
        private void SortDescriptors()
        {
            int j;

            List <object> newDesc = new List <object>(descriptors.Count);
            int           cnt     = 0;


            for (int i = 0; i < descriptors.Count; i++)
            {
                SingleCharacter s;
                CharacterRange  range;

                if (descriptors[i] is SingleCharacter)
                {
                    s = (SingleCharacter)descriptors[i];

                    for (j = 0; j < cnt; j++)
                    {
                        if (newDesc[j] is SingleCharacter)
                        {
                            if (((SingleCharacter)newDesc[j]).Character > s.Character)
                            {
                                break;
                            }
                            else if (((SingleCharacter)newDesc[j]).Character == s.Character)
                            {
                                goto Outer;
                            }
                        }
                        else
                        {
                            char l = ((CharacterRange)newDesc[j]).Left;

                            if (InRange(s.Character, (CharacterRange)newDesc[j]))
                            {
                                goto Outer;
                            }
                            else
                            if (l > s.Character)
                            {
                                break;
                            }
                        }
                    }

                    newDesc.Insert(j, s);
                    cnt++;
                }
                else
                {
                    range = (CharacterRange)descriptors[i];

                    for (j = 0; j < cnt; j++)
                    {
                        if (newDesc[j] is SingleCharacter)
                        {
                            if (InRange(((SingleCharacter)newDesc[j]).Character, range))
                            {
                                newDesc.RemoveAt(j--);
                                cnt--;
                            }
                            else if (((SingleCharacter)newDesc[j]).Character > range.Right)
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (SubRange(range, (CharacterRange)newDesc[j]))
                            {
                                goto Outer;
                            }
                            else if (SubRange((CharacterRange)newDesc[j], range))
                            {
                                newDesc[j] = range;
                                goto Outer;
                            }
                            else if (Overlaps(range, (CharacterRange)newDesc[j]))
                            {
                                range.Left = (char)(((CharacterRange)newDesc[j]).Right + 1);
                            }
                            else if (Overlaps((CharacterRange)newDesc[j], range))
                            {
                                CharacterRange tmp = range;
                                ((CharacterRange)newDesc[j]).Right = ((char)(range.Left + 1));
                                range      = (CharacterRange)newDesc[j];
                                newDesc[j] = tmp;
                            }
                            else if (((CharacterRange)newDesc[j]).Left > range.Right)
                            {
                                break;
                            }
                        }
                    }

                    newDesc.Insert(j, range);
                    cnt++;
                }
Outer:
                ;
            }

            descriptors = newDesc;
        }
Esempio n. 2
0
 private static bool SubRange(CharacterRange r1, CharacterRange r2)
 {
     return(r1.Left >= r2.Left && r1.Right <= r2.Right);
 }
Esempio n. 3
0
 private static bool InRange(char c, CharacterRange range)
 {
     return(c >= range.Left && c <= range.Right);
 }
Esempio n. 4
0
 private static bool Overlaps(CharacterRange r1, CharacterRange r2)
 {
     return(r1.Left <= r2.Right && r1.Right > r2.Right);
 }