Exemplo n.º 1
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

            SqlStringParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

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

            position += firstWord.Length;

            SqlStringParserBase.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);
        }
Exemplo n.º 2
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

            SqlStringParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

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

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

            return(-1);
        }
Exemplo n.º 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

            SqlStringParserBase.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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        protected virtual void InitializeFromDataCore(SqlStringParserBase parser, string value, bool hasContents)
        {
            Parser = parser;

            Value = value;

            HasContents = hasContents;

            IsInitialized = true;
        }
Exemplo n.º 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

            SqlStringParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            return(MatchEndStatic(sql, position));
        }
Exemplo n.º 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(SqlStringParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            SqlStringParserBase.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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Checks whether there is the tag start at the specified position
        /// in the specified sql.
        /// </summary>
        /// <returns>
        /// The position after the tag or -1 there is no tag start at the position.
        /// </returns>
        public static int MatchStartStatic(string sql, int position)
        {
            #region Check the arguments

            SqlStringParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

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

            return(position + cTagDelimiter.Length);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        public void InitializeFromData(SqlStringParserBase parser, string value, bool hasContents)
        {
            #region Check the arguments

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

            #endregion

            InitializeFromDataCore(parser, value, hasContents);

            IsInitialized = true;
        }
Exemplo n.º 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(SqlStringParserBase 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);
        }
Exemplo n.º 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");
            }

            SqlStringParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

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

            return(position + name.Length);
        }
Exemplo n.º 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(SqlStringParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            SqlStringParserBase.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);
        }
Exemplo n.º 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(SqlStringParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            SqlStringParserBase.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);
        }
Exemplo n.º 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(SqlStringParserBase parser, string text, int position, TagBase parentTag);