Skip to content

Commit

Permalink
rename getc/ungetc
Browse files Browse the repository at this point in the history
  • Loading branch information
dhconnelly committed Nov 28, 2024
1 parent 30e5ed0 commit 0daf43f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/json/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,43 @@ constexpr const std::string_view to_string(TokenType type) {
assert(false);
}

int Scanner::getc() {
int Scanner::GetChar() {
if (pos_ >= size_) return EOF;
clearerr(f_);
int c = fgetc(f_);
if (c != EOF) ++pos_;
return c;
}

void Scanner::ungetc(int c) {
void Scanner::UngetChar(int c) {
--pos_;
assert(::ungetc(c, f_) == c);
}

void Scanner::SkipWhitespace() {
while (true) {
int c = getc();
int c = GetChar();
if (c == EOF) return;
if (!isspace(c)) {
ungetc(c);
UngetChar(c);
return;
}
}
}

std::optional<char> Scanner::Peek() {
int c = getc();
int c = GetChar();
if (c == EOF) {
if (errno == EAGAIN || errno == EWOULDBLOCK) return {};
if (ferror(f_)) throw SystemError(errno);
return {};
}
ungetc(c);
UngetChar(c);
return c;
}

char Scanner::Advance() {
int c = getc();
int c = GetChar();
if (c == EOF) {
if (ferror(f_)) throw SystemError(errno);
else throw ParsingError("unexpected eof");
Expand Down
4 changes: 2 additions & 2 deletions src/json/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Scanner {
void SkipWhitespace();
std::optional<char> Peek();
char Advance();
int getc();
void ungetc(int c);
int GetChar();
void UngetChar(int c);
std::optional<Token> Scan();

FILE* f_;
Expand Down

0 comments on commit 0daf43f

Please sign in to comment.