DEPRECATED[M], createMemoryBlock(), text stream ...

This commit is contained in:
2022-05-11 20:55:51 +03:00
parent 0897a8369f
commit ef8ffcd02f
12 changed files with 84 additions and 39 deletions

View File

@@ -38,8 +38,8 @@ class PITextStream {
public:
PITextStream(PIBinaryStream<P> * stream): s(stream) {}
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
PITextStream<P> & space() {s->binaryStreamAppend(' '); return *this;}
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
void append(const PIString & v) {
if (v.isEmpty()) return;
auto utf8 = v.toUTF8();
@@ -56,24 +56,53 @@ public:
char takeChar(bool * ok) {return (char)s->binaryStreamTakeByte(ok);}
bool skipSpaces() {
//if ()
}
PIString takeLine() {
PIByteArray line;
PIByteArray ret;
bool ok = true;
for (;;) {
char b = takeChar(&ok);
if (!ok || b == '\n') break;
if (b != '\r')
line.append((uchar)b);
ret.append((uchar)b);
}
return PIString::fromUTF8(line);
return PIString::fromUTF8(ret);
}
PIString takeWord() {
static PIConstChars spaces(" \t\n\r");
return takeUntil(spaces);
}
PIString takeCWord() {
static PIConstChars chars(" \t\n\r:;%$&#@!?~/*-+=.,\\\"'`[](){}<>");
return takeUntil(chars);
}
PIString takeWord();
private:
PIString takeUntil(const PIConstChars & chars) {
static PIConstChars spaces(" \t\n\r");
bool ok = true;
char c = skipWhile(spaces, &ok);
if (!ok || chars.contains(c)) return PIString();
PIByteArray ret;
ret.append((uchar)c);
for (;;) {
c = takeChar(&ok);
if (!ok || chars.contains(c)) break;
ret.append((uchar)c);
}
return PIString::fromUTF8(ret);
}
// returns first non-"chars" char
char skipWhile(const PIConstChars & chars, bool * rok) {
bool ok = true;
char c = 0;
for (;;) {
c = takeChar(&ok);
if (!ok || !chars.contains(c)) break;
}
if (rok) *rok = ok;
return c;
}
PIBinaryStream<P> * s;
};