1
0
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:
apicquot 2019-02-04 03:08:54 -05:00 committed by Develo
parent 8c01516f8a
commit e43a586f0d
3 changed files with 18 additions and 2 deletions

View File

@ -121,6 +121,21 @@ const char* File::name() const {
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) {
if (!_impl) {
return File();

View File

@ -72,6 +72,7 @@ public:
void close();
operator bool() const;
const char* name() const;
String readString() override;
protected:
FileImplPtr _p;

View File

@ -101,7 +101,7 @@ class Stream: public Print {
// returns the number of characters placed in the buffer (0 means no valid data found)
// Arduino String functions to be added here
String readString();
virtual String readString();
String readStringUntil(char terminator);
protected: