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

CharInCategory() private static method

private static CharInCategory ( 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 CharInCategory(char ch, string set, int start, int mySetLength, int myCategoryLength) {
            UnicodeCategory chcategory = char.GetUnicodeCategory(ch);

            int i=start + SETSTART + mySetLength;
            int end = i + myCategoryLength;
            while (i<end) {
                int curcat = (short) set[i];

                if (curcat == 0) {
                    // zero is our marker for a group of categories - treated as a unit
                    if (CharInCategoryGroup(ch, chcategory, set, ref i))
                        return true;
                }
                else if (curcat > 0) {
                    // greater than zero is a positive case

                    if (curcat  == SpaceConst) {
                        if (Char.IsWhiteSpace(ch))
                            return true;
                        else  {
                            i++;
                            continue;
                        }
                    }
                    --curcat;

                    if (chcategory == (UnicodeCategory) curcat)
                        return true;
                }
                else {
                    // less than zero is a negative case
                    if (curcat == NotSpaceConst) {
                        if (!Char.IsWhiteSpace(ch))
                            return true;
                        else  {
                            i++;
                            continue;
                        }
                    }
                    
                    //curcat = -curcat;
                    //--curcat;
                    curcat = -1 - curcat;

                    if (chcategory != (UnicodeCategory) curcat)
                        return true;
                }
                i++;
            }
            return false;
        }