本文整理汇总了C++中StringPiece::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::assign方法的具体用法?C++ StringPiece::assign怎么用?C++ StringPiece::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringPiece
的用法示例。
在下文中一共展示了StringPiece::assign方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readLine
LineReader::State LineReader::readLine(StringPiece& line) {
bol_ = eol_; // Start past what we already returned
for (;;) {
// Search for newline
char* newline = static_cast<char*>(memchr(eol_, '\n', end_ - eol_));
if (newline) {
eol_ = newline + 1;
break;
} else if (state_ != kReading || (bol_ == buf_ && end_ == bufEnd_)) {
// If the buffer is full with one line (line too long), or we're
// at the end of the file, return what we have.
eol_ = end_;
break;
}
// We don't have a full line in the buffer, but we have room to read.
// Move to the beginning of the buffer.
memmove(buf_, eol_, end_ - eol_);
end_ -= (eol_ - buf_);
bol_ = buf_;
eol_ = end_;
// Refill
ssize_t available = bufEnd_ - end_;
ssize_t n = readFull(fd_, end_, available);
if (n < 0) {
state_ = kError;
n = 0;
} else if (n < available) {
state_ = kEof;
}
end_ += n;
}
line.assign(bol_, eol_);
return eol_ != bol_ ? kReading : state_;
}