InvalidPattern() публичный статический Метод

public static InvalidPattern ( string pat ) : Exception
pat string
Результат System.Exception
Пример #1
0
        internal string AnalyzePattern(string pat)
        {
            int length = pat.Length;

            char[] destination = new char[length + 1];
            pat.CopyTo(0, destination, 0, length);
            destination[length] = '\0';
            string str = null;

            char[] chArray2 = new char[length + 1];
            int    num3     = 0;
            int    num4     = 0;
            int    index    = 0;

            while (index < length)
            {
                if ((destination[index] == '*') || (destination[index] == '%'))
                {
                    while (((destination[index] == '*') || (destination[index] == '%')) && (index < length))
                    {
                        index++;
                    }
                    if (((index < length) && (num3 > 0)) || (num4 >= 2))
                    {
                        throw ExprException.InvalidPattern(pat);
                    }
                    num4++;
                }
                else if (destination[index] == '[')
                {
                    index++;
                    if (index >= length)
                    {
                        throw ExprException.InvalidPattern(pat);
                    }
                    chArray2[num3++] = destination[index++];
                    if (index >= length)
                    {
                        throw ExprException.InvalidPattern(pat);
                    }
                    if (destination[index] != ']')
                    {
                        throw ExprException.InvalidPattern(pat);
                    }
                    index++;
                }
                else
                {
                    chArray2[num3++] = destination[index];
                    index++;
                }
            }
            str = new string(chArray2, 0, num3);
            if (num4 == 0)
            {
                this.kind = 4;
                return(str);
            }
            if (num3 > 0)
            {
                if ((destination[0] == '*') || (destination[0] == '%'))
                {
                    if ((destination[length - 1] == '*') || (destination[length - 1] == '%'))
                    {
                        this.kind = 3;
                        return(str);
                    }
                    this.kind = 2;
                    return(str);
                }
                this.kind = 1;
                return(str);
            }
            this.kind = 5;
            return(str);
        }
Пример #2
0
        internal string AnalizePattern(string pat)
        {
#if DEBUG
            if (CompModSwitches.BinaryNode.TraceVerbose)
            {
                Debug.WriteLine("Like pattern " + pat);
            }
#endif

            int    length   = pat.Length;
            char[] patchars = new char[length + 1];
            pat.CopyTo(0, patchars, 0, length);
            patchars[length] = (char)0;
            string substring = null;

            char[] constchars = new char[length + 1];
            int    newLength  = 0;

            int stars = 0;

            int i = 0;

            while (i < length)
            {
                if (patchars[i] == '*' || patchars[i] == '%')
                {
                    // replace conseq. * or % with one..
                    while ((patchars[i] == '*' || patchars[i] == '%') && i < length)
                    {
                        i++;
                    }

                    // we allowing only *str* pattern
                    if ((i < length && newLength > 0) || stars >= 2)
                    {
                        // we have a star inside string constant..
                        throw ExprException.InvalidPattern(pat);
                    }
                    stars++;
                }
                else if (patchars[i] == '[')
                {
                    i++;
                    if (i >= length)
                    {
                        throw ExprException.InvalidPattern(pat);
                    }
                    constchars[newLength++] = patchars[i++];

                    if (i >= length)
                    {
                        throw ExprException.InvalidPattern(pat);
                    }

                    if (patchars[i] != ']')
                    {
                        throw ExprException.InvalidPattern(pat);
                    }
                    i++;
                }
                else
                {
                    constchars[newLength++] = patchars[i];
                    i++;
                }
            }

            substring = new string(constchars, 0, newLength);

#if DEBUG
            if (CompModSwitches.BinaryNode.TraceVerbose)
            {
                Debug.WriteLine("new Like pattern " + substring);
            }
#endif

            if (stars == 0)
            {
                kind = match_exact;
            }
            else
            {
                if (newLength > 0)
                {
                    if (patchars[0] == '*' || patchars[0] == '%')
                    {
#if DEBUG
                        if (CompModSwitches.BinaryNode.TraceVerbose)
                        {
                            Debug.WriteLine("looking for a substring " + substring);
                        }
#endif

                        if (patchars[length - 1] == '*' || patchars[length - 1] == '%')
                        {
                            kind = match_middle;
                        }
                        else
                        {
                            kind = match_right;
                        }
                    }
                    else
                    {
                        Debug.Assert(patchars[length - 1] == '*' || patchars[length - 1] == '%', "Invalid LIKE pattern formed.. ");
                        kind = match_left;
                    }
                }
                else
                {
                    kind = match_all;
                }
            }
            return(substring);
        }