Exemple #1
0
        public override void Process(CharSetExpression expression, NormalizedCharSet target, CharRange range)
        {
            int index = 0;

            while (index < target.Ranges.Count)
            {
                var cur    = target.Ranges[index];
                var ranges = target.Ranges;
                if (!cur.IsOverlapped(range))
                {
                    index++;
                    continue;
                }

                else if (cur.Begin < range.Begin)
                {
                    //cur:  |---------|
                    //range:   |---------?
                    //切割成两半
                    //插入两半后,index 自增后演变成:
                    //cur:  |--|-------|
                    //range:   |---------?
                    ranges.RemoveAt(index);
                    target.AddRange(cur.Begin, (char)(range.Begin - 1));
                    target.AddRange(range.Begin, cur.End);
                    index++;
                }
                else if (cur.Begin > range.Begin)
                {
                    //cur:        |----|
                    //range:   |---------?
                    target.AddRange(range.Begin, (char)(cur.Begin - 1));
                    range.Begin = cur.Begin;
                    index++;
                }
                else if (cur.End < range.End)
                {
                    //cur:        |----|
                    //range:      |---------|
                    range.Begin = (char)(cur.End + 1);
                    index++;
                }
                else if (cur.End > range.End)
                {
                    //cur:        |-----------|
                    //range:      |---------|
                    target.Ranges.RemoveAt(index);
                    target.Ranges.Add(range);
                    target.AddRange((char)(range.End + 1), cur.End);
                    return;
                }
                else
                {
                    return;
                }
            }
            target.Ranges.Add(range);
        }
Exemple #2
0
        public override bool Apply(CharSetExpression expression, NormalizedCharSet param)
        {
            var source = new FlatSet <CharRange>(expression.Ranges);

            expression.Ranges.Clear();
            Loop(expression, source, param);
            expression.IsReverse = false;
            return(false);
        }
Exemple #3
0
 public override void Process(CharSetExpression expression, NormalizedCharSet target, CharRange range)
 {
     foreach (var r in target.Ranges)
     {
         if (range.Begin <= r.Begin && r.End <= range.End)
         {
             expression.Ranges.Add(r);
         }
     }
 }
Exemple #4
0
 public override bool Apply(CharSetExpression expression, NormalizedCharSet target)
 {
     Loop(expression, expression.Ranges, target);
     return(false);
 }
Exemple #5
0
 public void NormalizeCharSet(out FlatSet<CharRange> subsets)
 {
     var normalized = new NormalizedCharSet();
     new BuildNormalizedCharSetAlgorithm().Invoke(this, normalized);
     new SetNormalizedCharSetAlgorithm().Invoke(this, normalized);
     subsets = new FlatSet<CharRange>(normalized.Ranges);
 }