コード例 #1
0
        private void WriteEscapedString(string str)
        {
            if (!Settings.UsesEscapeSequences)
            {
                _writer.Write(str);
                return;
            }

            foreach (char ch in str)
            {
                if (!VdfStructure.IsEscapable(ch))
                {
                    _writer.Write(ch);
                }
                else
                {
                    _writer.Write(VdfStructure.Escape);
                    _writer.Write(VdfStructure.GetEscape(ch));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Reads a single token. The value is stored in the 'Value' property.
        /// </summary>
        /// <returns>True if a token was read, false otherwise.</returns>
        public override bool ReadToken()
        {
            if (!SeekToken())
            {
                return(false);
            }

            _tokenSize = 0;

            while (EnsureBuffer())
            {
                char curChar = _charBuffer[_charPos];

                #region Comment

                if (_isComment)
                {
                    if (curChar == '\r' || curChar == '\n')
                    {
                        _isComment   = false;
                        Value        = new string(_tokenBuffer, 0, _tokenSize);
                        CurrentState = State.Comment;
                        return(true);
                    }
                    else
                    {
                        _tokenBuffer[_tokenSize++] = curChar;
                        _charPos++;
                        continue;
                    }
                }
                else if (!_isQuoted && _tokenSize == 0 && curChar == VdfStructure.Comment && _charBuffer[_charPos + 1] == VdfStructure.Comment)
                {
                    _isComment = true;
                    _charPos  += 2;
                    continue;
                }

                #endregion

                #region Escape

                if (curChar == VdfStructure.Escape)
                {
                    _tokenBuffer[_tokenSize++] = (!Settings.UsesEscapeSequences ? curChar : VdfStructure.GetUnescape(_charBuffer[++_charPos]));
                    _charPos++;
                    continue;
                }

                #endregion

                #region Quote

                if (curChar == VdfStructure.Quote || (!_isQuoted && Char.IsWhiteSpace(curChar)))
                {
                    Value        = new string(_tokenBuffer, 0, _tokenSize);
                    CurrentState = State.Property;
                    _charPos++;
                    return(true);
                }

                #endregion

                #region Object start/end

                if (curChar == VdfStructure.ObjectStart || curChar == VdfStructure.ObjectEnd)
                {
                    if (_isQuoted)
                    {
                        _tokenBuffer[_tokenSize++] = curChar;
                        _charPos++;
                        continue;
                    }
                    else if (_tokenSize != 0)
                    {
                        Value        = new string(_tokenBuffer, 0, _tokenSize);
                        CurrentState = State.Property;
                        return(true);
                    }
                    else
                    {
                        Value        = curChar.ToString();
                        CurrentState = State.Object;
                        _charPos++;
                        return(true);
                    }
                }

                #endregion

                #region Long token

                _tokenBuffer[_tokenSize++] = curChar;
                _charPos++;

                #endregion
            }

            return(false);
        }