Skip to content

Commit

Permalink
Modernize tokenizer.cc to use nullptr instead of NULL.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 710750767
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 30, 2024
1 parent 937e9dc commit 4d0382e
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/google/protobuf/io/tokenizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ void Tokenizer::Refresh() {
record_start_ = 0;
}

const void* data = NULL;
buffer_ = NULL;
const void* data = nullptr;
buffer_ = nullptr;
buffer_pos_ = 0;
do {
if (!input_->Next(&data, &buffer_size_)) {
Expand All @@ -302,14 +302,14 @@ inline void Tokenizer::RecordTo(std::string* target) {

inline void Tokenizer::StopRecording() {
// Note: The if() is necessary because some STL implementations crash when
// you call string::append(NULL, 0), presumably because they are trying to
// be helpful by detecting the NULL pointer, even though there's nothing
// wrong with reading zero bytes from NULL.
// you call string::append(nullptr, 0), presumably because they are trying
// to be helpful by detecting the nullptr pointer, even though there's
// nothing wrong with reading zero bytes from nullptr.
if (buffer_pos_ != record_start_) {
record_target_->append(buffer_ + record_start_,
buffer_pos_ - record_start_);
}
record_target_ = NULL;
record_target_ = nullptr;
record_start_ = -1;
}

Expand Down Expand Up @@ -496,21 +496,21 @@ Tokenizer::TokenType Tokenizer::ConsumeNumber(bool started_with_zero,
}

void Tokenizer::ConsumeLineComment(std::string* content) {
if (content != NULL) RecordTo(content);
if (content != nullptr) RecordTo(content);

while (current_char_ != '\0' && current_char_ != '\n') {
NextChar();
}
TryConsume('\n');

if (content != NULL) StopRecording();
if (content != nullptr) StopRecording();
}

void Tokenizer::ConsumeBlockComment(std::string* content) {
int start_line = line_;
int start_column = column_ - 2;

if (content != NULL) RecordTo(content);
if (content != nullptr) RecordTo(content);

while (true) {
while (current_char_ != '\0' && current_char_ != '*' &&
Expand All @@ -519,7 +519,7 @@ void Tokenizer::ConsumeBlockComment(std::string* content) {
}

if (TryConsume('\n')) {
if (content != NULL) StopRecording();
if (content != nullptr) StopRecording();

// Consume leading whitespace and asterisk;
ConsumeZeroOrMore<WhitespaceNoNewline>();
Expand All @@ -530,10 +530,10 @@ void Tokenizer::ConsumeBlockComment(std::string* content) {
}
}

if (content != NULL) RecordTo(content);
if (content != nullptr) RecordTo(content);
} else if (TryConsume('*') && TryConsume('/')) {
// End of comment.
if (content != NULL) {
if (content != nullptr) {
StopRecording();
// Strip trailing "*/".
content->erase(content->size() - 2);
Expand All @@ -548,7 +548,7 @@ void Tokenizer::ConsumeBlockComment(std::string* content) {
AddError("End-of-file inside block comment.");
error_collector_->RecordError(start_line, start_column,
" Comment started here.");
if (content != NULL) StopRecording();
if (content != nullptr) StopRecording();
break;
}
}
Expand Down Expand Up @@ -619,10 +619,10 @@ bool Tokenizer::Next() {

switch (TryConsumeCommentStart()) {
case LINE_COMMENT:
ConsumeLineComment(NULL);
ConsumeLineComment(nullptr);
continue;
case BLOCK_COMMENT:
ConsumeBlockComment(NULL);
ConsumeBlockComment(nullptr);
continue;
case SLASH_NOT_COMMENT:
return true;
Expand Down Expand Up @@ -729,14 +729,14 @@ class CommentCollector {
has_comment_(false),
is_line_comment_(false),
can_attach_to_prev_(true) {
if (prev_trailing_comments != NULL) prev_trailing_comments->clear();
if (detached_comments != NULL) detached_comments->clear();
if (next_leading_comments != NULL) next_leading_comments->clear();
if (prev_trailing_comments != nullptr) prev_trailing_comments->clear();
if (detached_comments != nullptr) detached_comments->clear();
if (next_leading_comments != nullptr) next_leading_comments->clear();
}

~CommentCollector() {
// Whatever is in the buffer is a leading comment.
if (next_leading_comments_ != NULL && has_comment_) {
if (next_leading_comments_ != nullptr && has_comment_) {
comment_buffer_.swap(*next_leading_comments_);
}
}
Expand Down Expand Up @@ -774,13 +774,13 @@ class CommentCollector {
void Flush() {
if (has_comment_) {
if (can_attach_to_prev_) {
if (prev_trailing_comments_ != NULL) {
if (prev_trailing_comments_ != nullptr) {
prev_trailing_comments_->append(comment_buffer_);
}
has_trailing_comment_ = true;
can_attach_to_prev_ = false;
} else {
if (detached_comments_ != NULL) {
if (detached_comments_ != nullptr) {
detached_comments_->push_back(comment_buffer_);
}
}
Expand All @@ -797,9 +797,9 @@ class CommentCollector {

// If there's one comment, make sure it is detached.
if (count == 1) {
if (has_trailing_comment_ && prev_trailing_comments_ != NULL) {
if (has_trailing_comment_ && prev_trailing_comments_ != nullptr) {
std::string trail = *prev_trailing_comments_;
if (detached_comments_ != NULL) {
if (detached_comments_ != nullptr) {
// push trailing comment to front of detached
detached_comments_->insert(detached_comments_->begin(), 1, trail);
}
Expand Down

0 comments on commit 4d0382e

Please sign in to comment.