Пример #1
0
        /// <summary>
        /// Returns a value indicating whether there is the tag ending at the specified position.
        /// </summary>
        /// <returns>
        /// If this value is less than zero, then there is no ending; otherwise the
        /// position after ending is returned.
        /// </returns>
        public override int MatchEnd(string sql, int position)
        {
            CheckInitialized();

            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (ParentTag != null && ParentTag.MatchEnd(sql, position) >= 0)
            {
                return(position);
            }

            Type myTag = (Parser as SqlParser).IsTag(sql, position);
            if (
                myTag != null &&
                !myTag.IsAssignableFrom(typeof(StringLiteralTag)) &&
                !myTag.IsAssignableFrom(typeof(BracesTag))
                )
            {
                return(position);
            }

            return(-1);
        }
Пример #2
0
        /// <summary>
        /// Checks whether there is the tag at the specified position
        /// in the specified sql.
        /// </summary>
        /// <name>The value of the Name property.</name>
        /// <returns>
        /// The position after the tag or -1 there is no tag at the position.
        /// </returns>
        internal static int MatchStart(string firstWord, string secondWord, string sql, int position)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, firstWord, 0, firstWord.Length, true) != 0)
            {
                return(-1);
            }

            position += firstWord.Length;

            ParserBase.SkipWhiteSpace(sql, ref position);
            if (position == sql.Length)
            {
                return(-1);
            }

            if (string.Compare(sql, position, secondWord, 0, secondWord.Length, true) != 0)
            {
                return(-1);
            }

            return(position + secondWord.Length);
        }
Пример #3
0
        /// <summary>
        /// Returns a value indicating whether there is the tag ending at the specified position.
        /// </summary>
        /// <returns>
        /// If this value is less than zero, then there is no ending; otherwise the
        /// position after ending is returned.
        /// </returns>
        private int MatchEnd(string sql, int position, int literalStartPos)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, cTagDelimiter, 0, cTagDelimiter.Length, true) != 0)
            {
                return(-1);
            }

            #region Check the next and previous symbols (where there are ' symbols)

            #region Determine the number of ' symbols before

            int myNumberOfApostBefore = 0;
            for (int myCurPos = position - 1; myCurPos >= literalStartPos; myCurPos--)
            {
                if (string.Compare(sql, myCurPos, cTagDelimiter, 0, cTagDelimiter.Length, true) == 0)
                {
                    myNumberOfApostBefore++;
                }
                else
                {
                    break;
                }
            }

            #endregion

            if (!(myNumberOfApostBefore == 1 && position == literalStartPos + 1))
            {
                if (myNumberOfApostBefore % 2 == 1)
                {
                    return(-1);
                }

                #region Check whether the next symbol is '

                if (position + 1 < sql.Length)
                {
                    if (string.Compare(sql, position + 1, cTagDelimiter, 0, cTagDelimiter.Length, true) == 0)
                    {
                        return(-1);
                    }
                }

                #endregion
            }

            #endregion

            return(position + cTagDelimiter.Length);
        }
Пример #4
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        protected virtual void InitializeFromDataCore(ParserBase parser, string value, bool hasContents)
        {
            Parser = parser;

            Value = value;

            HasContents = hasContents;

            IsInitialized = true;
        }
Пример #5
0
        /// <summary>
        /// Returns a value indicating whether there is the tag ending at the specified position.		///
        /// </summary>
        /// <returns>
        /// If this value is less than zero, then there is no ending; otherwise the
        /// position after ending is returned.
        /// </returns>
        public override int MatchEnd(string sql, int position)
        {
            CheckInitialized();

            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            return(MatchEndStatic(sql, position));
        }
