Esempio n. 1
0
        /// <summary>
        /// Asserts the given value is a token.
        /// </summary>
        /// <param name="value">value in question.</param>
        private static void AssertToken(string value)
        {
            Debug.Assert(!string.IsNullOrEmpty(value), "!string.IsNullOrEmpty(value)");
            int  index = 0;
            bool isQuotedString;

            HttpUtils.ReadTokenOrQuotedStringValue("header", value, ref index, out isQuotedString, message => new ODataException(message));
            Debug.Assert(!isQuotedString, "!isQuotedString");
            Debug.Assert(index == value.Length, "index == value.Length");
        }
Esempio n. 2
0
        /// <summary>
        /// Asserts the given value is a token or a quoted-string.
        /// </summary>
        /// <param name="value">value in question.</param>
        private static void AssertTokenOrQuotedString(string value)
        {
            if (value == null)
            {
                return;
            }

            int  index = 0;
            bool isQuotedString;

            HttpUtils.ReadTokenOrQuotedStringValue("header", value, ref index, out isQuotedString, message => new ODataException(message));
            Debug.Assert(index == value.Length, "index == value.Length");
        }
Esempio n. 3
0
        /// <summary>
        /// Reads a token or quoted-string value from the header.
        /// </summary>
        /// <returns>The token or quoted-string value that was read from the header.</returns>
        private HttpHeaderValueLexer ReadNextTokenOrQuotedString()
        {
            int    index = this.startIndexOfNextItem;
            bool   isQuotedString;
            string nextValue = HttpUtils.ReadTokenOrQuotedStringValue(this.httpHeaderName, this.httpHeaderValue, ref index, out isQuotedString, message => new ODataException(message));

            // Instead of testing whether result is null or empty, we check to see if the index have moved forward because we can encounter the empty quoted string "".
            if (index == this.startIndexOfNextItem)
            {
                throw new ODataException(Strings.HttpHeaderValueLexer_FailedToReadTokenOrQuotedString(this.httpHeaderName, this.httpHeaderValue, this.startIndexOfNextItem));
            }

            if (isQuotedString)
            {
                string original = this.httpHeaderValue.Substring(this.startIndexOfNextItem, index - this.startIndexOfNextItem);
                return(new HttpHeaderQuotedString(this.httpHeaderName, this.httpHeaderValue, nextValue, original, index));
            }

            return(new HttpHeaderToken(this.httpHeaderName, this.httpHeaderValue, nextValue, index));
        }