File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -300,6 +300,8 @@ class simplecpp::TokenList::Stream {
300300
301301protected:
302302 void init () {
303+ // initialize since we use peek() in getAndSkipBOM()
304+ isUtf16 = false ;
303305 bom = getAndSkipBOM ();
304306 isUtf16 = (bom == 0xfeff || bom == 0xfffe );
305307 }
@@ -338,6 +340,7 @@ class simplecpp::TokenList::Stream {
338340 }
339341
340342 unsigned short bom;
343+ protected:
341344 bool isUtf16;
342345};
343346
@@ -389,7 +392,14 @@ class FileStream : public simplecpp::TokenList::Stream {
389392 return ch;
390393 }
391394 virtual void unget () {
392- ungetc (lastCh, file);
395+ if (isUtf16) {
396+ // TODO: use ungetc() as well
397+ // UTF-16 has subsequent unget() calls
398+ fseek (file, -1 , SEEK_CUR);
399+ }
400+ else
401+ ungetc (lastCh, file);
402+
393403 }
394404 virtual bool good () {
395405 return lastCh != EOF;
You can’t perform that action at this time.
0 commit comments