vector<string*>* Configuration::ReadTextFile(const string& fileName) { const int BufferSize = 500; vector<string*>* lines = new vector<string*>(); try { ifstream textFile( fileName.c_str() ); ifstream::char_type buffer[BufferSize]; if(!textFile.fail()) { try { for(;;) { textFile.getline(buffer,BufferSize*sizeof(ifstream::char_type)); if(textFile.fail()) break; string& line = *new string(buffer); Strings::Trim(line); if (line.empty()||line[0]=='#') { delete &line; continue; } lines->push_back(&line); } } catch (...) { Trace::WriteLine(1,"Configuration.ReadTextFile: warning: reading exception."); } } } catch (...) { Trace::WriteLine(1,"Configuration.ReadTextFile: warning: opening exception."); delete lines; return NULL; } return lines; }
void wxExGuiReportTestFixture::testTextFileWithListView() { wxExTool tool(ID_TOOL_REPORT_FIND); wxExFrameWithHistory* frame = (wxExFrameWithHistory *)wxTheApp->GetTopWindow(); const wxExFileName fn(TEST_FILE); wxExListViewFileName* report = new wxExListViewFileName( frame, wxExListViewFileName::LIST_FIND); wxExFindReplaceData::Get()->SetFindString("xx"); CPPUNIT_ASSERT(wxExTextFileWithListView::SetupTool(tool, frame, report)); wxExTextFileWithListView textFile(fn, tool); CPPUNIT_ASSERT( textFile.RunTool()); CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT(!textFile.IsOpened()); // file should be closed after running tool CPPUNIT_ASSERT( textFile.RunTool()); // do the same test CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT(!textFile.IsOpened()); // file should be closed after running tool wxExTextFileWithListView textFile2(fn, tool); CPPUNIT_ASSERT( textFile2.RunTool()); CPPUNIT_ASSERT(!textFile2.GetStatistics().GetElements().GetItems().empty()); }
void Logic::ParsingFile(int NumberMessage,QString filterStart,QString filterFinish,QString& Output) { int i = NumberMessage; QFile textFile("Message"+QString::number(i,10)+".txt"); textFile.open(QIODevice::ReadOnly | QIODevice::Text); bool exit = false; bool base64 = false; while(!exit) { bool flag = true; QString textLine = textFile.readLine(); if(textLine.startsWith("Content-Transfer-Encoding: base64")) base64 = true; if(textLine.startsWith(filterStart)) { while(!exit) { Output += textLine; textLine = textFile.readLine(); if(textFile.atEnd())exit = true; } } Output.replace(0,4,"\n"); } if(base64) { QByteArray xcode("");; xcode.append(Output); QByteArray precode(QByteArray::fromBase64(xcode)); Output = precode.data(); } textFile.close(); }
ModList::OrderList ModList::readListFile() { OrderList itemList; if (m_list_file.isNull() || m_list_file.isEmpty()) return itemList; QFile textFile(m_list_file); if (!textFile.open(QIODevice::ReadOnly | QIODevice::Text)) return OrderList(); QTextStream textStream; textStream.setAutoDetectUnicode(true); textStream.setDevice(&textFile); while (true) { QString line = textStream.readLine(); if (line.isNull() || line.isEmpty()) break; else { OrderItem it; it.enabled = !line.endsWith(".disabled"); if (!it.enabled) { line.chop(9); } it.id = line; itemList.append(it); } } textFile.close(); return itemList; }
//this function maps the path to a string to the string contained in path, if the string has been loaded //before then the strings path is just the key to the string at the path else //the path is used to return the string std::string StringLoader::doString( std::string _path){ for( auto s: strings){ if(s.first == _path){ std::cout<< "string at " << _path << " found."<< std::endl; return s.second; } } //temporary string container std::string temp, input; std::ifstream textFile( _path.c_str()); if( textFile){ while(getline( textFile, input)){ temp += input + '\n'; } //setting key value pair strings[ _path] = temp; //recursivley call function again, this way string will have been initialised return doString( _path); }else{ std::cout <<"File at " << _path << " not found."<< std::endl; return "File does not exist"; } }
void MainForm::saveText() { if (actionSelect_HTML_format->isChecked()) settings.setOutputFormat("html"); else settings.setOutputFormat("text"); QString filter; if (settings.getOutputFormat() == "text") filter = trUtf8("Text Files (*.txt)"); else filter = trUtf8("HTML Files (*.html)"); QFileDialog dialog(this, trUtf8("Save Text"), settings.getLastOutputDir(), filter); if (settings.getOutputFormat() == "text") dialog.setDefaultSuffix("txt"); else dialog.setDefaultSuffix("html"); dialog.setAcceptMode(QFileDialog::AcceptSave); if (dialog.exec()) { QStringList fileNames; fileNames = dialog.selectedFiles(); settings.setLastOutputDir(dialog.directory().path()); QFile textFile(fileNames.at(0)); textFile.open(QIODevice::ReadWrite | QIODevice::Truncate); if (settings.getOutputFormat() == "text") textFile.write(textEdit->toPlainText().toUtf8()); else saveHtml(&textFile); textFile.close(); textSaved = TRUE; } }
int main( int argc, char * argv[] ) { if( argc != 3 ){ std::cerr << "Usage: " << argv[ 0 ] << " dictionary_file text_file" << std::endl; return 1; } AhoCorasick ac; auto const print = []( size_t const pos, std::string const & word ){ std::cout << "> " << std::string( pos, ' ' ) << word << std::endl; }; std::string line; std::ifstream dictFile( argv[ 1 ] ); std::ifstream textFile( argv[ 2 ] ); while( std::getline( dictFile, line ) ){ ac.insert( line ); } while( std::getline( textFile, line ) ){ std::cout << "> " << line << "\n"; ac.search( line, print ); std::cout << std::string( 80, '-' ) << "\n"; } }
std::string easyUtils::readTextFile (const std::string &fileName) { std::ifstream textFile (fileName); std::stringstream buffer; buffer << textFile.rdbuf (); return buffer.str (); }
bool MainWindow::fileOperate(QString &flname, int mode){ switch(mode){ case openFile:{ QFile textFile(flname); if(textFile.open(QIODevice::ReadOnly)){ QByteArray content=textFile.readAll(); QString stringContent(content); textArea->setText(stringContent); textFile.close(); return true; } break; } case saveFile:{ QFile textFile(flname); /* if(textFile.exists()){ int res=QMessageBox::warning(this,"Warning!!","File Already Exists <br/> Do you want to overwrite?",QMessageBox::Ok|QMessageBox::Cancel); if(res){ if(textFile.open(QIODevice::WriteOnly)){ return true; } } } else{ if(textFile.open(QIODevice::WriteOnly)){ return true; } } */ if(textFile.open(QIODevice::WriteOnly)){ QString stringContent=textArea->toPlainText(); QByteArray content=stringContent.toAscii(); textFile.write(content); textFile.close(); return true; } } }; return false; }
int main() { FILE *cfPtr; /* credit.dat file pointer */ int choice; /* user's choice */ /* fopen opens the file; exits if file cannot be opened */ if ( ( cfPtr = fopen( "credit.dat", "rb+" ) ) == NULL ) { printf( "File could not be opened.\n" ); } /* end if */ else { /* enable user to specify action */ while ( ( choice = enterChoice() ) != 6 ) { switch ( choice ) { /* create text file from record file */ case 1: textFile( cfPtr ); break; /* update record */ case 2: updateRecord( cfPtr ); break; /* create record */ case 3: newRecord( cfPtr ); break; /* delete existing record */ case 4: deleteRecord( cfPtr ); break; /* sum up balances of valid records and record sum in text file */ case 5: sumRecords( cfPtr ); break; /* display message if user does not select valid choice */ default: printf( "Incorrect choice\n" ); break; } /* end switch */ } /* end while */ fclose( cfPtr ); /* fclose closes the file */ } /* end else */ return 0; /* indicates successful termination */ } /* end main */
void ArthurFrame::loadDescription(const QString &fileName) { QFile textFile(fileName); QString text; if (!textFile.open(QFile::ReadOnly)) text = QString("Unable to load resource file: '%1'").arg(fileName); else text = textFile.readAll(); setDescription(text); }
void PEAC:: preload() { QFile textFile(name); textFile.open(QIODevice::ReadOnly); QTextStream textStream(&textFile); QString line; line=textStream.readAll(); list=line.split("\n"); }
u_int32_t HY3131DMMLib::readADC1(u_int8_t r0,u_int8_t r1,u_int8_t r2){ //Load No of Samples from File~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bool ok=true; QStringList stringList; QFile textFile("/home/HY3131/Samples.dat"); if (textFile.open(QIODevice::ReadOnly)) { QTextStream textStream(&textFile); while (!textStream.atEnd()) { stringList.append(textStream.readLine()); } m_nSampleCount=stringList.value(0).toInt(&ok,10); textStream.flush(); } textFile.close(); //qDebug()<<"samples:"<<m_nSampleCount; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ busyState=true; //Clear SPI RX Registors // if(selAppCard) // IAppCard->writeRegister(0x0, DMM_DATA_TX_MSW); // else IBackPlane->writeBackPlaneRegister(0x0, DMM_DATA_TX_MSW_BP); // if(selAppCard) // IAppCard->writeRegister(0x0, DMM_DATA_TX_LSW); // else IBackPlane->writeBackPlaneRegister(0x0, DMM_DATA_TX_LSW_BP); usleep(1000); u_int32_t a, b, c, t, t2,temp=0; //Read ADC1 for(int i=0;i<m_nSampleCount;i++){ reg0 = (u_int8_t) readDMMSPI(r0) & 0x000000FF; reg1 = (u_int8_t) readDMMSPI(r1) & 0x000000FF; reg2 = (u_int8_t) readDMMSPI(r2) & 0x000000FF; //Shift & Combine a = reg0; b = (reg1 << 8); c = (reg2 << 16); t = a | b; t2 = t | c; temp+=t2; } temp=temp/m_nSampleCount; //qDebug()<<"_______________________________________________________________"; qDebug()<<"ADC Read Data:"<<hex<<temp; busyState=false; return temp; }
void Logic::ParsingFileForInputMessage(int NumberMessage,QString& Output) { if(NumberMessage!=0) { int i = NumberMessage-1; QFile textFile("send_message"+QString::number(i,10)+".txt"); textFile.open(QIODevice::ReadOnly | QIODevice::Text); Output = textFile.readAll(); textFile.close(); } }
QString GmacsScriptLoader::loadScript(QString filepath) { QString script = ""; QFile textFile(filepath); if (textFile.open(QIODevice::ReadOnly)) { QTextStream input(&textFile); script = input.readAll(); textFile.close(); } return script; }
unsigned char easyUtils::fileExists (const char *fileName) { std::ifstream textFile (fileName); if (textFile.good ()) { textFile.close (); return true; } else { return false; } }
std::string read_text_file(const std::string &path) { std::stringstream contentStream; std::ifstream textFile(path); if (textFile.is_open()) { contentStream << textFile.rdbuf(); } else { std::cout << "ERROR::TEXT_FILE::OPEN\n" << path << std::endl; } return contentStream.str(); }
void easyUtils::writeTextFile (const std::string &fileName, const std::string &text) { std::ofstream textFile (fileName); if (textFile.is_open ()) { textFile << text; textFile.close (); } else { std::cout << "Unable to open the file: " << fileName << "!" << std::endl; exit (EXIT_FAILURE); } }
u_int64_t FileWorker::FileLenght(std::string& fileName) { u_int64_t fileLenght; std::ifstream textFile(fileName.c_str(), std::ifstream::in); if (textFile.is_open()) { textFile.seekg(0, std::ios_base::end); fileLenght = textFile.tellg(); textFile.close(); } else { //TODO Errors } return fileLenght; }
void wxExTestFixture::testFileStatistics() { wxExFileStatistics fileStatistics; wxExTextFile textFile(wxExFileName(TEST_FILE), ID_TOOL_REPORT_COUNT); CPPUNIT_ASSERT(fileStatistics.Get().empty()); CPPUNIT_ASSERT(fileStatistics.Get("xx") == 0); CPPUNIT_ASSERT( textFile.RunTool()); CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); fileStatistics += textFile.GetStatistics(); CPPUNIT_ASSERT(!fileStatistics.Get().empty()); }
void fixture::testTextFile() { // Test find. wxExTextFile textFile(GetTestFile(), ID_TOOL_REPORT_FIND); CPPUNIT_ASSERT( textFile.GetFileName() == GetTestFile()); CPPUNIT_ASSERT( textFile.GetTool().GetId() == ID_TOOL_REPORT_FIND); wxExFindReplaceData::Get()->SetFindString("test"); wxExFindReplaceData::Get()->SetMatchCase(true); wxExFindReplaceData::Get()->SetMatchWord(true); wxExFindReplaceData::Get()->SetUseRegEx(false); wxStopWatch sw; sw.Start(); CPPUNIT_ASSERT( textFile.RunTool()); const long elapsed = sw.Time(); CPPUNIT_ASSERT(elapsed < 20); Report(wxString::Format( "wxExTextFile::matching %d items in %ld ms", textFile.GetStatistics().Get(_("Actions Completed")), elapsed).ToStdString()); CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT( textFile.GetStatistics().Get(_("Actions Completed")) == 193); // Test replace. wxExTextFile textFile2(GetTestFile(), ID_TOOL_REPORT_REPLACE); wxExFindReplaceData::Get()->SetReplaceString("test"); wxStopWatch sw2; sw2.Start(); CPPUNIT_ASSERT( textFile2.RunTool()); const long elapsed2 = sw2.Time(); CPPUNIT_ASSERT(elapsed2 < 100); Report(wxString::Format( "wxExTextFile::replacing %d items in %ld ms", textFile2.GetStatistics().Get(_("Actions Completed")), elapsed2).ToStdString()); CPPUNIT_ASSERT(!textFile2.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT( textFile2.GetStatistics().Get(_("Actions Completed")) == 194); }
void wxExTestFixture::testTextFile() { wxExTextFile textFile(wxExFileName(TEST_FILE), ID_TOOL_REPORT_COUNT); CPPUNIT_ASSERT( textFile.RunTool()); CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT(!textFile.IsOpened()); // file should be closed after running tool CPPUNIT_ASSERT( textFile.RunTool()); // do the same test CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT(!textFile.IsOpened()); // file should be closed after running tool wxExTextFile textFile2(wxExFileName(TEST_FILE), ID_TOOL_REPORT_KEYWORD); CPPUNIT_ASSERT( textFile2.RunTool()); // we have no lexers, so no keywords CPPUNIT_ASSERT( textFile2.GetStatistics().GetKeywords().GetItems().empty()); }
bool ModList::saveListFile() { if(m_list_file.isNull() || m_list_file.isEmpty()) return false; QFile textFile(m_list_file); if(!textFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) return false; QTextStream textStream(&textFile); for(auto mod:mods) { auto pathname = mod.filename(); QString filename = pathname.fileName(); textStream << filename << endl; } textFile.close(); return false; }
void ErrorReportDialog::onShowFileContent(const QItemSelection& newSelection, const QItemSelection & oldSelection) { ARX_UNUSED(oldSelection); const QModelIndexList selectedIndexes = newSelection.indexes(); if(selectedIndexes.empty()) return; const QModelIndex selectedIndex = selectedIndexes.at(0); if(!selectedIndex.isValid()) return; fs::path fileName = m_errorReport.GetAttachedFiles()[selectedIndex.row()].path; QString ext = fileName.ext().c_str(); if(ext == ".txt" || ext == ".log" || ext == ".ini" || ext == ".xml") { QFile textFile(fileName.string().c_str()); textFile.open(QIODevice::ReadOnly | QIODevice::Text); QByteArray data; data = textFile.readAll(); ui->fileViewText->setText(QString::fromUtf8(data)); ui->stackedFileViews->setCurrentIndex(0); } else if(ext == ".jpg" || ext == ".jpeg" || ext == ".bmp" || ext == ".png" || ext == ".gif") { m_fileViewImage.load(fileName.string().c_str()); ui->stackedFileViews->setCurrentIndex(1); } else { QFile binaryFile(fileName.string().c_str()); binaryFile.open(QIODevice::ReadOnly); if(binaryFile.size() > 20 * 1024 * 1024) { ui->stackedFileViews->setCurrentIndex(3); return; } QByteArray data; data = binaryFile.readAll(); m_fileViewHex.setData(data); ui->stackedFileViews->setCurrentIndex(2); } }
void Logic::ParsingFile(int NumberMessage,QString filter,QString& Output) { int i = NumberMessage; QFile textFile("Message"+QString::number(i,10)+".txt"); textFile.open(QIODevice::ReadOnly | QIODevice::Text); bool exit = false; while(!exit) { QString textLine = textFile.readLine(); if(textLine.startsWith(filter)) { Output = textLine; exit = true; } } textFile.close(); }
bool TextPlayer::playOn(const ValuePacket &values, QWidget *target, QString *errorStr) { m_UpdateTimer.stop(); m_CurrentTextPtr = 0; const QString& textFilePath = values.value(TextFilePathName, "").toString(); if(textFilePath == "") { m_Text = values.value(TextName, "").toString(); if(m_Text == "") { SetString(tr("得到文本文件路径或者直接文本失败"), errorStr); return false; } } else { QFile textFile(textFilePath); if(!textFile.open(QFile::ReadOnly)) { SetString(tr("打开播放文本出错"), errorStr); return false; } QByteArray bytes = textFile.readAll(); m_Text = QString::fromLocal8Bit(bytes.data()); } // this->setText(text); if(target != NULL) { target->setAutoFillBackground(true); QLayout* layout = target->layout(); if(layout == NULL) layout = new QHBoxLayout; layout->setMargin(1); layout->addWidget(this); target->setLayout(layout); } m_UpdateTimer.start(m_UpdateInterval); return true; }
Double_t CrossSection(std::string token){ std::ifstream textFile("textFile.txt"); std::string thisSample; double crosssection = 0.; double thisNum = 0.; while( textFile >> thisSample >> thisNum ){ if( token.find(thisSample) != std::string::npos ) crosssection = thisNum; } return crosssection; }
//! Loads all text data from file according to the current locale void CTranslation::loadTextData(const string& fullPath) { //cout << "Translation file loaded : " << fullPath.c_str() << endl; ifstream textFile(fullPath.c_str(), ios::in); if (textFile) { //cout << "Processing translation file..." << endl; char currentChar; bool inTextIdentifier = true; bool inTextValue = false; string identifier = ""; string value = ""; while (textFile.get(currentChar)) { if (currentChar == '\n' || currentChar == '\r') { // Nouvelle traduction if (identifier != "") { //cout << "Added translation (" << identifier.c_str() << ") = (" << value.c_str() << ")" << endl; TextData[identifier] = value; } identifier = ""; value = ""; inTextValue = false; inTextIdentifier = true; } else { if (inTextValue) { value += currentChar; } if (inTextIdentifier) { if (currentChar == '=') { // Passage de l'identifiant a la valeur inTextIdentifier = false; inTextValue = true; } else { identifier += currentChar; } } } } textFile.close(); } else { //cout << "[!!] Translation file not found: " << fullPath.c_str() << endl; } }
void CGI::logCGIData(const QString& filename) { // create a QFile object to do the file I/O QFile file(filename); // open the file if (file.open(QIODevice::WriteOnly)) { // create a QTextStream object on the file Q3TextStream textFile(&file); // get the environment textFile << "REQUEST_METHOD=" << getenv("REQUEST_METHOD") << endl; textFile << "CONTENT_LENGTH=" << getenv("CONTENT_LENGTH") << endl; // write the query string to the file textFile << "QUERY_STRING=" << query_string << endl; // write misc. CGI environment pieces textFile << "AUTH_TYPE=" << getAuthType() << endl; textFile << "GATEWAY_INTERFACE=" << getGatewayInterface() << endl; textFile << "HTTP_ACCEPT=" << getHTTPAccept() << endl; textFile << "HTTP_ACCEPT_ENCODING=" << getHTTPAcceptEncoding() << endl; textFile << "HTTP_ACCEPT_LANGUAGE=" << getHTTPAcceptLanguage() << endl; textFile << "HTTP_CONNECTION=" << getHTTPConnection() << endl; textFile << "HTTP_REFERER=" << getHTTPReferer() << endl; textFile << "HTTP_USER_AGENT=" << getHTTPUserAgent() << endl; textFile << "REMOTE_HOST=" << getRemoteHost() << endl; textFile << "REMOTE_ADDRESS=" << getRemoteAddress() << endl; textFile << "REMOTE_PORT=" << getRemotePort() << endl; textFile << "REQUEST_URI=" << getRequestURI() << endl; textFile << "SCRIPT_NAME=" << getScriptName() << endl; textFile << "SERVER_ADMIN=" << getServerAdmin() << endl; textFile << "SERVER_NAME=" << getServerName() << endl; textFile << "SERVER_PORT=" << getServerPort() << endl; textFile << "SERVER_PROTOCOL=" << getServerProtocol() << endl; textFile << "SERVER_SOFTWARE=" << getServerSoftware() << endl; } // close the file file.close(); }
void MainForm::recognizeInternal(const QImage &img) { const QString inputFile = "input.bmp"; const QString outputFile = "output.txt"; QFile f(workingDir+inputFile); f.remove(); f.setFileName(workingDir+outputFile); f.remove(); QPixmapCache::clear(); img.save(workingDir + inputFile, "BMP"); if (settings.getSelectedEngine() == UseCuneiform) { if (!useCuneiform(inputFile, outputFile)) return; } if (settings.getSelectedEngine() == UseTesseract) { if (!useTesseract(inputFile)) return; } QFile textFile(workingDir + outputFile); textFile.open(QIODevice::ReadOnly); QByteArray text = textFile.readAll(); textFile.close(); QString textData; QTextCodec *codec = QTextCodec::codecForName("UTF-8"); textData = codec->toUnicode(text); //QString::fromUtf8(text.data()); if (settings.getOutputFormat() == "text") textData.prepend("<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\" />"); textData.replace("<img src=output_files", ""); textData.replace(".bmp\">", "\"--"); textData.replace(".bmp>", ""); // textData.replace("-</p><p>", ""); // textData.replace("-<br>", ""); textEdit->append(textData); textEdit->append(QString(" ")); textSaved = FALSE; if (settings.getCheckSpelling()) { spellChecker->setLanguage(settings.getLanguage()); actionCheck_spelling->setChecked(spellChecker->spellCheck()); } }