Skip to content

Commit 6f8bbc6

Browse files
committed
Use 64 bit integers (if available) when int is not big enough
1 parent 1d674b7 commit 6f8bbc6

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

JSON/include/Poco/JSON/DefaultHandler.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ class JSON_API DefaultHandler : public Handler
9292
/// An integer value is read
9393

9494

95+
#if defined(POCO_HAVE_INT64)
96+
virtual void value(Int64 v);
97+
/// A 64-bit integer value is read
98+
#endif
99+
100+
95101
virtual void value(const std::string& s);
96102
/// A string value is read.
97103

@@ -135,6 +141,13 @@ inline void DefaultHandler::value(int v)
135141
setValue(v);
136142
}
137143

144+
#if defined(POCO_HAVE_INT64)
145+
inline void DefaultHandler::value(Int64 v)
146+
{
147+
setValue(v);
148+
}
149+
#endif
150+
138151

139152
inline void DefaultHandler::value(const std::string& s)
140153
{

JSON/include/Poco/JSON/Handler.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3131
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
3232
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33-
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
33+
// FOR ANY DAMAGES OR OTHER LIABILITY, W#if defined(POCO_HAVE_INT64)HETHER IN CONTRACT, TORT OR OTHERWISE,
3434
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
3535
// DEALINGS IN THE SOFTWARE.
3636
//
@@ -78,6 +78,12 @@ class JSON_API Handler
7878

7979
virtual void value(int v) = 0;
8080
/// An integer value is read
81+
82+
83+
#if defined(POCO_HAVE_INT64)
84+
virtual void value(Int64 v) = 0;
85+
/// A 64-bit integer value is read
86+
#endif
8187

8288

8389
virtual void value(const std::string& value) = 0;

JSON/src/Parser.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,20 @@ void Parser::readValue(const Token* token)
566566
case Token::INTEGER_LITERAL_TOKEN:
567567
if ( _handler != NULL )
568568
{
569-
_handler->value(token->asInteger());
569+
int value = token->asInteger();
570+
#if defined(POCO_HAVE_INT64)
571+
if ( value == std::numeric_limits<int>::max()
572+
|| value == std::numeric_limits<int>::min() )
573+
{
574+
_handler->value(NumberParser::parse64(token->asString()));
575+
}
576+
else
577+
{
578+
_handler->value(token->asInteger());
579+
}
580+
#else
581+
_handle->value(value);
582+
#endif
570583
}
571584
break;
572585
case Token::KEYWORD_TOKEN:

0 commit comments

Comments
 (0)