Skip to content

Commit 7d1b7c0

Browse files
dmcppcheckclaude
andcommitted
Make Stream::get(), peek() and unget() protected
Calling them from outside Stream would skip the lookahead buffer, UTF-16 decoding and CR handling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b812a85 commit 7d1b7c0

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,6 @@ class simplecpp::TokenList::Stream {
295295
public:
296296
virtual ~Stream() = default;
297297

298-
virtual int get() = 0;
299-
virtual int peek() = 0;
300-
virtual void unget() = 0;
301-
302298
/**
303299
* Read the next character. CR and CR LF are returned as LF.
304300
* At the end of the input, EOF converted to unsigned char is returned
@@ -346,6 +342,11 @@ class simplecpp::TokenList::Stream {
346342
}
347343

348344
protected:
345+
/** Raw input, used only by the Stream class. Call readChar(), peekChar() and ungetChar() instead. */
346+
virtual int get() = 0;
347+
virtual int peek() = 0;
348+
virtual void unget() = 0;
349+
349350
void init() {
350351
// initialize since we use peek() in getAndSkipBOM()
351352
isUtf16 = false;
@@ -444,6 +445,7 @@ namespace {
444445
init();
445446
}
446447

448+
protected:
447449
int get() override {
448450
return istr.get();
449451
}
@@ -468,6 +470,7 @@ namespace {
468470
init();
469471
}
470472

473+
protected:
471474
int get() override {
472475
if (pos >= size)
473476
return EOF;
@@ -512,6 +515,7 @@ namespace {
512515
file = nullptr;
513516
}
514517

518+
protected:
515519
int get() override {
516520
lastCh = fgetc(file);
517521
return lastCh;

0 commit comments

Comments
 (0)