mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Added custom implementation of strtol() (issue #465)
`char` is now treated as an integral type (issue #337, #370)
This commit is contained in:
@@ -8,12 +8,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "./ctype.hpp"
|
||||
#include "./math.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Polyfills {
|
||||
|
||||
inline bool isFloat(const char* s) {
|
||||
if (!s) return false;
|
||||
|
||||
if (!strcmp(s, "NaN")) return true;
|
||||
if (issign(*s)) s++;
|
||||
if (!strcmp(s, "Infinity")) return true;
|
||||
|
||||
22
include/ArduinoJson/Polyfills/isInteger.hpp
Normal file
22
include/ArduinoJson/Polyfills/isInteger.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright Benoit Blanchon 2014-2017
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./ctype.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Polyfills {
|
||||
|
||||
inline bool isInteger(const char* s) {
|
||||
if (!s) return false;
|
||||
if (issign(*s)) s++;
|
||||
while (isdigit(*s)) s++;
|
||||
return *s == '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ inline T parseFloat(const char* s) {
|
||||
typedef typename traits::mantissa_type mantissa_t;
|
||||
typedef typename traits::exponent_type exponent_t;
|
||||
|
||||
if (!s) return 0;
|
||||
|
||||
bool negative_result = false;
|
||||
switch (*s) {
|
||||
case '-':
|
||||
|
||||
@@ -9,48 +9,32 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../Configuration.hpp"
|
||||
#include "./ctype.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Polyfills {
|
||||
template <typename T>
|
||||
T parseInteger(const char *s);
|
||||
T parseInteger(const char *s) {
|
||||
if (!s) return 0;
|
||||
|
||||
template <>
|
||||
inline long parseInteger<long>(const char *s) {
|
||||
return ::strtol(s, NULL, 10);
|
||||
}
|
||||
T result = 0;
|
||||
bool negative_result = false;
|
||||
|
||||
template <>
|
||||
inline unsigned long parseInteger<unsigned long>(const char *s) {
|
||||
return ::strtoul(s, NULL, 10);
|
||||
}
|
||||
switch (*s) {
|
||||
case '-':
|
||||
negative_result = true;
|
||||
case '+':
|
||||
s++;
|
||||
break;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int parseInteger<int>(const char *s) {
|
||||
return ::atoi(s);
|
||||
}
|
||||
while (isdigit(*s)) {
|
||||
result = static_cast<T>(result * 10 + (*s - '0'));
|
||||
s++;
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
template <>
|
||||
inline long long parseInteger<long long>(const char *s) {
|
||||
return ::strtoll(s, NULL, 10);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline unsigned long long parseInteger<unsigned long long>(const char *s) {
|
||||
return ::strtoull(s, NULL, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_USE_INT64
|
||||
template <>
|
||||
inline __int64 parseInteger<__int64>(const char *s) {
|
||||
return ::_strtoi64(s, NULL, 10);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline unsigned __int64 parseInteger<unsigned __int64>(const char *s) {
|
||||
return ::_strtoui64(s, NULL, 10);
|
||||
}
|
||||
#endif
|
||||
return negative_result ? static_cast<T>(result*-1) : result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user