unleashed-firmware/lib/file_reader/file_reader.cpp
Albert Kharisov c583cce5bd
[FL-1401] Add Universal TV remote (#539)
* Remove excess headers
* Add ButtonPanel
* Add Popup
* Move FileReader to standalone object
* Universal remote (part 1)
* Universal remote (part 2)
* Global rename tranciever/file_parser
* Compile assets
* syntax fix
* English: rename tranceiver to transceiver.

Co-authored-by: あく <alleteam@gmail.com>
2021-06-25 16:52:27 +03:00

39 lines
1.1 KiB
C++

#include "file_reader/file_reader.hpp"
std::string FileReader::getline(File* file) {
std::string str;
size_t newline_index = 0;
bool found_eol = false;
while(1) {
if(file_buf_cnt > 0) {
size_t end_index = 0;
char* endline_ptr = (char*)memchr(file_buf, '\n', file_buf_cnt);
newline_index = endline_ptr - file_buf;
if(endline_ptr == 0) {
end_index = file_buf_cnt;
} else if(newline_index < file_buf_cnt) {
end_index = newline_index + 1;
found_eol = true;
} else {
furi_assert(0);
}
str.append(file_buf, end_index);
memmove(file_buf, &file_buf[end_index], file_buf_cnt - end_index);
file_buf_cnt = file_buf_cnt - end_index;
if(found_eol) break;
}
file_buf_cnt +=
fs_api->file.read(file, &file_buf[file_buf_cnt], sizeof(file_buf) - file_buf_cnt);
if(file_buf_cnt == 0) {
break; // end of reading
}
}
return str;
}