Skip to content

Commit daa4c4a

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

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

simplecpp.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ class simplecpp::TokenList::Stream {
335335
}
336336

337337
unsigned short bom;
338+
protected:
338339
bool isUtf16;
339340
};
340341

@@ -386,7 +387,14 @@ class FileStream : public simplecpp::TokenList::Stream {
386387
return ch;
387388
}
388389
virtual void unget() {
389-
ungetc(lastCh, file);
390+
if (isUtf16) {
391+
// TODO: use ungetc() as well
392+
// UTF-16 has subsequent unget() calls
393+
fseek(file, -1, SEEK_CUR);
394+
}
395+
else
396+
ungetc(lastCh, file);
397+
390398
}
391399
virtual bool good() {
392400
return lastCh != EOF;

0 commit comments

Comments
 (0)