1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import org.as2lib.regexp.AsciiUtil;
    18  import org.as2lib.regexp.node.Node;
    19  import org.as2lib.regexp.node.NotRange;
    20  import org.as2lib.regexp.node.RangeA;
    21  
    22  /**
    23   * {@code NotRange} is a node class for matching characters without an 
    24   * explicit case independent value range.
    25   * 
    26   * @author Igor Sadovskiy
    27   */
    28  
    29  class org.as2lib.regexp.node.NotRangeA extends NotRange {
    30  	
    31      private var lower, upper:Number;
    32      
    33      public function NotRangeA(n:Number) {
    34          lower = n >>> 16;
    35          upper = n & 0xFFFF;
    36      }
    37      
    38      public function dup(flag:Boolean):Node {
    39          if (flag) {
    40              return new RangeA((lower << 16) + upper);
    41          } else {
    42              return new NotRangeA((lower << 16) + upper);
    43          }
    44      }
    45      
    46      public function match(matcher:Object, i:Number, seq:String):Boolean {
    47          if (i < matcher.to) {
    48              var ch:Number = seq.charCodeAt(i);
    49              var m:Boolean = (((ch-lower)|(upper-ch)) < 0);
    50              if (m) {
    51                  ch = AsciiUtil.toUpper(ch);
    52                  m = (((ch-lower)|(upper-ch)) < 0);
    53                  if (m) {
    54                      ch = AsciiUtil.toLower(ch);
    55                      m = (((ch-lower)|(upper-ch)) < 0);
    56                  }
    57              }
    58  
    59              return (m && next.match(matcher, i+1, seq));
    60          }
    61          return false;
    62      }
    63  }
    64  
    65