System.Text.RegularExpressions.RegexCharClass.CharInClassInternal C# (CSharp) Method

CharInClassInternal() private static method

private static CharInClassInternal ( char ch, string set, int start, int mySetLength, int myCategoryLength ) : bool
ch char
set string
start int
mySetLength int
myCategoryLength int
return bool
        private static bool CharInClassInternal(char ch, string set, int start, int mySetLength, int myCategoryLength) {
            int min;
            int max;
            int mid;
            min = start + SETSTART;
            max = min + mySetLength;

            while (min != max) {
                mid = (min + max) / 2;
                if (ch < set[mid])
                    max = mid;
                else
                    min = mid + 1;
            }

            // The starting position of the set within the character class determines
            // whether what an odd or even ending position means.  If the start is odd, 
            // an *even* ending position means the character was in the set.  With recursive 
            // subtractions in the mix, the starting position = start+SETSTART.  Since we know that 
            // SETSTART is odd, we can simplify it out of the equation.  But if it changes we need to 
            // reverse this check. 
            Debug.Assert((SETSTART & 0x1) == 1, "If SETSTART is not odd, the calculation below this will be reversed");
            if ((min & 0x1) == (start & 0x1)) 
                return true;
            else {
                if (myCategoryLength == 0)
                    return false;
                
                return CharInCategory(ch, set, start, mySetLength, myCategoryLength);
            }
        }