本文整理汇总了C++中std::istream::unget方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::unget方法的具体用法?C++ istream::unget怎么用?C++ istream::unget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::unget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReaderObject
ReaderObject
FileReader::parse(std::istream& stream)
{
int c = stream.get();
stream.unget();
if (c == '{')
{
Json::Reader reader;
Json::Value root;
if (reader.parse(stream, root))
{
return ReaderObject(std::make_shared<JsonReaderObjectImpl>(root));
}
else
{
log_error("json parse error: %1%", reader.getFormattedErrorMessages());
return ReaderObject();
}
}
else
{
std::shared_ptr<lisp::Lisp> sexpr = lisp::Parser::parse(stream, "<stream>");
if (sexpr)
{
return ReaderObject(std::make_shared<SExprReaderObjectImpl>(sexpr->get_list_elem(0)));
}
else
{
log_error("sexpr parse error");
return ReaderObject();
}
}
}
示例2: TestComment
char SplineGeometry::TestComment(std::istream& infile)
{
bool comment = true;
char ch = '\0';
while (comment && !infile.eof()) {
infile >> ch;
if (ch == '#') {
// skip comments
while (ch != '\n' && !infile.eof()) {
infile.get(ch);
}
} else if (ch == '\n') {
// skip empty lines
} else if (isblank(ch)) {
// skip whitespaces
} else if (ch == '-') {
// do not unget '-'
comment = false;
} else {
// end of comment
infile.unget();
comment = false;
}
}
return ch;
}
示例3: runtime_error
int Midi::Event::Parse(std::istream &f, int running)
{
delta = read_vl(f);
int p = f.get();
type = p >> 4;
if(!(type & 0x8))
{
type = running;
f.unget();
}
if(type == Midi::Event::Extra)
{
f.ignore(1);
int length = f.get();
f.ignore(length);
}
else
{
param1 = f.get();
param2 = f.get();
}
if(f.eof())
throw std::runtime_error("Cannot read event: file truncated");
return type;
}
示例4: rollbackStream
/**
* Method rolls back in passed std::istream-e by passed number of read characters.
*
* @param stream reference to stream which will be rolled back.
* @param size the value representing number of characters we want to roll back.
*/
void CiscoInputParser::rollbackStream(std::istream& stream, std::streamsize size)
{
for ( streamsize i = 0; i < size; ++i )
{
stream.unget();
}
}
示例5: skip_comment
// helper function: skip commment lines in the header of ppm image
void PPM_Image::skip_comment(std::istream &is) {
char c; is >> c;
while (c == '#') { // skipping comment lines
is.ignore(256, '\n');
is >> c;
}
is.unget();
}
示例6: trim_whitespaces
void trim_whitespaces(std::istream& is) {
while( is.good() ) {
if(! std::isspace( is.get() ) ) {
// When not space, go to previous character and break
is.unget();
return;
}
}
}std::istream& operator>>(std::istream& is, Matrix& m)
示例7: read
int asn_object::read(std::istream& istr){
char c1, c2;
if(!(istr>>c1)){
//istr.unget();
return -1;
}
if(!(istr>>c2)){
//istr.unget();
istr.unget();
return -1;
}
if(!isxdigit(c1) || !isxdigit(c2)){
istr.unget();
istr.unget();
return -1;
}
return hex2int(c1)*16 + hex2int(c2);
}
示例8: lex_name
Token lex_name(std::istream& stream) {
char c;
std::string name;
while (stream.get(c) && std::isalpha(c))
name.push_back(c);
if (stream)
stream.unget();
return {name_token, name};
}
示例9: lex_number
Token lex_number(std::istream& stream) {
char c;
std::string number;
while (stream.get(c) && std::isdigit(c))
number.push_back(c);
if (stream)
stream.unget();
return {number_token, number};
}
示例10: lex_operator
Token lex_operator(std::istream& stream) {
char c;
std::string op;
while (stream.get(c) && isoperator(c))
op.push_back(c);
if (stream)
stream.unget();
return {name_token, op};
}
示例11: getContinuousChar
int getContinuousChar(std::istream& is, char c)
{
int count = 1;
char p;
while (is >> p) {
if (p != c) break;
count++;
}
is.unget();
return count;
}
示例12: if
std::shared_ptr<Object> read_character(std::istream &in) {
std::stringstream buf;
int c = in.get();
if (in.eof()) {
throw "EOF while reading character";
}
buf.put(c);
for (; ;) {
c = in.get();
if (in.eof() || iswhitespace(c) || isterminator(c)) {
in.unget();
break;
}
buf.put(c);
}
std::string token = buf.str();
if (token.size() == 1) {
return std::make_shared<Character>( token[0] );
} else if (token == "newline") {
return std::make_shared<Character>( '\n' );
} else if (token == "space") {
return std::make_shared<Character>( ' ' );
} else if (token == "tab") {
return std::make_shared<Character>( '\t' );
} else if (token == "backspace") {
return std::make_shared<Character>( '\b' );
} else if (token == "formfeed") {
return std::make_shared<Character>( '\f' );
} else if (token == "return") {
return std::make_shared<Character>( '\r' );
} else if (token[0] == 'u') {
long uc = read_unicode_char(token, 1, 4, 16);
if (c >= 0xD800 && c <= 0xDFFF) {
// TODO: java clojure actually prints u + the hex value of uc
// is this any different than token?
throw "Invalid character constant: \\" + token;
}
return std::make_shared<Character>( uc );
} else if (token[0] == 'o') {
int len = token.size() - 1;
if (len > 3) {
throw "Invalid octal escape sequence length: " + std::to_string(len);
}
long uc = read_unicode_char(token, 1, len, 8);
if (uc > 0377) {
throw "Octal escape sequence mst be in range [0, 377].";
}
return std::make_shared<Character>( uc );
}
throw "Unsupported character: \\" + token;
}
示例13: readBranchLength
double readBranchLength(std::istream &iss)
{
bool foundNext = false;
while(not foundNext)
{
int ch = iss.get();
foundNext = ( ch == ')'
|| ch == ';'
|| ch == ',' ) ;
}
iss.unget();
return nan("");
}
示例14: goto_first_not_of
static bool goto_first_not_of(std::istream& s, const std::string& str)
{
char c;
while (s.get(c))
{
if (str.find(c) == std::string::npos)
{
s.unget();
return true;
}
}
return false;
}
示例15: undoScan
void Scanner::undoScan(std::istream& stream, int character_count)
{
for ( int i = 0; i < character_count; i++ )
{
stream.unget();
if ( stream.fail() == true )
{
stream.clear();
this->end_of_file = false;
stream.seekg(-(--character_count), std::ios::end);
return;
}
}
}