Skip to content

Commit b18a40f

Browse files
committed
fixed FileStream::unget() with subsequent calls (i.e. UTF-16 encoding)
1 parent f761852 commit b18a40f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

simplecpp.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class simplecpp::TokenList::Stream {
297297

298298
protected:
299299
void init() {
300+
// initialize since we use peek() in getAndSkipBOM()
301+
isUtf16 = false;
300302
bom = getAndSkipBOM();
301303
isUtf16 = (bom == 0xfeff || bom == 0xfffe);
302304
}
@@ -335,6 +337,7 @@ class simplecpp::TokenList::Stream {
335337
}
336338

337339
unsigned short bom;
340+
protected:
338341
bool isUtf16;
339342
};
340343

@@ -386,7 +389,14 @@ class FileStream : public simplecpp::TokenList::Stream {
386389
return ch;
387390
}
388391
virtual void unget() {
389-
ungetc(lastCh, file);
392+
if (isUtf16) {
393+
// TODO: use ungetc() as well
394+
// UTF-16 has subsequent unget() calls
395+
fseek(file, -1, SEEK_CUR);
396+
}
397+
else
398+
ungetc(lastCh, file);
399+
390400
}
391401
virtual bool good() {
392402
return lastCh != EOF;

0 commit comments

Comments
 (0)