mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Added custom implementation of strtod() (issue #453)
This commit is contained in:
40
include/ArduinoJson/Polyfills/isFloat.hpp
Normal file
40
include/ArduinoJson/Polyfills/isFloat.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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"
|
||||
#include "./math.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Polyfills {
|
||||
|
||||
inline bool isFloat(const char* s) {
|
||||
if (!strcmp(s, "NaN")) return true;
|
||||
if (issign(*s)) s++;
|
||||
if (!strcmp(s, "Infinity")) return true;
|
||||
|
||||
while (isdigit(*s)) s++;
|
||||
|
||||
bool has_dot = *s == '.';
|
||||
if (has_dot) {
|
||||
s++;
|
||||
while (isdigit(*s)) s++;
|
||||
}
|
||||
|
||||
bool has_exponent = *s == 'e' || *s == 'E';
|
||||
if (has_exponent) {
|
||||
s++;
|
||||
if (issign(*s)) s++;
|
||||
if (!isdigit(*s)) return false;
|
||||
while (isdigit(*s)) s++;
|
||||
}
|
||||
|
||||
return (has_dot || has_exponent) && *s == '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user