mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Improved readString() for File (#5445)
* added new boards * corrected block size error * added board to last commit working well * override of readString for File class Stream::readString requires a timeout of 1 seconds + multiple memory resize * correct indent return if size 0 before reserve * correct indent * good indent * stricter test for end of string * same implementation than Stream by replacing timeRead by read * reading file by block of 256 * make sure there is an end of string * fixed bug for file size multiple of 256 string::concate(char*) needs a string terminator to work
This commit is contained in:
parent
8c01516f8a
commit
e43a586f0d
@ -121,6 +121,21 @@ const char* File::name() const {
|
|||||||
return _p->name();
|
return _p->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String File::readString()
|
||||||
|
{
|
||||||
|
String ret;
|
||||||
|
ret.reserve(size() - position());
|
||||||
|
char temp[256+1];
|
||||||
|
int countRead = readBytes(temp, sizeof(temp)-1);
|
||||||
|
while (countRead > 0)
|
||||||
|
{
|
||||||
|
temp[countRead] = 0;
|
||||||
|
ret += temp;
|
||||||
|
countRead = readBytes(temp, sizeof(temp)-1);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
File Dir::openFile(const char* mode) {
|
File Dir::openFile(const char* mode) {
|
||||||
if (!_impl) {
|
if (!_impl) {
|
||||||
return File();
|
return File();
|
||||||
|
@ -72,6 +72,7 @@ public:
|
|||||||
void close();
|
void close();
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
const char* name() const;
|
const char* name() const;
|
||||||
|
String readString() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FileImplPtr _p;
|
FileImplPtr _p;
|
||||||
|
@ -101,7 +101,7 @@ class Stream: public Print {
|
|||||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
// Arduino String functions to be added here
|
// Arduino String functions to be added here
|
||||||
String readString();
|
virtual String readString();
|
||||||
String readStringUntil(char terminator);
|
String readStringUntil(char terminator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user