示例#1
0
文件: arrays.cs 项目: sioncheng/mono
    public static int test_1_bit_index()
    {
        var t = new BitClass();

        t.setBit(0, true);
        t.setBit(3, true);
        if (t.getBit(1))
        {
            return(4);
        }
        if (!t.getBit(0))
        {
            return(5);
        }
        if (!t.getBit(3))
        {
            return(6);
        }
        return(1);
    }
 private CharProperty bitsOrSingle(BitClass bits, int ch) {
     /* Bits can only handle codepoints in [u+0000-u+00ff] range.
        Use "single" node instead of bits when dealing with unicode
        case folding for codepoints listed below.
        (1)Uppercase out of range: u+00ff, u+00b5
           toUpperCase(u+00ff) -> u+0178
           toUpperCase(u+00b5) -> u+039c
        (2)LatinSmallLetterLongS u+17f
           toUpperCase(u+017f) -> u+0053
        (3)LatinSmallLetterDotlessI u+131
           toUpperCase(u+0131) -> u+0049
        (4)LatinCapitalLetterIWithDotAbove u+0130
           toLowerCase(u+0130) -> u+0069
        (5)KelvinSign u+212a
           toLowerCase(u+212a) ==> u+006B
        (6)AngstromSign u+212b
           toLowerCase(u+212b) ==> u+00e5
     */
     //int d;
     if (ch < 256 &&
         !(has(CASE_INSENSITIVE) && has(UNICODE_CASE) &&
           (ch == 0xff || ch == 0xb5 ||
            ch == 0x49 || ch == 0x69 ||  //I and i
            ch == 0x53 || ch == 0x73 ||  //S and s
            ch == 0x4b || ch == 0x6b ||  //K and k
            ch == 0xc5 || ch == 0xe5)))  //A+ring
         return bits.add(ch, flags());
     return newSingle(ch);
 }
 private CharProperty range(BitClass bits) {
     int ch = peek();
     if (ch == '\\') {
         ch = nextEscaped();
         if (ch == 'p' || ch == 'P') { // A property
             boolean comp = (ch == 'P');
             boolean oneLetter = true;
             // Consume { if present
             ch = next();
             if (ch != '{')
                 unread();
             else
                 oneLetter = false;
             return family(oneLetter, comp);
         } else { // ordinary escape
             unread();
             ch = escape(true, true);
             if (ch == -1)
                 return (CharProperty) root;
         }
     } else {
         ch = single();
     }
     if (ch >= 0) {
         if (peek() == '-') {
             int endRange = temp[_cursor+1];
             if (endRange == '[') {
                 return bitsOrSingle(bits, ch);
             }
             if (endRange != ']') {
                 next();
                 int m = single();
                 if (m < ch)
                     throw error(new String("Illegal character range"));
                 if (has(CASE_INSENSITIVE))
                     return caseInsensitiveRangeFor(ch, m);
                 else
                     return rangeFor(ch, m);
             }
         }
         return bitsOrSingle(bits, ch);
     }
     throw error(new String("Unexpected character '"+((char)ch)+"'"));
 }
 private CharProperty clazz(boolean consume) {
     CharProperty prev = null;
     CharProperty node = null;
     BitClass bits = new BitClass();
     boolean include = true;
     boolean firstInClass = true;
     int ch = next();
     for (;;) {
         switch (ch) {
             case '^':
                 // Negates if first char in a class, otherwise literal
                 if (firstInClass) {
                     if (temp[_cursor-1] != '[')
                         break;
                     ch = next();
                     include = !include;
                     continue;
                 } else {
                     // ^ not first in class, treat as literal
                     break;
                 }
             case '[':
                 firstInClass = false;
                 node = clazz(true);
                 if (prev == null)
                     prev = node;
                 else
                     prev = union(prev, node);
                 ch = peek();
                 continue;
             case '&':
                 firstInClass = false;
                 ch = next();
                 if (ch == '&') {
                     ch = next();
                     CharProperty rightNode = null;
                     while (ch != ']' && ch != '&') {
                         if (ch == '[') {
                             if (rightNode == null)
                                 rightNode = clazz(true);
                             else
                                 rightNode = union(rightNode, clazz(true));
                         } else { // abc&&def
                             unread();
                             rightNode = clazz(false);
                         }
                         ch = peek();
                     }
                     if (rightNode != null)
                         node = rightNode;
                     if (prev == null) {
                         if (rightNode == null)
                             throw error(new String("Bad class syntax"));
                         else
                             prev = rightNode;
                     } else {
                         prev = intersection(prev, node);
                     }
                 } else {
                     // treat as a literal &
                     unread();
                     break;
                 }
                 continue;
             case 0:
                 firstInClass = false;
                 if (_cursor >= patternLength)
                     throw error(new String("Unclosed character class"));
                 break;
             case ']':
                 firstInClass = false;
                 if (prev != null) {
                     if (consume)
                         next();
                     return prev;
                 }
                 break;
             default:
                 firstInClass = false;
                 break;
         }
         node = range(bits);
         if (include) {
             if (prev == null) {
                 prev = node;
             } else {
                 if (prev != node)
                     prev = union(prev, node);
             }
         } else {
             if (prev == null) {
                 prev = node.complement();
             } else {
                 if (prev != node)
                     prev = setDifference(prev, node);
             }
         }
         ch = peek();
     }
 }