blob: 040e2d7c02a1b5f3263bdfbaa271d860578d8e79 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include "TextFile.class.h"
bool TextFile::write(String str, bool addnl) {
ByteArray a(str, m_encoding);
if (addnl) a += (u8int)'\n';
return File::write(a);
}
String TextFile::readLine(char separator) {
const u32int bufflen = 512;
String ret;
ByteArray temp;
while (1) {
temp.resize(bufflen);
u32int r = read(temp);
u32int l = r;
for (u32int i = 0; i < r; i++) {
if (temp[i] == separator) {
l = i;
temp.resize(i);
break;
}
}
ret += temp.toString(m_encoding);
if (l != r or r != bufflen) {
if (l != r) seek((r - l) - 1, SM_BACKWARD);
return ret;
}
}
}
|