Ejemplo n.º 1
0
        private HtmlReaderStringValue ReadStringValue()
        {
            bool quote = false;
            //_propertyQuote = "";
            HtmlReaderStringValue value = new HtmlReaderStringValue();
            //value.Quote = "";
            char quoteChar = (char)PeekChar();
            if (quoteChar == '"' || quoteChar == '\'')
            {
                quote = true;
                //_propertyQuote = quoteChar.ToString();
                value.Quote = quoteChar;
                GetChar();
            }

            _stringBuilder.Remove(0, _stringBuilder.Length);
            while (true)
            {
                GetChar();
                if (_charInt == -1
                    || (quote && (_char == quoteChar || ((_char == '"' || _char == '\'') && PeekChar() == '>')))
                    || (!quote && (_char == ' ' || _char == '\t' || _char == '\r' || _char == '\n'))
                    || _char == '>' || (_char == '/' && PeekChar() == '>')
                    )
                    break;
                _stringBuilder.Append(_char);
            }
            //_propertyValue = _stringBuilder.ToString();
            //_propertyValue = HtmlCharCodes.TranslateCode(_propertyValue);
            value.Value = HtmlCharCodes.TranslateCode(_stringBuilder.ToString());
            return value;
        }
Ejemplo n.º 2
0
        private HtmlReaderStringValue ReadStringValue()
        {
            HtmlReaderStringValue value = new HtmlReaderStringValue();

            bool quote = false;
            char quoteChar = (char)_charStreamReader.PeekChar();
            if (quoteChar == '"' || quoteChar == '\'')
            {
                quote = true;
                value.Quote = quoteChar;
                _charStreamReader.ReadChar();
            }

            char car = '\0';

            Func<bool> isString_v1 = () =>
            {
                if (quote)
                {
                    if (car == quoteChar)
                    {
                        _charStreamReader.ReadChar();
                        return false;
                    }
                    if ((car == '"' || car == '\'') && _charStreamReader.PeekChar(1) == '>')
                    {
                        _charStreamReader.ReadChar();
                        return false;
                    }
                }
                else
                {
                    if (car == ' ' || car == '\t' || car == '\r' || car == '\n')
                        return false;
                    if (car == '>' || (car == '/' && _charStreamReader.PeekChar(1) == '>'))
                        return false;
                }
                // bad test see _useReadAttributeValue_v2
                if (car == '>' || (car == '/' && _charStreamReader.PeekChar(1) == '>'))
                    return false;
                return true;
            };

            Func<bool> isString_v2 = () =>
            {
                if (quote)
                {
                    if (car == quoteChar)
                    {
                        _charStreamReader.ReadChar();
                        return false;
                    }
                    if ((car == '"' || car == '\'') && _charStreamReader.PeekChar(1) == '>')
                    {
                        _charStreamReader.ReadChar();
                        return false;
                    }
                }
                else
                {
                    if (car == ' ' || car == '\t' || car == '\r' || car == '\n')
                        return false;
                    if (car == '>' || (car == '/' && _charStreamReader.PeekChar(1) == '>'))
                        return false;
                }
                return true;
            };

            Func<bool> isString;
            if (!_useReadAttributeValue_v2)
                isString = isString_v1;
            else
                isString = isString_v2;

            _stringBuilder.Remove(0, _stringBuilder.Length);
            while (true)
            {
                int code = _charStreamReader.PeekChar();
                if (code == -1)
                    break;
                car = (char)code;
                //if ((quote && (car == quoteChar || ((car == '"' || car == '\'') && _charStreamReader.PeekChar(1) == '>')))
                //    || (!quote && (car == ' ' || car == '\t' || car == '\r' || car == '\n'))
                //    || car == '>' || (car == '/' && _charStreamReader.PeekChar(1) == '>'))
                //    break;
                //if (quote)
                //{
                //    if (car == quoteChar)
                //    {
                //        _charStreamReader.ReadChar();
                //        break;
                //    }
                //    if ((car == '"' || car == '\'') && _charStreamReader.PeekChar(1) == '>')
                //    {
                //        _charStreamReader.ReadChar();
                //        break;
                //    }
                //}
                //else
                //{
                //    if (car == ' ' || car == '\t' || car == '\r' || car == '\n')
                //        break;
                //    if (car == '>' || (car == '/' && _charStreamReader.PeekChar(1) == '>'))
                //        break;
                //}
                if (!isString())
                    break;
                _stringBuilder.Append(car);
                _charStreamReader.ReadChar();
            }
            value.Value = HtmlCharCodes.TranslateCode(_stringBuilder.ToString());
            return value;
        }