internal static bool IsProcessingInstructionName(string name)
        {
            if (name == null)
            {
                return(false);
            }

            int         nameLength  = name.Length;
            int         position    = 0;
            XmlCharType xmlCharType = XmlCharType.Instance;

            while (position < nameLength && xmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position >= nameLength)
            {
                return(false);
            }

            if (position < nameLength && !xmlCharType.IsStartNCNameChar(name[position]))
            {
                return(false);
            }

            while (position < nameLength && xmlCharType.IsNCNameChar(name[position]))
            {
                position++;
            }

            while (position < nameLength && xmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position < nameLength)
            {
                return(false);
            }

            if (nameLength == 3 &&
                (name[0] == CharX || name[0] == Charx) &&
                (name[1] == CharM || name[1] == Charm) &&
                (name[2] == CharL || name[2] == Charl)
                )
            {
                return(false);
            }

            return(true);
        }
        public static bool ValidatePrefix(string prefix)
        {
            if (prefix.Length == 0)
            {
                return(false);
            }
            XmlCharType xmlCharType = XmlCharType.Instance;

            if (!xmlCharType.IsStartNCNameChar(prefix[0]))
            {
                return(false);
            }
            for (int i = 1; i < prefix.Length; i++)
            {
                if (!xmlCharType.IsNCNameChar(prefix[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        //
        // Parsing qualified names
        //

        private static string ParseNCName(string qname, ref int position)
        {
            int qnameLength = qname.Length;
            int nameStart   = position;

            if (
                qnameLength == position ||                           // Zero length ncname
                !XmlCharType.IsStartNCNameChar(qname[position])      // Start from invalid char
                )
            {
                throw new XsltException(Res.Xslt_InvalidQName, qname);
            }

            position++;

            while (position < qnameLength && XmlCharType.IsNCNameChar(qname[position]))
            {
                position++;
            }

            return(qname.Substring(nameStart, position - nameStart));
        }
        public bool NextLex()
        {
            SkipSpace();
            switch (this.CurerntChar)
            {
            case '\0':
                kind = LexKind.Eof;
                return(false);

            case ',':
            case '@':
            case '(':
            case ')':
            case '|':
            case '*':
            case '[':
            case ']':
            case '+':
            case '-':
            case '=':
            case '#':
            case '$':
                kind = (LexKind)Convert.ToInt32(this.CurerntChar, CultureInfo.InvariantCulture);
                NextChar();
                break;

            case '<':
                kind = LexKind.Lt;
                NextChar();
                if (this.CurerntChar == '=')
                {
                    kind = LexKind.Le;
                    NextChar();
                }
                break;

            case '>':
                kind = LexKind.Gt;
                NextChar();
                if (this.CurerntChar == '=')
                {
                    kind = LexKind.Ge;
                    NextChar();
                }
                break;

            case '!':
                kind = LexKind.Bang;
                NextChar();
                if (this.CurerntChar == '=')
                {
                    kind = LexKind.Ne;
                    NextChar();
                }
                break;

            case '.':
                kind = LexKind.Dot;
                NextChar();
                if (this.CurerntChar == '.')
                {
                    kind = LexKind.DotDot;
                    NextChar();
                }
                else if (xmlCharType.IsDigit(this.CurerntChar))
                {
                    kind        = LexKind.Number;
                    numberValue = ScanFraction();
                }
                break;

            case '/':
                kind = LexKind.Slash;
                NextChar();
                if (this.CurerntChar == '/')
                {
                    kind = LexKind.SlashSlash;
                    NextChar();
                }
                break;

            case '"':
            case '\'':
                this.kind        = LexKind.String;
                this.stringValue = ScanString();
                break;

            default:
                if (xmlCharType.IsDigit(this.CurerntChar))
                {
                    kind        = LexKind.Number;
                    numberValue = ScanNumber();
                }
                else if (xmlCharType.IsStartNCNameChar(this.CurerntChar))
                {
                    kind        = LexKind.Name;
                    this.name   = ScanName();
                    this.prefix = string.Empty;
                    // "foo:bar" is one lexem not three because it doesn't allow spaces in between
                    // We should distinct it from "foo::" and need process "foo ::" as well
                    if (this.CurerntChar == ':')
                    {
                        NextChar();
                        // can be "foo:bar" or "foo::"
                        if (this.CurerntChar == ':')     // "foo::"
                        {
                            NextChar();
                            kind = LexKind.Axe;
                        }
                        else                            // "foo:*", "foo:bar" or "foo: "
                        {
                            this.prefix = this.name;
                            if (this.CurerntChar == '*')
                            {
                                NextChar();
                                this.name = "*";
                            }
                            else if (xmlCharType.IsStartNCNameChar(this.CurerntChar))
                            {
                                this.name = ScanName();
                            }
                            else
                            {
                                throw XPathException.Create(Res.Xp_InvalidName, SourceText);
                            }
                        }
                    }
                    else
                    {
                        SkipSpace();
                        if (this.CurerntChar == ':')
                        {
                            NextChar();
                            // it can be "foo ::" or just "foo :"
                            if (this.CurerntChar == ':')
                            {
                                NextChar();
                                kind = LexKind.Axe;
                            }
                            else
                            {
                                throw XPathException.Create(Res.Xp_InvalidName, SourceText);
                            }
                        }
                    }
                    SkipSpace();
                    this.canBeFunction = (this.CurerntChar == '(');
                }
                else
                {
                    throw XPathException.Create(Res.Xp_InvalidToken, SourceText);
                }
                break;
            }
            return(true);
        }
        public bool NextLex()
        {
            prevLexEnd = curIndex;
            SkipSpace();
            lexStart = curIndex;
            switch (curChar)
            {
            case '\0':
                kind = LexKind.Eof;
                return(false);

            case ',':
            case '@':
            case '(':
            case ')':
            case '|':
            case '*':
            case '[':
            case ']':
            case '+':
            case '-':
            case '=':
            case '#':
            case '$':
            case '{':
            case '}':
                kind = (LexKind)curChar;
                NextChar();
                break;

            case '<':
                kind = LexKind.Lt;
                NextChar();
                if (curChar == '=')
                {
                    kind = LexKind.Le;
                    NextChar();
                }
                break;

            case '>':
                kind = LexKind.Gt;
                NextChar();
                if (curChar == '=')
                {
                    kind = LexKind.Ge;
                    NextChar();
                }
                break;

            case '!':
                kind = LexKind.Bang;
                NextChar();
                if (curChar == '=')
                {
                    kind = LexKind.Ne;
                    NextChar();
                }
                break;

            case '.':
                kind = LexKind.Dot;
                NextChar();
                if (curChar == '.')
                {
                    kind = LexKind.DotDot;
                    NextChar();
                }
                else if (xmlCharType.IsDigit(curChar))
                {
                    ScanFraction();
                }
                break;

            case '/':
                kind = LexKind.Slash;
                NextChar();
                if (curChar == '/')
                {
                    kind = LexKind.SlashSlash;
                    NextChar();
                }
                break;

            case '"':
            case '\'':
                ScanString();
                break;

            default:
                if (xmlCharType.IsDigit(curChar))
                {
                    ScanNumber();
                }
                else if (xmlCharType.IsStartNCNameChar(curChar))
                {
                    kind        = LexKind.Name;
                    this.name   = ScanNCName();
                    this.prefix = string.Empty;
                    int saveSourceIndex = curIndex;
                    // "foo:bar" is one lexem not three because it doesn't allow spaces in between
                    // We should distinct it from "foo::" and need process "foo ::" as well
                    if (curChar == ':')
                    {
                        NextChar();
                        // can be "foo:bar" or "foo::"
                        if (curChar == ':')     // "foo::"
                        {
                            NextChar();
                            kind = LexKind.Axis;
                        }
                        else                    // "foo:*", "foo:bar" or "foo: "
                        {
                            if (curChar == '*')
                            {
                                NextChar();
                                this.prefix = this.name;
                                this.name   = "*";
                            }
                            else if (xmlCharType.IsStartNCNameChar(curChar))
                            {
                                this.prefix = this.name;
                                this.name   = ScanNCName();
                            }
                            else
                            {
                                // this lex is something like "foo:?". Let's it be recognized as name "foo"
                                // and leave ":-" to be scaned late as unknown lex.
                                SetSourceIndex(saveSourceIndex);
                            }
                        }
                    }
                    else
                    {
                        SkipSpace();
                        if (curChar == ':')
                        {
                            NextChar();
                            // it can be "foo ::" or just "foo :"
                            if (curChar == ':')
                            {
                                NextChar();
                                kind = LexKind.Axis;
                            }
                            else
                            {
                                // this lex is something like "foo :?". Let's it be recognized as name "foo"
                                // and leave ":-" to be scaned late as unknown lex.
                                SetSourceIndex(saveSourceIndex);
                            }
                        }
                    }
                    // look ahead for '('. I don't want curIndex to be moved by SkipSpace() here to be able to detect presize lexem size.
                    saveSourceIndex = curIndex;
                    SkipSpace();
                    this.canBeFunction = (curChar == '(');
                    SetSourceIndex(saveSourceIndex);
                }
                else
                {
                    kind = LexKind.Unknown;
                    NextChar();
                }
                break;
            }
            return(true);
        }