/// <summary> /// Init constructor. /// </summary> public JSonReaderTokenInfo(string text, JSonReaderTokenType type, int line, int offset) { Text = text; Type = type; Line = line; Offset = offset; }
/// <summary> /// Init constructor. /// </summary> public TokenDataString(string token, JSonReaderTokenType type, object value, IJSonObject jValue) : base(type) { if (string.IsNullOrEmpty(token)) throw new ArgumentNullException("token"); Token = token; Value = value; ValueAsJSonObject = jValue; }
/// <summary> /// Init constructor. /// </summary> public TokenDataString(string token, JSonReaderTokenType type, object value, IJSonObject jValue) : base(type) { if (string.IsNullOrEmpty(token)) { throw new ArgumentNullException("token"); } Token = token; Value = value; ValueAsJSonObject = jValue; }
/// <summary> /// Init constructor. /// </summary> public TokenDataChar(char token, JSonReaderTokenType type) : base(type) { Token = token; }
/// <summary> /// Reads next token from the input source with a possibility to treat already known character as the one read. /// Option required mostly for JSON elements that don't have a closing tokens (i.e.: ']' for arrays) and used for number and keywords. /// </summary> private JSonReaderTokenInfo ReadNextToken(bool fromCurrentChar) { // token was already read in advanced and put on the stack: if (_getTokenFromStack) { _getTokenFromStack = false; // reached end of input stream: if (_input.IsEof) { return(new JSonReaderTokenInfo(string.Empty, JSonReaderTokenType.EndOfText, _input.Line, _input.LineOffset)); } if (_tokens.Count == 0) { throw new JSonReaderException("Lack of tokens", (JSonReaderTokenInfo)null); } return(_tokens.Peek()); } if (fromCurrentChar) { // clear the whitespace characters: StringHelper.ReadWhiteChars(_input); } // reached end of input stream: if (_input.IsEof) { return(new JSonReaderTokenInfo(string.Empty, JSonReaderTokenType.EndOfText, _input.Line, _input.LineOffset)); } char tokenChar = _input.CurrentChar; string tokenString = tokenChar.ToString(); JSonReaderTokenType tokenType = JSonReaderTokenType.Unknown; // check if this is one of the already known tokens... foreach (var tokenDef in AvailableTokens) { if (tokenDef.Token == tokenChar) { tokenType = tokenDef.Type; break; } } // is this the beginning of a keyword? if (tokenType == JSonReaderTokenType.Unknown && char.IsLetter(tokenChar)) { tokenType = JSonReaderTokenType.Keyword; } // is this the beginning of the number? if (tokenType == JSonReaderTokenType.Unknown && (char.IsDigit(tokenChar) || tokenChar == '-')) { tokenType = JSonReaderTokenType.Number; } // if this is still unknown element... if (tokenType == JSonReaderTokenType.Unknown) { throw new JSonReaderException("Invalid token found", tokenString, _input.Line, _input.LineOffset); } JSonReaderTokenInfo nextToken = new JSonReaderTokenInfo(tokenString, tokenType, _input.Line, _input.LineOffset); _tokens.Push(nextToken); // return it: return(nextToken); }
protected TokenData(JSonReaderTokenType type) { Type = type; }