Changed String to be a typedef of std::string (issues #142 and #161)

This commit is contained in:
Benoit Blanchon
2015-11-25 21:09:18 +01:00
parent 8b66a25f66
commit 056682327b
5 changed files with 12 additions and 55 deletions

View File

@ -1,31 +0,0 @@
// Copyright Benoit Blanchon 2014-2015
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#ifndef ARDUINO
#include "../../include/ArduinoJson/Arduino/String.hpp"
#include <stdio.h> // for sprintf()
String::String(double value, unsigned char digits) {
char tmp[32];
sprintf(tmp, "%.*f", digits, value);
*this = tmp;
}
String::String(long value) {
char tmp[32];
sprintf(tmp, "%ld", value);
*this = tmp;
}
String::String(int value) {
char tmp[32];
sprintf(tmp, "%d", value);
*this = tmp;
}
#endif

View File

@ -76,20 +76,12 @@ JsonInteger JsonVariant::asInteger() const {
template <>
String JsonVariant::as<String>() const {
String s;
if ((_type == JSON_STRING || _type == JSON_UNPARSED) &&
_content.asString != NULL)
return String(_content.asString);
if (_type == JSON_INTEGER || _type == JSON_BOOLEAN)
return String(_content.asInteger);
if (_type >= JSON_FLOAT_0_DECIMALS) {
uint8_t decimals = static_cast<uint8_t>(_type - JSON_FLOAT_0_DECIMALS);
return String(_content.asFloat, decimals);
}
String s;
printTo(s);
s = _content.asString;
else
printTo(s);
return s;
}