TagPayloadCompound::TagPayloadCompound(istream& inStream){ char nxtByte = inStream.peek(); while(static_cast<TAG_TypeID>(nxtByte) != TAG_End){ payload.push_back(NBTTag(inStream)); nxtByte = inStream.peek(); } }
bool Response::read(istream& str) { ACE_CString version; ACE_CString status; ACE_CString reason; int ch = str.peek (); if (ch == eof_) { str.get (); // skip to eof return false; } // skip whitespace while (ACE_OS::ace_isspace (str.peek ())) { str.get (); } // get version ch = this->read_ws_field (str, version, MAX_VERSION_LENGTH); if (ch == eof_ || !ACE_OS::ace_isspace (ch)) return false; // invalid HTTP version string // skip whitespace while (ACE_OS::ace_isspace (str.peek ())) { str.get (); } // get status ch = this->read_ws_field (str, status, MAX_STATUS_LENGTH); if (ch == eof_ || !ACE_OS::ace_isspace (ch)) return false; // invalid HTTP status code // skip whitespace while (ACE_OS::ace_isspace (str.peek ())) { str.get (); } // get reason ch = this->read_field (str, reason, MAX_REASON_LENGTH, '\r'); if (ch == '\r') ch = str.get (); // get lf if (ch != '\n') return false; // HTTP reason string too long INET_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT ("ACE_INet_HTTP: <-- %C %C %C\n"), version.c_str (), status.c_str (), reason.c_str())); // get header lines if (!Header::read (str)) return false; // skip empty line ch = str.get (); while (ch != '\n' && ch != eof_) ch = str.get (); this->set_version(version); this->status_.set_status (status); this->status_.set_reason (reason); return true; }
bool t_dir_graph::read_format2(istream& input, const string first_line){ vector<t_vertex> verts; int adj; t_vertex v; uint datas = atoi(first_line.c_str()); while(input.peek() == '\n') input.ignore(1); // read the '\n' // read vertices for(uint i = 0; i < datas; i++){ input >> v; verts.push_back(v); while(input.peek() == '\n') input.ignore(1); // read the '\n' } for(uint i=0; i < verts.size(); i++) insert_vertex(verts[i]); // read adjacency matrix for(uint i=0; i < verts.size(); i++){ for(uint j=0; j < verts.size(); j++){ input >> adj; if(adj > 0) insert_arc(t_arc(verts[i], verts[j])); while(input.peek() == ' ') input.ignore(1); // read the ' ' while(input.peek() == '\n') input.ignore(1); // read the '\n' } } return true; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Properties::readQuotedString(istream& in) { char c; // Read characters until we see a quote while(in.get(c)) { if(c == '"') break; } // Read characters until we see the close quote string s; while(in.get(c)) { if((c == '\\') && (in.peek() == '"')) in.get(c); else if((c == '\\') && (in.peek() == '\\')) in.get(c); else if(c == '"') break; else if(c == '\r') continue; s += c; } return s; }
void eatWhiteSpaces (istream &input) { while (input.peek() == 32 || input.peek () == 10 || input.peek () == 13) input.get(); }
/** * \brief Tokenize a stream of XML by chopping it up into XMLTokens and * returning a vector of these tokens. * * This function consumes all data in the stream */ vector<XMLToken> XMLToken::tokenize(istream& istrm) { vector<XMLToken> tokens; while (istrm.good()) { chomp(istrm); if (!istrm.good()) break; // parse tag if (istrm.peek() == '<') { string tagname; bool isEndTag = false; istrm.get(); // skip < chomp(istrm); if (!istrm.good()) break; if (istrm.peek() == '/') { istrm.get(); // skip / isEndTag = true; } while (istrm.good() && (istrm.peek() != '>')) tagname += istrm.get(); istrm.get(); // skip > tokens.push_back(XMLToken(tagname,isEndTag)); } else { // parse string string buf = ""; while (istrm.good() && (istrm.peek() != '<')) buf += istrm.get(); tokens.push_back(XMLToken(buf)); } } return tokens; }
vector<vector<string> > getQueries(istream& input, int queryLines){ vector<vector<string> > queries; for (size_t i = 0; i < queryLines; i++) { vector<string> singleQuery; string temp; while(input.peek() != '\n' && input.peek()>0){ if(input.peek() == '.' || input.peek() == '~'){ singleQuery.push_back(temp); temp.clear(); input.get(); }else{ temp.push_back(input.get()); } } singleQuery.push_back(temp); queries.push_back(singleQuery); input.get(); } return queries; }
void translateStream(istream& inputStream, ostream& outputStream) { int i = 0; char ch; const int maxLength = 70; char word[maxLength] = {""}, translated[maxLength] = {""}; // no word case with eof handler while (!isalnum(inputStream.peek())){ if (inputStream.eof()) return; inputStream.get(ch); outputStream << ch; } // word case to obtain words while (isalnum(inputStream.peek())){ inputStream.get(word[i]); i++; } // obtain translation and send to output stream translateWord(word,translated); outputStream << translated; // recusive call translateStream(inputStream,outputStream); }
// reads chars from the stream until one of the closing chars is found // (either a comma, closing bracket or closing brace). The closing char // is NOT consumed. Function assumes the stream is pointing at the // first character of the value. // Note: This function is not used for strings. See readString() for that. string readUntilCloseChar(istream &istr) { string value; char next = static_cast<char>(istr.peek()); while ((next != ',') && (next != '}') && (next != ']')) { if (istr.eof()) { throw JSONParseException( "Stream unexpectedly ended without a closing char."); } if ((value.size() > 0) || (!isspace( next))) // don't add white space to the start of the value string { value += next; } istr.get(); // consume the char from the stream next = static_cast<char>(istr.peek()); } // Strip any whitespace off the end of the value string while (isspace(value.back())) { value.pop_back(); } return value; }
//--------------------------------------------------------------------------- unique_ptr<Expression> ExpressionParser::parseSingleExpression(istream& input, ExpressionType lastExpression, Environment& environment) { // read harriet::skipWhiteSpace(input); char a = input.get(); if(!input.good()) return nullptr; // other single letter operators if(a == '(') return make_unique<OpeningPharentesis>(); if(a == ')') return make_unique<ClosingPharentesis>(); if(a == '+') return make_unique<PlusOperator>(); if(a == '-') { if(lastExpression==ExpressionType::TBinaryOperator || lastExpression==ExpressionType::TUnaryOperator || lastExpression==ExpressionType::TOpeningPharentesis) return make_unique<UnaryMinusOperator>(); else return make_unique<MinusOperator>(); } if(a == '*') return make_unique<MultiplicationOperator>(); if(a == '/') return make_unique<DivisionOperator>(); if(a == '%') return make_unique<ModuloOperator>(); if(a == '^') return make_unique<ExponentiationOperator>(); if(a == '&') return make_unique<AndOperator>(); if(a == '|') return make_unique<OrOperator>(); if(a=='>' && input.peek()!='=') return make_unique<GreaterOperator>(); if(a=='<' && input.peek()!='=') return make_unique<LessOperator>(); if(a=='!' && input.peek()!='=') return make_unique<NotOperator>(); if(a=='=' && input.peek()!='=') return make_unique<AssignmentOperator>(); // check for string char b = input.get(); if(a=='"') { string result; while(b!='"' && a!='\\') { if(!input.good()) throw harriet::Exception{"unterminated string expression"}; result.push_back(b); a = b; b = input.get(); } return make_unique<StringValue>(result); } // check for two signed letters if(input.good()) { if(a=='=' && b=='=') return make_unique<EqualOperator>(); if(a=='>' && b=='=') return make_unique<GreaterEqualOperator>(); if(a=='<' && b=='=') return make_unique<LessEqualOperator>(); if(a=='!' && b=='=') return make_unique<NotEqualOperator>(); input.unget(); } else { input.clear(); } // check for a number input.unget(); if(isdigit(a)) { int32_t intNum; input >> intNum; if(input.peek()=='.' && input.good()) { float floatNum; input >> floatNum; return make_unique<FloatValue>(floatNum+intNum); } else { return make_unique<IntegerValue>(intNum);
bool fcnn::internal::read_comment(istream &is, string &s) { if (!is.good() || is.eof()) return false; char c; s.clear(); c = is.peek(); if (c != '#') return false; is.get(c); start_line: do { is.get(c); } while ((is.good() && !is.eof()) && ((c == ' ') || (c == '\t'))); if (is.eof()) return true; if (is.fail()) return false; while ((is) && (c != '\n')) { s += c; is.get(c); } if (is.eof()) return true; if (is.fail()) return false; if (c == '\n') { if (is.peek() == '#') { s += c; goto start_line; } else return true; } return true; }
void SpatialDomain::ignoreCrLf(istream &in) { char c = in.peek(); while (c == 10 || c == 13) { in.ignore(); c = in.peek(); } }
// Initialize a JSON object from a stream (presumably creating a whole // hierarchy) // // This is the big one. :) The expectation is that the first character // will be a '{' and the function will run until if finds a matching '}' // char. Along the way, it may create nested objects and/or arrays // (which means it may be called recursively - by way of // initValueFromStream()) // Note: The function will consume the closing brace from the stream void initFromStream(JSONObject &obj, istream &istr) { char nextChar; istr >> nextChar; checkChar(nextChar, '{'); // sanity check skipWhiteSpace(istr); // Check for empty object (and make sure we consume the }) nextChar = static_cast<char>(istr.peek()); if (nextChar == '}') { istr.ignore(); } while (nextChar != '}') // process the stream { // Quick sanity check if (istr.eof()) { throw JSONParseException("Unexpected end of data stream"); } // We expect to start the loop with the stream pointing to the opening quote // of the key nextChar = static_cast<char>(istr.peek()); checkChar(nextChar, '"'); string key = readString(istr); istr >> nextChar; // >> operator automatically skips white space checkChar(nextChar, ':'); // the separator between the key and the value skipWhiteSpace(istr); // Now. we're at the start of the value. // Add the key and value to our object obj[key] = initValueFromStream(istr); istr >> nextChar; // nextChar is guaranteed to be either a comma, close brace or close // bracket. //(If it was anything else, initValueFromStream() would have thrown an // exception.) // A bracket is an error, a brace means the object is done (and will be // checked at // the start of the while loop) and a comma needs to be thrown out (along // with any // following whitespace) to position us for the next key/value pair if (nextChar == ']') throw JSONParseException( "Invalid closing bracket while initializing object"); else if (nextChar == ',') { skipWhiteSpace(istr); // Check to see if another key/value pair really follows the comma // (because if one doesn't, the parser will get screwed up and may not // actually detect the problem). if (istr.peek() != '"') { throw JSONParseException( "Invalid comma (no key/value pair following it)"); } } } }
void Symbol::read(istream& in) { char ch = in.peek(); while(!isspace(ch) && (ch != '(') && (ch != ')')) { in.get(ch); name.push_back(ch); ch = in.peek(); } }
void skipwhite(istream &s) { s.get(); return; while(s.peek()==' ' || s.peek()=='\t') { char c=s.get(); cout<<"skip:"<<c<<endl; } }
TokenType ReadStringConst(istream& is, string& str, Coordinates& xy) { char c; bool eos = false; c = str[0]; str = ""; while (!is.eof()) { switch (c){ case '\'' : while (!is.eof() && !eos) { c = is.peek(); if (c == '\n') throw Error("wrong string literal", pos.first, pos.second); if (c == '\'') { GetSymb(is,xy); if (is.peek() != '\'') eos = true; } if (!eos) { str = str + c; GetSymb(is,xy); } } eos = false; break; case '#': { int symb = -1; c = is.peek(); if (GetState(c) != is_digit) throw Error("wrong string literal", pos.first, pos.second); is>>symb; if (symb < 0 || symb > 255) throw Error("wrong string literal", pos.first, pos.second); char ch = symb; str = str + ch; break; } default : { str = '\'' + str + '\''; return string_const; } } c = is.peek(); if ((!IsSep(c) && c != ' ') || c == '\'') GetSymb(is,xy); } str = '\'' + str + '\''; return string_const; }
static void eatWS( istream& is ) { int ch = is.peek(); while( ch == ' ' || ch == '\t' || ch == '\n' || ch == 0x0D || ch == 0x0A) { is.get(); if( !is ) { return; } ch = is.peek(); } }
static void eatNL( istream& is ) { int ch = is.peek(); while( ch != '\n' ) { is.get(); if( !is ) { return; } ch = is.peek(); } }
/** Determines type of next token without swallowing it. That means * the same token will be read again next time. */ char Calculator::lookAhead (istream &is) { while (isspace(is.peek())) // skip whitespace is.get(); if (is.eof()) return END; int c = is.peek(); if (isdigit(c) || c == '.') return NUMBER; if (isalpha(c)) return NAME; return char(c); }
vector<tag> getHtml(istream& input, int htmlLines){ vector<tag> html; stack<tag> holdTag; for (size_t i = 0; i < htmlLines; i++) { tag temp; input.ignore(LINESIZE, '<'); if (input.peek() == '/') { tag hold = holdTag.top(); holdTag.pop(); if (holdTag.empty()) { html.push_back(hold); }else{ holdTag.top().children.push_back(hold); } input.ignore(LINESIZE, '\n'); }else{ holdTag.push(tag()); input >> holdTag.top().tagName; if(holdTag.top().tagName.back() == '>'){ holdTag.top().tagName.erase(holdTag.top().tagName.end()-1); input.unget(); //remove the last char if the > char is found there } while(input.peek() != '>'){ string key, val; input.get(); getline(input, key, ' '); input.ignore(LINESIZE, '\"'); getline(input, val, '\"'); holdTag.top().attributes.insert(make_pair(key, val)); } } } return html; }
bool CPlayListRAM::LoadData(istream& stream) { CLog::Log(LOGINFO, "Parsing RAM"); CStdString strMMS; while( stream.peek() != '\n' && stream.peek() != '\r' ) strMMS += stream.get(); CLog::Log(LOGINFO, "Adding element %s", strMMS.c_str()); CFileItemPtr newItem(new CFileItem(strMMS)); newItem->SetPath(strMMS); Add(newItem); return true; }
TokenType ReadIdentifier(istream& is, string& str, Coordinates& xy) { char c = is.peek(); State st = GetState(is.peek()); while (st == is_letter || st == is_digit || st == is_emphasize) { str = str + GetSymb(is, xy); st = GetState(is.peek()); if (IsSyntaxError(st)) throw Error("syntax error", pos.first, pos.second); } return identifier; }
int GetString(string&strFound,istream&ifs) { strFound = ""; DFAEdge*ptDfa = &dfa; set<DFAEdge>::iterator edgeIt; int iChr; //skip leading WS while (true) { iChr=ifs.peek(); if (iChr == char_traits<char>::eof()) { ifs.clear(); break; } switch (iChr) { case '\r': case '\n': case '\t': case ' ': ifs.get(); continue; } break; } while (true) { char ch; if ((iChr=ifs.peek()) == char_traits<char>::eof()) { ifs.clear(); ch = '\0'; } else { ch = (char)iChr; } edgeIt = ptDfa->edges.find(ch); if (edgeIt == ptDfa->edges.end()) { return ptDfa->id; } strFound += ch; ifs.get(); ptDfa = &(*edgeIt); } return 0; }
// Initialize a JSON array from a stream // This is similar to initFromStream() above and may also be called // recursively by way of initValueFromStream() // The expectation is that the first character will be a '[' and it // will run until if finds a matching ']' char. Along the way it // may create nested objects and/or arrays. // Note: It will consume the closing bracket from the stream void initArrayFromStream(JSONArray &arr, istream &istr) { char nextChar; istr >> nextChar; checkChar(nextChar, '['); // sanity check skipWhiteSpace(istr); // Check for empty array (and make sure we consume the ]) nextChar = static_cast<char>(istr.peek()); if (nextChar == ']') { istr.ignore(); } while (nextChar != ']') // process the stream { // Quick sanity check if (istr.eof()) { throw JSONParseException("Unexpected end of data stream"); } // We expect to start the loop with the stream pointing to the // first character of the value // Add the value to our array arr.push_back(initValueFromStream(istr)); istr >> nextChar; // nextChar is guaranteed to be either a comma, close brace or close // bracket. //(If it was anything else, initValueFromStream() would have thrown an // exception.) // A brace is an error, a bracket means the array is done (and will be // checked at // the start of the while loop) and a comma needs to be thrown out (along // with any // following whitespace) to position us for the next value if (nextChar == '}') throw JSONParseException( "Invalid closing brace while initializing array"); else if (nextChar == ',') { skipWhiteSpace(istr); // Check to see if another key/value pair really follows the comma // (because if one doesn't, the parser will get screwed up and may not // actually detect the problem). if (istr.peek() == ']') { throw JSONParseException( "Invalid comma (array ended with no further values)"); } } } }
long SkipWhiteSpace(istream& s) { long c; c = s.peek(); while (IsWhiteSpace(c)) { s.get(); c = s.peek(); } if (c == EOF) return 0; else return 1; }
/*--------------- G e t C m d ( ) --------------- PURPOSE Accept a command from the keyboard. INPUT PARAMETERS cmdStream -- the stream from which commands are to be read pwlFcn -- the pwlFcn list. RETURN VALUE The command letter. */ string GetCmd(istream &cmdStream, DblLinkedList &pwlFcn) { // Display the current point before accepting each command. if (!pwlFcn.AtEnd()/* && cmdStream == cin*/) { // Display the current item. cout << "\nCURRENT ITEM" << endl; cout << pwlFcn.CurrentItem() << endl; } // Prompt for a new command. cout << "\n>"; string cmdLine; // Command line // Quit at end of a command file. if (cmdStream.peek() == EOF) { cmdLine = QuitCmd; if (cmdStream != cin) cout << cmdLine << endl; return cmdLine; } // Get the next command and return it. getline(cmdStream, cmdLine); if (cmdStream != cin) cout << cmdLine << endl; return cmdLine; }
void LastFilePosSection::read(istream & is) { string tmp; do { char c = is.peek(); if (c == '[') break; getline(is, tmp); if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') continue; try { // read lastfilepos // pos, file\n FilePos filepos; string fname; istringstream itmp(tmp); itmp >> filepos.pit; itmp.ignore(2); // ignore ", " itmp >> filepos.pos; itmp.ignore(2); // ignore ", " getline(itmp, fname); if (!FileName::isAbsolute(fname)) continue; FileName const file(fname); if (file.exists() && !file.isDirectory() && lastfilepos.size() < num_lastfilepos) lastfilepos[file] = filepos; else LYXERR(Debug::INIT, "LyX: Warning: Ignore pos of last file: " << fname); } catch (...) { LYXERR(Debug::INIT, "LyX: Warning: unknown pos of last file: " << tmp); } } while (is.good()); }
void LastOpenedSection::read(istream & is) { string tmp; do { char c = is.peek(); if (c == '[') break; getline(is, tmp); if (tmp.empty() || tmp[0] == '#' || tmp[0] == ' ') continue; try { LastOpenedFile lof; istringstream itmp(tmp); itmp >> lof.active; itmp.ignore(2); // ignore ", " string fname; getline(itmp, fname); if (!FileName::isAbsolute(fname)) continue; FileName const file(fname); if (file.exists() && !file.isDirectory()) { lof.file_name = file; lastopened.push_back(lof); } else { LYXERR(Debug::INIT, "LyX: Warning: Ignore last opened file: " << tmp); } } catch (...) { LYXERR(Debug::INIT, "LyX: Warning: unknown state of last opened file: " << tmp); } } while (is.good()); }
static void __pnm_read_values( istream &io_istream, list<string> &o_values, list<string> *o_comments ) { char c; string currentValue(25,' '), comment; currentValue.clear(); do { if ( io_istream.peek()=='#' ) { if ( currentValue.length()!=0 ) { o_values.push_back(currentValue); currentValue.clear(); } getline( io_istream, comment ); if ( o_comments!=NULL && comment.length()>1 ) o_comments->push_back( comment.substr(1) ); } io_istream.get(c); if ( __pnm_is_whitespace(c) ) { if ( currentValue.length()!=0 ) { o_values.push_back(currentValue); currentValue.clear(); } } else currentValue.append( 1, c ); } while ( !io_istream.eof() && o_values.size()<4 ); }
inline bool peek( istream &is, char &c ) { char const temp = is.peek(); bool const peeked = is.good(); if ( peeked ) c = temp; return peeked; }