2018-04-16 16:34:39 +02:00
|
|
|
/**
|
|
|
|
StreamString.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2015 Markus Sattler. All rights reserved.
|
2019-04-26 18:41:42 +02:00
|
|
|
This file is part of the esp8266 core for Arduino environment.
|
2018-04-16 16:34:39 +02:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include "StreamString.h"
|
|
|
|
|
2019-04-26 18:41:42 +02:00
|
|
|
size_t StreamString::write(const uint8_t *data, size_t size) {
|
2018-04-16 16:34:39 +02:00
|
|
|
if(size && data) {
|
2019-05-11 10:16:05 +02:00
|
|
|
const unsigned int newlen = length() + size;
|
|
|
|
if(reserve(newlen + 1)) {
|
2019-04-26 18:41:42 +02:00
|
|
|
memcpy((void *) (wbuffer() + len()), (const void *) data, size);
|
2019-05-11 10:16:05 +02:00
|
|
|
setLen(newlen);
|
|
|
|
*(wbuffer() + newlen) = 0x00; // add null for string end
|
2018-04-16 16:34:39 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:41:42 +02:00
|
|
|
size_t StreamString::write(uint8_t data) {
|
2018-04-16 16:34:39 +02:00
|
|
|
return concat((char) data);
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:41:42 +02:00
|
|
|
int StreamString::available() {
|
2018-04-16 16:34:39 +02:00
|
|
|
return length();
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:41:42 +02:00
|
|
|
int StreamString::read() {
|
2018-04-16 16:34:39 +02:00
|
|
|
if(length()) {
|
|
|
|
char c = charAt(0);
|
|
|
|
remove(0, 1);
|
|
|
|
return c;
|
|
|
|
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:41:42 +02:00
|
|
|
int StreamString::peek() {
|
2018-04-16 16:34:39 +02:00
|
|
|
if(length()) {
|
|
|
|
char c = charAt(0);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:41:42 +02:00
|
|
|
void StreamString::flush() {
|
2018-04-16 16:34:39 +02:00
|
|
|
}
|
|
|
|
|