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.Range; 
    20  import org.as2lib.regexp.node.NotRangeA;
    21  
    22  /**
    23   * {@code RangeA} is a node class for matching characters within an explicit 
    24   * value range in a case insensitive manner.
    25   * 
    26   * @author Igor Sadovskiy
    27   */
    28   
    29  class org.as2lib.regexp.node.RangeA extends Range {
    30  	
    31      public function RangeA(n:Number) {
    32          lower = n >>> 16;
    33          upper = n & 0xFFFF;
    34      }
    35      
    36      public function dup(flag:Boolean):Node {
    37          return (flag) ?
    38              new NotRangeA((lower << 16) + upper) :
    39              new RangeA((lower << 16) + upper);
    40      }
    41      
    42      public function match(matcher:Object, i:Number, seq:String):Boolean {
    43          if (i < matcher.to) {
    44              var ch:Number = seq.charCodeAt(i);
    45              var m:Boolean = (((ch-lower)|(upper-ch)) >= 0);
    46              if (!m) {
    47                  ch = AsciiUtil.toUpper(ch);
    48                  m = (((ch-lower)|(upper-ch)) >= 0);
    49                  if (!m) {
    50                      ch = AsciiUtil.toLower(ch);
    51                      m = (((ch-lower)|(upper-ch)) >= 0);
    52                  }
    53              }
    54              return (m && next.match(matcher, i+1, seq));
    55          }
    56          return false;
    57      }
    58  }
    59  
    60