Pchp.Library.CharMap.ToString C# (CSharp) Method

ToString() public method

Accumulates all characters contained or not contained in the set to the string in ascending order.
or are not mapped by this instance.
public ToString ( char first, char last, bool complement ) : string
first char The lower bound.
last char The upper bound.
complement bool Whether to return characters not contained in the string.
return string
        public string ToString(char first, char last, bool complement)
        {
            if (first > last)
                //throw new ArgumentException(CoreResources.GetString("last_is_less_than_first"));
                throw new NotImplementedException();

            int modf = first & 0x1f;
            int modl = last & 0x1f;
            int f = first >> 5;
            int l = last >> 5;

            // an optimization:
            if (l > lastDirty && !complement)
            {
                // sets upper bound to the last bit in the lastDirty block:
                l = lastDirty;
                modl = 31;

                // the whole interval is beyond the last set bit:
                if (f > l) return String.Empty;
            }

            // if complementary set is required, we xor each item of the "flags" array by the "invert_equality" 
            // and so invert the result of comparison with zero in the following if statement:
            uint invert_inequality = (complement) ? 0xffffffffU : 0U;
            uint flg;
            char c = first;
            StringBuilder result = new StringBuilder();

            if (f == l)
            {
                // the "first" and the "last" points to the same block:
                flg = flags[f] ^ invert_inequality;
                for (uint mask = (0x80000000U >> modf); mask > (0x80000000U >> modl); mask >>= 1)
                {
                    if ((flg & mask) != 0) result.Append(c);
                    c++;
                }
            }
            else
            {
                // the first block:
                flg = flags[f] ^ invert_inequality;
                for (uint mask = 0x80000000U >> modf; mask != 0; mask >>= 1)
                {
                    if ((flg & mask) != 0) result.Append(c);
                    c++;
                }

                // middle blocks (if any):
                for (int i = f + 1; i < l; i++)
                {
                    flg = flags[i] ^ invert_inequality;
                    for (uint mask = 0x80000000U; mask != 0; mask >>= 1)
                    {
                        if ((flg & mask) != 0) result.Append(c);
                        c++;
                    }
                }

                // the last block:
                flg = flags[l] ^ invert_inequality;
                for (uint mask = 0x80000000U; mask >= (0x80000000U >> modl); mask >>= 1)
                {
                    if ((flg & mask) != 0) result.Append(c);
                    c++;
                }
            }

            return result.ToString();
        }
    }