string SceneLoader::getString(istream &str) { string ret; char temp; str >> temp; // get rid of white space, get to first char str.putback(temp); while (str.get(temp)) { if (temp >= 'a' && temp <= 'z' || temp >= 'A' && temp <= 'Z' || temp >= '0' && temp <= '9' || temp == '_' ) { ret += temp; } else if (temp == '#') { string no; getline(str, no); if (ret.empty()) return getString(str); else return ret; } else { str.putback(temp); break; } } return ret; }
XFileToken XFileToken::ReadNumber(istream& s) { XFileToken result; result.m_type = Integer; char c; s.get(c); result.m_content.push_back(c); while (s.get(c)) { if (c == '.') { if (result.m_type == Integer) result.m_type = Float; else { s.putback(c); return result; } } else if (!isdigit(c)) { s.putback(c); return result; } result.m_content.push_back(c); } return result; }
//----------------------------------------------------------------------------- // Class: CTime // Method: void CTime::input(istream& sin) // Description: input method for CTime objects // Input: sin // Called By: constructor from DateTime/CTime, mutators, saferead // Parameters: istream& sin - input istream // Returns: n/a // History Log: // 4/29/15 KG completed version 1.0 // ---------------------------------------------------------------------------- void CTime::input(istream& sin) { int hour = 0; int minute = 0; int second = 0; m_hour = hour; m_second = second; m_minute = minute; char c = ' '; sin.get(c); if(c == '\n') //checks for no input if datetime { sin.putback(c); return; } sin.putback(c); //puts back character if normal input if(sin >> hour) { if(hour > MINTIME && hour <= MAXHOUR) m_hour = hour; sin.get(c); if(c == '\n') { sin.putback(c); return; } if(c == ':') { if(sin >> minute) { if(minute > MINTIME && minute < MAXMINSEC) { m_minute = minute; } sin.get(c); if(c == '\n') { sin.putback(c); return; } if(c == ':') { if(sin >> second) { if(second > MINTIME && second < MAXMINSEC) { m_second = second; } } } else sin.setstate(std::ios::failbit); } } else
bool _check_idlabel_title(istream &s, string &title) { title.clear(); if (!s.good()) return false; bool hv = false; while (1) { string line0; getline(s, line0); if (!allSpace(line0)) { string line = removeLeadSpace2(line0); if (line.length() <= 1 || !( (line.front() == '"' && line.back() == '"') || (line.front() == '\'' && line.back() == '\'') || (line.front() == '(' && line.back() == ')') )) { if (!s.eof()) s.putback('\n'); s.clear(); strputback(s, line0); return hv; } title = line.substr(1, line.length() - 2); return true; } if (s.eof() || hv) break; hv = true; } return true; }
bool // // Extracts the next word from the input stream. This function has the same // functionality as "cin >> word", excepts it additionally makes sure that // the word buffer is not over-run! // getWord(istream& in, string& word) { int i = 0; char ch; word = ""; while(in.get(ch)) { if(!isspace(ch)) { if(i > MAX_WORDLEN) { in.putback(ch); break; } else { word += ch; i++; } } else { break; } } if (i > 0) return true; else return false; }
string predicate_scan_token ( istream & is, scan_token_predicate & prd ) { char ch = '\0'; string res = ""; do { // eat whitespaces ... ch = is.get(); } while ( isspace( ch ) ); for( bool longString = false;; ch = is.get() ) { if( ch == DOUBLE_L ) { if( longString ) break; else longString = true; } else if( longString ) res += ch; else if( prd.check( ch ) ) { if( res.size() ) is.putback( ch ); else res += ch; break; } else res += ch; } return res; }
bool XFileToken::SkipComments(istream& s) { char c; SkipWS(s); while (s.get(c)) { if (c == '/') { if (!s.get(c)) THROW_EXCEPTION_T("Parsing error", ParsingException); if (c != '/') THROW_EXCEPTION_T("Parsing error", ParsingException); } else if (c != '#') { s.putback(c); return true; } while (s.get(c)) { if (c == '\n') break; } SkipWS(s); } return false; }
int ChessIO::scan_pgn(istream &game_file, vector<string> &contents) { Board board; int c; while (game_file.good() && !game_file.eof()) { // Collect the header: long first; vector<Header> hdrs; string eventStr; collect_headers(game_file, hdrs, first); if (get_header(hdrs,"Event",eventStr)) { // We have the headers, munge them into a single-line game // description. Append the index to the game so the GUI // can navigate to the game when the user clicks on the // description. string descr; get_game_description(hdrs, descr, first); contents.push_back(descr); } hdrs.clear(); while (game_file.good() && !game_file.eof()) { if ((c = game_file.get()) == '[') { game_file.putback(c); break; } } } return 1; }
bool eof(istream& in) { char ch; in >> ch; in.putback(ch); return !in; }
void read_header(istream& fin, ostream& fout, int& width, int& height, int& max) { char header[100]; char ch; // Getmage=ic number fin.getline(header,100); // write magic number fout << header <<endl; cout << header << endl; // get all comment lines and write to new file fin >> ch; while (ch == '#') { fin.getline(header, 100); fout <<ch << header << endl; cout <<ch << header << endl; fin >> ch; } fin.putback(ch); // Input width and height of image fin >> width >> height; cout << width <<" " << height << endl; fout << width <<" " << height << endl; // Input maximum color value fin >> max; cout << max << endl; fout << max << endl; return; }
void CL_TimeOfDay::FromStream (istream& s) { CL_String rep; char c; long count = 0; char fill_char = s.fill (); while (s.get (c) && c == fill_char); if (!s.good() || s.eof()) { _numSecs = 0; return; } do { if (isalnum (c) || c == ':') { rep.Append (c); count++; } else break; } while (s.get (c)); long n = ParseAndConvert (rep); if (n > 0) { if (!s.eof()) s.putback (c); _numSecs = n; } else { s.seekg (s.tellg() - count, istream::cur); _numSecs = 0; } }
/****************************************************************************************** void skipspace(istream& in) Description: This function reads past all whitespace (ie. ' ' and '/t'). Parameters: istream& in -input stream being read ******************************************************************************************/ void skipspace(istream& in) { char ch; in.get(ch); while ((ch ==' ') ||(ch =='\t')) in.get(ch); in.putback(ch); }
int seek_eoln(istream &i) { char ch=' '; int ret=0; while ( (i) && (ch==' ') ) i.get(ch); if (ch=='\n') ret=1; else if (i) i.putback(ch); if (!i) ret=1; return ret; };
int seek_eof(istream &i) { char ch=' '; int ret=0; while ( (i) && ((ch==' ') || (ch=='\n')) ) i.get(ch); // if (ch==0) return 1; if (i) { i.putback(ch);} if (!i) ret=1; return ret; };
// Put a string back into an istream void a::putback(istream &in, const string &s) { if (s.length()==0) return; unsigned i=unsigned(s.length())-1; while (true) { in.putback(s[i]); if (i==0) return; i--; } }
void fcnn::internal::skip_blank(istream &is) { char c; while (is.good() && !is.eof()) { is.get(c); if ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\0')) { is.putback(c); break; } } }
// Consume whitespace characters from stream. Leaves the stream // pointing at the next non-whitespace char (or possibly eof()); void skipWhiteSpace(istream &istr) { char next; istr >> next; // take advantage of the fact that >> uses whitespace as a field // separator if (!istr.eof()) { // If eof() is set, it means we didn't find any tokens after the whitespace. // In this case // there's nother to put back, and doing so would unset the eof bit. istr.putback(next); } }
bool MpContextSave::GetListHead (istream& is, char bra, string &name) { MpParseTool::SkipWhiteSpace(is); char c; if (!is.get(c)) return false; else { if (c != bra) { is.putback(c); return false; } else return MpParseTool::GetWord(is,name); } }
static void ReadString (istream & ist, char * str) { //char * hstr = str; char ch; for (;;) { ist.get(ch); if (!ist.good()) break; if (!isspace (ch)) { ist.putback (ch); break; } } for (;;) { ist.get(ch); if (!ist.good()) break; if (isalpha(ch) || isdigit(ch)) { *str = ch; str++; } else { ist.putback (ch); break; } } *str = 0; // cout << "Read string (" << hstr << ")" // << "put back: " << ch << endl; }
void String::scanFrom(istream& strm) // Read next line of input from strm into this String. { ostream* os = strm.tie((ostream*)0); if (os != 0) { os->flush(); strm.tie(os); } char c; strm.get(c); if (c != '\n') strm.putback(c); char temp[513]; strm.get(temp,513); *this = String(temp); }
static bool skipComment( // skip any comments istream &in) // input stream { char ch = 0; // skip whitespace do { in.get(ch); } while (isspace(ch) && !in.eof()); while (ch == '#' && !in.eof()) { // comment? // skip to end of line do { in.get(ch); } while(ch != '\n' && !in.eof()); // skip whitespace do { in.get(ch); } while(isspace(ch) && !in.eof()); } if (in.eof()) return false; // end of file in.putback(ch); // put character back return true; }
XFileToken XFileToken::ReadIdentifier(istream& s) { XFileToken result; result.m_type = Identifier; char c; while (s.get(c)) { if (!isalnum(c) && c != '_') { s.putback(c); return result; } result.m_content.push_back(c); } return result; }
bool fcnn::internal::is_eol(istream &is) { char c; while (is.good() && !is.eof()) { is.get(c); if ((c != ' ') && (c != '\t')) { if (c == '\n') return true; else { is.putback(c); break; } } } return false; }
void fcnn::internal::skip_all(istream &is) { char c; while (is.good() && !is.eof()) { is.get(c); if ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\0')) { is.putback(c); if (c == '#') { skip_comment(is); } else { break; } } } }
// Read quotes from file, prioritizing short projects (no more // than 7 days) at the front. void readQuotes(istream &inStream, Dequeue<Quote> "es) { while (true) { // Read character to allow testing for end-of-file. char ch = inStream.get(); if (inStream.eof()) break; // Put back character read to test end-of-file. inStream.putback(ch); // READ IN AND QUEUE QUOTE. } }
bool fcnn::internal::is_eoleof(istream &is) { char c; if (is.eof()) return true; while (is) { if (is.eof()) return true; is.get(c); if ((c != ' ') && (c != '\t')) { if ((c == '\n') || (c == '\0')) return true; else { is.putback(c); return false; } } } return false; }
void parse_definitions(istream& _input, ostream& _output) { string line; getline(_input, line); char buffer[256]; strcpy(buffer, line.c_str()); char* pchar = buffer; while(isspace(*pchar)) pchar++; if(*pchar=='\0') { _output<<endl; return; } else if(*pchar=='\x7F') //generate an error. { throw(5); } else if(*pchar=='#') //comment { _output<<"\t// "<<*(pchar+1)<<endl; return; } else if(*pchar=='%') //type { string typeName,typeDest,typeEdit; while((_input>>typeName)&&(typeName!="end")) { if(endWith(typeName,";")) { typeName = typeName.substr(0, typeName.length()-1); _input.putback(';'); } typeList.push_back(typeName); _output<<"\tusing lachesis::" <<typeName<<"_t;"<<endl; while((_input>>typeName)&&(typeName!=";")) { throw(6); } } getline(_input, typeName); return; }
bignum bignum_read(istream& in) { bignum a; string num; char ch = in.peek(); while (!isspace(ch) && ch != '(' && ch != ')') { in.get(ch); if (ch == '+' || ch == '-' || ch == '*') { in.putback(ch); break; } else if (isdigit(ch)) { num += ch; } ch = in.peek(); } for(unsigned int i = num.length(); i > num.length() % BASE_EXPONENT; i -= BASE_EXPONENT) { string subNum = num.substr(i - BASE_EXPONENT, BASE_EXPONENT); int subVector = atoi(subNum.c_str()); a.push_back(subVector); } if (num.length() % BASE_EXPONENT != 0) { string subNum = num.substr(0, num.length() % BASE_EXPONENT); int subVector = atoi(subNum.c_str()); a.push_back(subVector); } else if (num.length() == 0) { a.push_back(0); } a = bignum_popzeroes(a); return a; }
void field_type<string>::read ( istream& is, const matrix_separators *ap_matsep ) { char endchar[2]; endchar[1] = '\0'; var().erase(); if (is_followed_by(is,'\"',false)) endchar[0] = '\"'; else endchar[0] = ap_matsep->m_field_sep; read_until(is,endchar,var()); is.putback(endchar[0]); // Feld-Ende-Zeichen nicht entnehmen }
int MpViewLabelList::read (istream& is) { MpViewLabelData d; char c; list.erase(list.begin(),list.end()); for (int i = 0; ; ++i) { if ( d.read(is) ) { list.push_back(d); MpParseTool::SkipWhiteSpace(is); if (is.get(c)) { if (c != ',') { is.putback(c); break; } } else break; } else break; } return (is.fail()) ? 1 : 0; }