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()23 Token::Token()
24 {
25 }
26 
27 
~Token()28 Token::~Token()
29 {
30 }
31 
32 
start(char c,std::istream & istr)33 bool Token::start(char c, std::istream& istr)
34 {
35 	_value = c;
36 	return false;
37 }
38 
39 
finish(std::istream & istr)40 void Token::finish(std::istream& istr)
41 {
42 }
43 
44 
tokenClass() const45 Token::Class Token::tokenClass() const
46 {
47 	return INVALID_TOKEN;
48 }
49 
50 
asString() const51 std::string Token::asString() const
52 {
53 	return _value;
54 }
55 
56 
57 #if defined(POCO_HAVE_INT64)
asInteger64() const58 Int64 Token::asInteger64() const
59 {
60 	return NumberParser::parse64(_value);
61 }
62 
63 
asUnsignedInteger64() const64 UInt64 Token::asUnsignedInteger64() const
65 {
66 	return NumberParser::parseUnsigned64(_value);
67 }
68 #endif
69 
70 
asInteger() const71 int Token::asInteger() const
72 {
73 	return NumberParser::parse(_value);
74 }
75 
76 
asUnsignedInteger() const77 unsigned Token::asUnsignedInteger() const
78 {
79 	return NumberParser::parseUnsigned(_value);
80 }
81 
82 
asFloat() const83 double Token::asFloat() const
84 {
85 	return NumberParser::parseFloat(_value);
86 }
87 
88 
asChar() const89 char Token::asChar() const
90 {
91 	return _value.empty() ? 0 : _value[0];
92 }
93 
94 
InvalidToken()95 InvalidToken::InvalidToken()
96 {
97 }
98 
99 
~InvalidToken()100 InvalidToken::~InvalidToken()
101 {
102 }
103 
104 
tokenClass() const105 Token::Class InvalidToken::tokenClass() const
106 {
107 	return INVALID_TOKEN;
108 }
109 
110 
EOFToken()111 EOFToken::EOFToken()
112 {
113 }
114 
115 
~EOFToken()116 EOFToken::~EOFToken()
117 {
118 }
119 
120 
tokenClass() const121 Token::Class EOFToken::tokenClass() const
122 {
123 	return EOF_TOKEN;
124 }
125 
126 
WhitespaceToken()127 WhitespaceToken::WhitespaceToken()
128 {
129 }
130 
131 
~WhitespaceToken()132 WhitespaceToken::~WhitespaceToken()
133 {
134 }
135 
136 
tokenClass() const137 Token::Class WhitespaceToken::tokenClass() const
138 {
139 	return WHITESPACE_TOKEN;
140 }
141 
142 
start(char c,std::istream & istr)143 bool 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)154 void 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