本文整理汇总了C++中StreamBuffer::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamBuffer::peek方法的具体用法?C++ StreamBuffer::peek怎么用?C++ StreamBuffer::peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamBuffer
的用法示例。
在下文中一共展示了StreamBuffer::peek方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLine
bool getLine(StreamBuffer &buffer, std::string &line){
line.clear();
if(buffer.empty()){
return false;
}
do {
const int ch = buffer.get();
if(ch == '\n'){
break;
} else if(ch == '\r'){
if(buffer.peek() == '\n'){
continue;
}
break;
}
line.push_back(ch);
} while(!buffer.empty());
return true;
}
示例2: load
void CsvParser::load(const char *file){
LOG_POSEIDON_DEBUG("Loading CSV file: ", file);
StreamBuffer buffer;
fileGetContents(buffer, file);
buffer.put('\n');
std::vector<OptionalMap> data;
std::vector<std::vector<std::string> > rows;
{
std::vector<std::string> row;
std::string token;
bool first = true;
bool inQuote = false;
do {
char ch = buffer.get();
if(ch == '\r'){
if(buffer.peek() == '\n'){
buffer.get();
}
ch = '\n';
}
if(first){
first = false;
if(ch == '\"'){
inQuote = true;
continue;
}
}
if(ch == '\"'){
if(inQuote){
if(buffer.peek() == '\"'){
buffer.get();
token.push_back('\"');
} else {
inQuote = false;
}
continue;
}
}
if(!inQuote){
if((ch == ',') || (ch == '\n')){
std::string trimmed;
const std::size_t begin = token.find_first_not_of(" \t\r\n");
if(begin != std::string::npos){
const std::size_t end = token.find_last_not_of(" \t\r\n") + 1;
trimmed = token.substr(begin, end - begin);
}
row.push_back(STD_MOVE(trimmed));
token.clear();
first = true;
if(ch == '\n'){
rows.push_back(STD_MOVE(row));
row.clear();
}
continue;
}
}
token.push_back(ch);
} while(!buffer.empty());
}
if(rows.empty() || rows.front().empty()){
LOG_POSEIDON_ERROR("The first line of a CSV file may not be empty.");
DEBUG_THROW(Exception, sslit("Bad CSV header"));
}
const std::size_t columnCount = rows.front().size();
std::vector<SharedNts> keys(columnCount);
for(std::size_t i = 0; i < columnCount; ++i){
AUTO_REF(key, rows.front().at(i));
for(std::size_t j = 0; j < i; ++j){
if(keys.at(j) == key){
LOG_POSEIDON_ERROR("Duplicate key: ", key);
DEBUG_THROW(Exception, sslit("Duplicate key"));
}
}
keys.at(i).assign(key.c_str());
}
for(std::size_t i = 1; i < rows.size(); ++i){
rows.at(i - 1).swap(rows.at(i));
}
rows.pop_back();
{
std::size_t line = 1;
std::size_t i = 0;
while(i < rows.size()){
AUTO_REF(row, rows.at(i));
++line;
if((row.size() == 1) && row.front().empty()){
for(std::size_t j = i + 1; j < rows.size(); ++j){
rows.at(j - 1).swap(rows.at(j));
}
//.........这里部分代码省略.........