Пример #6
0
        /// <summary>
        /// Reads the tag at the specified position in the specified sql string.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myLiteralStartPos = position;

            position = MatchStartStatic(sql, position);

            if (position < 0)
            {
                throw new Exception("Cannot read the StringLiteral tag.");
            }

            #region Read the literal value

            int myResult        = -1;
            int myValueStartPos = position;
            while (position < sql.Length)
            {
                myResult = MatchEnd(sql, position, myLiteralStartPos);
                if (myResult >= 0)
                {
                    if (position == myValueStartPos)
                    {
                        Value = string.Empty;
                    }
                    else
                    {
                        Value = sql.Substring(myValueStartPos, position - myValueStartPos);
                    }
                    break;
                }
                position++;
            }

            if (myResult < 0)
            {
                throw new Exception("Cannot read the StringLiteral tag.");
            }

            #endregion

            Parser = parser;

            HasContents = false;

            return(myResult);
        }
Пример #7
0
        /// <summary>
        /// Checks whether there is the tag end at the specified position
        /// in the specified sql.
        /// </summary>
        /// <returns>
        /// The position after the tag or -1 there is no tag end at the position.
        /// </returns>
        public static int MatchEndStatic(string sql, int position)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, cEndTag, 0, cEndTag.Length, true) != 0)
            {
                return(-1);
            }

            return(position + cEndTag.Length);
        }
Пример #8
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        public void InitializeFromData(ParserBase parser, string value, bool hasContents)
        {
            #region Check the arguments

            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            #endregion

            InitializeFromDataCore(parser, value, hasContents);

            IsInitialized = true;
        }
Пример #9
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <param name="parentTag">
        /// The parent tag of this tag. This argument is used to determine
        /// the end of the tag (it can be the end of the parent tag).
        /// </param>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        public int InitializeFromText(ParserBase parser, string text, int position, TagBase parentTag)
        {
            #region Check the arguments

            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            #endregion

            int myResult = InitializeCoreFromText(parser, text, position, parentTag);

            IsInitialized = true;

            return(myResult);
        }
Пример #10
0
        /// <summary>
        /// Checks whether there is the tag at the specified position
        /// in the specified sql.
        /// </summary>
        /// <name>The value of the Name property.</name>
        /// <returns>
        /// The position after the tag or -1 there is no tag at the position.
        /// </returns>
        internal static int MatchStart(string name, string sql, int position)
        {
            #region Check the arguments

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, name, 0, name.Length, true) != 0)
            {
                return(-1);
            }

            return(position + name.Length);
        }
Пример #11
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myResult = MatchStartStatic(sql, position);

            if (myResult < 0)
            {
                throw new Exception("Cannot read the Braces tag.");
            }

            Parser = parser;

            HasContents = true;

            return(myResult);
        }
Пример #12
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myAfterTagStartPos = MatchStartStatic(sql, position);

            if (myAfterTagStartPos < 0)
            {
                throw new Exception("Cannot read the QuotedIdentifier tag.");
            }

            #region Read the identifier's value

            int myTagEndPos = sql.IndexOf(cTagDelimiter, myAfterTagStartPos, StringComparison.InvariantCultureIgnoreCase);
            if (myTagEndPos < 0)
            {
                throw new Exception("Cannot read the QuotedIdentifier tag.");
            }

            if (myAfterTagStartPos == myTagEndPos)
            {
                Value = string.Empty;
            }
            else
            {
                Value = sql.Substring(myAfterTagStartPos, myTagEndPos - myAfterTagStartPos);
            }

            #endregion

            Parser = parser;

            HasContents = false;

            return(myTagEndPos + cTagDelimiter.Length);
        }
Пример #13
0
 /// <summary>
 /// Reads the tag at the specified position in the specified word and separator array.
 /// </summary>
 /// <param name="parentTag">
 /// The parent tag of this tag. This argument is used to determine
 /// the end of the tag (it can be the end of the parent tag).
 /// </param>
 /// <returns>
 /// The position after the tag (at which to continue reading).
 /// </returns>
 protected abstract int InitializeCoreFromText(ParserBase parser, string text, int position, TagBase parentTag);