| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- //
- // Token.cpp
- //
- // $Id: //poco/1.4/Foundation/src/Token.cpp#1 $
- //
- // Library: Foundation
- // Package: Streams
- // Module: StringTokenizer
- //
- // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
- // and Contributors.
- //
- // SPDX-License-Identifier: BSL-1.0
- //
- #include "Poco/Token.h"
- #include "Poco/NumberParser.h"
- #include "Poco/Ascii.h"
- namespace Poco {
- Token::Token()
- {
- }
- Token::~Token()
- {
- }
- bool Token::start(char c, std::istream& istr)
- {
- _value = c;
- return false;
- }
- void Token::finish(std::istream& istr)
- {
- }
- Token::Class Token::tokenClass() const
- {
- return INVALID_TOKEN;
- }
-
- std::string Token::asString() const
- {
- return _value;
- }
- #if defined(POCO_HAVE_INT64)
- Int64 Token::asInteger64() const
- {
- return NumberParser::parse64(_value);
- }
- UInt64 Token::asUnsignedInteger64() const
- {
- return NumberParser::parseUnsigned64(_value);
- }
- #endif
- int Token::asInteger() const
- {
- return NumberParser::parse(_value);
- }
- unsigned Token::asUnsignedInteger() const
- {
- return NumberParser::parseUnsigned(_value);
- }
- double Token::asFloat() const
- {
- return NumberParser::parseFloat(_value);
- }
- char Token::asChar() const
- {
- return _value.empty() ? 0 : _value[0];
- }
- InvalidToken::InvalidToken()
- {
- }
- InvalidToken::~InvalidToken()
- {
- }
- Token::Class InvalidToken::tokenClass() const
- {
- return INVALID_TOKEN;
- }
- EOFToken::EOFToken()
- {
- }
- EOFToken::~EOFToken()
- {
- }
- Token::Class EOFToken::tokenClass() const
- {
- return EOF_TOKEN;
- }
- WhitespaceToken::WhitespaceToken()
- {
- }
- WhitespaceToken::~WhitespaceToken()
- {
- }
- Token::Class WhitespaceToken::tokenClass() const
- {
- return WHITESPACE_TOKEN;
- }
- bool WhitespaceToken::start(char c, std::istream& istr)
- {
- if (Ascii::isSpace(c))
- {
- _value = c;
- return true;
- }
- return false;
- }
- void WhitespaceToken::finish(std::istream& istr)
- {
- int c = istr.peek();
- while (Ascii::isSpace(c))
- {
- istr.get();
- _value += (char) c;
- c = istr.peek();
- }
- }
- } // namespace Poco
|