std::set<wxString> parseShotTypeList(std::fstream &mfilestream) { char c; std::set<wxString> types; std::string shottypename; c = getnextnonwhite(mfilestream); if(c!='{') throw parseerror::missing_opening_bracket; while(whitespace(mfilestream.peek())) { c=mfilestream.get(); } if(mfilestream.peek() == '}') { mfilestream.get(); return types; } while(c!='}') { shottypename = extractQuotedPrefix(mfilestream); types.insert(shottypename); c = getnextnonwhite(mfilestream); if(c!=',' && c!='}') throw parseerror::missing_comma; } return types; }
char getnextnonwhite(std::fstream &mfilestream) { char c; mfilestream.get(c); while(whitespace(c)) { mfilestream.get(c); } return c; }
std::string extractQuotedPrefix(std::fstream &mfilestream) { char c; c = getnextnonwhite(mfilestream); if(c!='\"') { throw parseerror::no_leading_quote; } else { mfilestream.get(c); std::string output; bool escaped = false; bool stringmfinished = false; while(!stringmfinished) { output+=c; if(mfilestream.eof()) { throw parseerror::no_finishing_quote; } mfilestream.get(c); if(c=='\\') { if(escaped) { escaped = false; } else { escaped = true; } } else if(c =='\"') { if(escaped) { escaped = false; } else stringmfinished = true; } else { escaped = false; } } return output; } }
void FileReader::processData() { DBG("File: processing data..."); int offset = 0; char ch; while (offset < SIZE && m_fs.get(ch)) { m_data[offset++] = ch; } m_data[offset] = '\0'; }
std::string extractNumber(std::fstream &mfilestream) { char c; std::string entry; do { mfilestream.get(c); entry+=c; c = mfilestream.peek(); } while (c!=','&&c!='}'&&c!=')'); return entry; }
// sets the prog name. Requires a file pointer. Extracts exactly six characters // from fstream void HeaderRecord::setProgName(std::fstream & file) { int i; // get 6 characters and append them to the progName string for (i = 0; i < 6; i++) { // needs a string argument for append() char tempChar = file.get(); // error handler, check for eof bit Record::unexpectedEOF(file); // append to string progName += tempChar; } std::cout << "Program name: " + progName; }
// gets column 8-13 in header record setting the prog start address void HeaderRecord::setProgStart(std::fstream & file) { int i = 0; // get 6 characters, convert them to ints, and multiply to get their // significant places for (i = 0x100000; i > 0x00; i = i / 0x10) { int hexVal; char tempChar; tempChar = file.get(); // check for error, unexpected eof Record::unexpectedEOF(file); hexVal = ASCIItoHEX(tempChar); hexVal *= i; // adds values starting at MSB position and moving right each // iteration progStart += hexVal; } std::cout << " Program start address: " << progStart; }
//ReadOffsetString // Reads in the next 4 bytes as an offset to a zero-terminated string value, then // allocates and fills in the provided string with that value. void ReadOffsetString(std::fstream& f, char*& sz) { int32_t i; char szBuffer[4]; f.read(szBuffer, 4); if (*(int32_t*)szBuffer == 0) sz = NULL; else { f.seekg(*(int32_t*)szBuffer - 4, ios::cur); for (i = 0; f.get() != '\0'; ++i); f.seekg(-(i + 1), ios::cur); sz = new char[i + 1]; f.read(sz, i); sz[i] = '\0'; } f.seekg(4 - *(int32_t*)szBuffer - i, ios::cur); }
//////////////////////////////////////////////////////////////////////////////////// /// /// \brief Reads a line from a fstream adding it to a string, reading up /// to a newline character. /// /// \param[in] str File stream operator. /// \param[out] line Line read from file (doesn't include carriage return). /// /// \return Number of characters read. /// //////////////////////////////////////////////////////////////////////////////////// unsigned int FileIO::ReadLine(std::fstream& str, std::string& line) { char ch; line.reserve(512); line.clear(); while(str.eof() == false && str.good()) { str.get(ch); if(ch == '\n') { break; } else { line.push_back(ch); } } return (unsigned int)line.size(); }
std::streampos search_forward ( std::fstream & _bs, const std::string & sample ) { size_t match ( 0 ); cSaveIStreamPosition ip ( &_bs ); streampos result ( static_cast<streampos>( -1 ) ); cSaveStreamExceptions se ( &_bs, std::ios_base::goodbit ); for( int ch( EOF ); match < sample.length(); match++ ) { ch = _bs.get(); if( ch == EOF ) break; else if( ch != sample[match] ) match = 0; } if( match == sample.length() ) result = _bs.tellg() - static_cast<streampos>( match ); _bs.clear(); return result; }
void Scanner::Advance() { cur_char_ = file_.get(); }
static bool loadY4MHeader(std::fstream& fs, cv::Mat &img) { fs.seekg(fs.beg); if (fs.good()) { char inbuf [256]; fs >> inbuf; if (strcmp(inbuf, "YUV4MPEG2") != 0) { return false; } fs.get(); // space int width, height; char c = fs.get(); if (c != 'W') { return false; } fs >> width; c = fs.get();// space c = fs.get(); if (c != 'H') { return false; } fs >> height; img.create(height * 3 / 2, width, CV_8UC1); }