1 // 2 // Token.cpp 3 // 4 // Library: Foundation 5 // Package: Streams 6 // Module: StringTokenizer 7 // 8 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 9 // and Contributors. 10 // 11 // SPDX-License-Identifier: BSL-1.0 12 // 13 14 15 #include "Poco/Token.h" 16 #include "Poco/NumberParser.h" 17 #include "Poco/Ascii.h" 18 19 20 namespace Poco { 21 22 Token()23Token::Token() 24 { 25 } 26 27 ~Token()28Token::~Token() 29 { 30 } 31 32 start(char c,std::istream & istr)33bool Token::start(char c, std::istream& istr) 34 { 35 _value = c; 36 return false; 37 } 38 39 finish(std::istream & istr)40void Token::finish(std::istream& istr) 41 { 42 } 43 44 tokenClass() const45Token::Class Token::tokenClass() const 46 { 47 return INVALID_TOKEN; 48 } 49 50 asString() const51std::string Token::asString() const 52 { 53 return _value; 54 } 55 56 57 #if defined(POCO_HAVE_INT64) asInteger64() const58Int64 Token::asInteger64() const 59 { 60 return NumberParser::parse64(_value); 61 } 62 63 asUnsignedInteger64() const64UInt64 Token::asUnsignedInteger64() const 65 { 66 return NumberParser::parseUnsigned64(_value); 67 } 68 #endif 69 70 asInteger() const71int Token::asInteger() const 72 { 73 return NumberParser::parse(_value); 74 } 75 76 asUnsignedInteger() const77unsigned Token::asUnsignedInteger() const 78 { 79 return NumberParser::parseUnsigned(_value); 80 } 81 82 asFloat() const83double Token::asFloat() const 84 { 85 return NumberParser::parseFloat(_value); 86 } 87 88 asChar() const89char Token::asChar() const 90 { 91 return _value.empty() ? 0 : _value[0]; 92 } 93 94 InvalidToken()95InvalidToken::InvalidToken() 96 { 97 } 98 99 ~InvalidToken()100InvalidToken::~InvalidToken() 101 { 102 } 103 104 tokenClass() const105Token::Class InvalidToken::tokenClass() const 106 { 107 return INVALID_TOKEN; 108 } 109 110 EOFToken()111EOFToken::EOFToken() 112 { 113 } 114 115 ~EOFToken()116EOFToken::~EOFToken() 117 { 118 } 119 120 tokenClass() const121Token::Class EOFToken::tokenClass() const 122 { 123 return EOF_TOKEN; 124 } 125 126 WhitespaceToken()127WhitespaceToken::WhitespaceToken() 128 { 129 } 130 131 ~WhitespaceToken()132WhitespaceToken::~WhitespaceToken() 133 { 134 } 135 136 tokenClass() const137Token::Class WhitespaceToken::tokenClass() const 138 { 139 return WHITESPACE_TOKEN; 140 } 141 142 start(char c,std::istream & istr)143bool WhitespaceToken::start(char c, std::istream& istr) 144 { 145 if (Ascii::isSpace(c)) 146 { 147 _value = c; 148 return true; 149 } 150 return false; 151 } 152 153 finish(std::istream & istr)154void WhitespaceToken::finish(std::istream& istr) 155 { 156 int c = istr.peek(); 157 while (Ascii::isSpace(c)) 158 { 159 istr.get(); 160 _value += (char) c; 161 c = istr.peek(); 162 } 163 } 164 165 166 } // namespace Poco 167