Skip to content

Commit

Permalink
fixed reading of files with multi-byte characters in FileStream
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 19, 2022
1 parent f761852 commit 1781870
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ class FileStream : public simplecpp::TokenList::Stream {
}

virtual int get() {
lastCh = fgetc(file);
unsigned char ch;
const int res = fread(&ch, 1, 1, file);
lastCh = (res != 1 && feof(file)) ? EOF : ch;
return lastCh;
}
virtual int peek() {
Expand All @@ -386,7 +388,7 @@ class FileStream : public simplecpp::TokenList::Stream {
return ch;
}
virtual void unget() {
ungetc(lastCh, file);
fseek(file, -1, SEEK_CUR);
}
virtual bool good() {
return lastCh != EOF;
Expand Down

0 comments on commit 1781870

Please sign in to comment.