本文整理汇总了C++中std::istream::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::peek方法的具体用法?C++ istream::peek怎么用?C++ istream::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: skip_quals
// Skip quals header and qual values (read_len) of them.
void skip_quals(std::istream& is, size_t read_len) {
ignore_line(is);
size_t quals = 0;
while(is.good() && quals < read_len) {
skip_newlines(is);
is.ignore(read_len - quals + 1, '\n');
quals += is.gcount();
if(is)
++read_len;
}
skip_newlines(is);
if(quals == read_len && (is.peek() == '@' || is.peek() == EOF))
return;
throw std::runtime_error("Invalid fastq sequence");
}
示例2: verificarFirma
bool Verificador::verificarFirma(ParDeClaves& parDeClaves,const std::string& firma,std::istream& mensaje){
RSA* rsa = parDeClaves;
EVP_PKEY* pk = EVP_PKEY_new();
EVP_MD_CTX ctx;
EVP_PKEY_set1_RSA(pk,parDeClaves);
EVP_MD_CTX_init(&ctx);
M_EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_PAD_PKCS1/*EVP_MD_CTX_FLAG_PAD_X931*/);
EVP_VerifyInit_ex(&ctx, EVP_get_digestbynid(NID_sha1), NULL);
while(!mensaje.eof()){
unsigned char buffer[tamanio_de_buffer_default];
mensaje.read((char*)buffer,tamanio_de_buffer_default);
EVP_VerifyUpdate(&ctx, buffer, mensaje.gcount());
mensaje.peek();
}
int ok = EVP_VerifyFinal(&ctx, (unsigned char*)firma.c_str(), firma.size(), pk);
EVP_MD_CTX_cleanup(&ctx);
// El free esta en el constructor de ParDeClaves no puede
// liberarse aca
//FIPS_rsa_free(pk.pkey.rsa);
EVP_PKEY_free(pk);
return ok==1;
}
示例3: readHeader
void MailMessage::readHeader(std::istream& istr)
{
clear();
MessageHeader::read(istr);
istr.get(); // \r
if ('\n' == istr.peek()) istr.get(); // \n
}
示例4: cmnDataDeSerializeText
void cmnDataDeSerializeText(std::string & data,
std::istream & inputStream,
const char delimiter)
throw (std::runtime_error)
{
// reset string content
data = "";
bool lastCharWasEscape = false;
char newChar;
// seek around to figure how many characters are left in input stream
std::streampos currentPosition = inputStream.tellg();
inputStream.seekg(0, inputStream.end);
std::streamoff charactersLeft = inputStream.tellg() - currentPosition;
inputStream.seekg(currentPosition);
// keep reading as long as we don't run into comma
while (charactersLeft > 0 // there is still something to read
&& ((inputStream.peek() != delimiter) // we are not finding the delimiter
|| lastCharWasEscape) // unless the delimiter has been "escaped"
) {
inputStream.get(newChar);
--charactersLeft;
if ((newChar == '\\')
&& !lastCharWasEscape) {
lastCharWasEscape = true;
} else {
lastCharWasEscape = false;
data.append(1, newChar);
}
}
}
示例5: while
boost::shared_ptr<Token> Tokenizer::next(std::istream &is, SymbolTablePtr symbols) {
// Clear any whitespace until the next token. This works because no token
// depends on _leading_ whitespace, as long as it is separated from the
// previous token.
while(std::isspace(is.peek())) is.get();
// Now that we've cleared whitespace, may be at EOF.
if(!is.good()) return NULL;
for(size_t i = 0; i < TOKEN_PARSING_FUNCS_LENGTH; i++) {
std::streampos pos = is.tellg();
TokenParsingFunc f = TOKEN_PARSING_FUNCS[i];
boost::shared_ptr<Token> token = f(is, symbols);
if(token) {
return token;
} else {
is.seekg(pos);
}
}
std::cerr << "Tokenizer error!" << std::endl;
exit(0);
return NULL;
}
示例6: parse
bool Configuration::parse(std::istream& in) {
try {
/* It looks like BOM */
if(in.peek() == Bom[0]) {
char bom[4];
in.get(bom, 4);
/* This is not a BOM, rewind back */
if(bom[0] != Bom[0] || bom[1] != Bom[1] || bom[2] != Bom[2]) in.seekg(0);
/* Or set flag */
else _flags |= InternalFlag::HasBom;
}
/* Parse file */
CORRADE_INTERNAL_ASSERT_OUTPUT(parse(in, this, {}).empty());
} catch(std::string e) {
Error() << "Utility::Configuration::Configuration():" << e;
clear();
return false;
}
return true;
}
示例7: getFirstCharacter
static int getFirstCharacter(std::istream & in)
{
int const c = in.peek();
if ( c >= 0 )
in.putback(c);
return c;
}
示例8: chomp
void chomp(std::istream& data)
{
if (data.peek() == '\n') {
std::string junk;
std::getline(data, junk);
}
}
示例9: getlinePortable
/*!
* @if jp
* @brief 入力ストリームから1行読み込む
* @else
* @brief Read a line from input stream
* @endif
*/
int getlinePortable(std::istream& istr, std::string& line)
{
char c;
std::stringstream s;
while (istr.get(c))
{
if (c == '\n')
{
break;
}
else if (c == '\r')
{
if (istr.peek() == '\n')
{
istr.ignore();
}
break;
}
else
{
s << c;
}
}
line = s.str();
return static_cast<int>(line.size());
}
示例10: memset
//----------------------------------------------------------------------
//! \brief Read an InboxListItem from an istream
//! \param aStream The stream to read from
//----------------------------------------------------------------------
void InboxListItem::readFromStream
(
std::istream &aStream
)
{
int i;
int num;
char dummy;
uint8 idSize;
uint8 id[16];
i = 0;
aStream >> num;
idSize = (uint8)num;
aStream >> dummy; // ignore '-' inserted between id size and id
memset( id, 0, 16 );
while( aStream.peek() != '\n' && !aStream.eof() )
{
aStream >> num;
aStream >> dummy; //ignore',' inserted between chars of id
if( i < 16 )
id[i++] = (uint8)num;
}
aStream >> dummy; // ignore '\n' inserted after item
messageId = MessageId( idSize, id );
mIsValid = TRUE;
}
示例11: readChar
int PropertyFileConfiguration::readChar(std::istream& istr)
{
for (;;)
{
int c = istr.get();
if (c == '\\')
{
c = istr.get();
switch (c)
{
case 't':
return '\t';
case 'r':
return '\r';
case 'n':
return '\n';
case 'f':
return '\f';
case '\r':
if (istr.peek() == '\n')
istr.get();
continue;
case '\n':
continue;
default:
return c;
}
}
else if (c == '\n' || c == '\r')
return 0;
else
return c;
}
}
示例12: eatArray
static Value eatArray(std::istream& stream)
{
Value obj(Type::arrayValue);
while (!stream.eof())
{
ltrim(stream);
if (stream.peek() == ']')
{
stream.get();
break;
}
obj.push_back(eatValue(stream));
ltrim(stream);
char token = stream.get();
if (token == '/')
{
eatComment(stream);
token = stream.get();
}
if (token == ']')
break;
assert(token == ',');
}
return obj;
};
示例13: readTemplateCommand
std::string Template::readTemplateCommand(std::istream& in)
{
std::string command;
readWhiteSpace(in);
int c = in.get();
while(c != -1)
{
if ( Ascii::isSpace(c) )
break;
if ( c == '?' && in.peek() == '>' )
{
in.putback(c);
break;
}
if ( c == '=' && command.length() == 0 )
{
command = "echo";
break;
}
command += c;
c = in.get();
}
return command;
}
示例14: readInTrips
void BarGeraImporter::readInTrips(InputGraph& graph, std::istream& is)
{
skipComments(is);
is.ignore(numeric_limits<streamsize>::max(),'>');//Skip to #zones
unsigned z;
is >> z;
skipComments(is);
is.ignore(numeric_limits<streamsize>::max(),'\n');//Skip next line
skipComments(is);
endMetadata(is);
int currentNode = -1;
vector<pair<unsigned, double> > currentDestinations;
while(true) {
skipComments(is);
if(!is.good()) break;
if(is.peek() == 'O') {
is.ignore(6);
//New origin. Add the old one to the graph if it has destinations.
if (!currentDestinations.empty()) {
for(vector<pair<unsigned,double> >::iterator i = currentDestinations.begin(); i != currentDestinations.end(); ++i)
graph.addDemand(currentNode-1, i->first, i->second);
currentDestinations.clear();
}
is >> currentNode;
continue;
} else {
示例15: next_is_between
bool Parser::next_is_between(char c1, char c2) {
if (is->eof()) return false;
char c = is->peek();
return ((c >= c1) && (c <= c2));
}