void LinNativeDisplayForm::parseAtomFeed() { QXmlStreamReader textReader(reply); QString htmlOutput = htmlPrefix; while (!textReader.atEnd()) { textReader.readNext(); if (textReader.isStartElement()) { if (textReader.name() == "entry") { parseAtomEntry(htmlOutput, textReader); } } } if (textReader.hasError()) { QString err; err.append("QXmlStreamReader returned error: "); err.append(textReader.errorString()); err.append("\nFor URL: "); err.append(sourceUrl); QMaemo5InformationBox::information(0, err, 0); qWarning() << err; return; } reply->deleteLater(); htmlOutput += " </body>\n</html>"; setHtml(htmlOutput, sourceUrl); }
void LinNativeDisplayForm::parseRSSFeed() { QXmlStreamReader textReader(reply); while (!textReader.atEnd()) { textReader.readNext(); if (textReader.isStartElement()) { if (textReader.name() == "channel") { parseRSSChannel(textReader); // For now, only parse one channel: break; } } } if (textReader.hasError()) { QString err; err.append("QXmlStreamReader returned error: "); err.append(textReader.errorString()); err.append("\nFor URL: "); err.append(sourceUrl); QMaemo5InformationBox::information(0, err, 0); qWarning() << err; return; } reply->deleteLater(); }
int CFileContentFinder::Find(LPCTSTR fileName, LPCTSTR matchString) { CSimpleStringMatcher sm(matchString); bool bSetSMToNull(m_pStringMatcher == NULL); if (bSetSMToNull) m_pStringMatcher = &sm; CFileContentFinderCallback::MatchData md; CTextLineReader textReader(fileName); while (true) { md.strLine = textReader.ReadLine(); if (md.strLine.IsEmpty()) break; md.bMatched = m_pStringMatcher->Match(md.strLine); if (md.bMatched) ++md.iMatchCount; md.iLineNo = textReader.GetCurrentLineNumber(); if (m_pFinderCallback != NULL) { if (m_pFinderCallback->MatchCallback(md)) break; } } if (bSetSMToNull) m_pStringMatcher = NULL; return md.iMatchCount; }
bool CSVData::load(const std::shared_ptr<IReader>& reader, const StringView separators, const StringView quotes, const StringView escapes) { TextReader textReader(reader); if (!loadFromTextReader(textReader, separators, quotes, escapes)) { clear(); return false; } return true; }
bool CSVData::load(const FilePath& path, const StringView separators, const StringView quotes, const StringView escapes) { TextReader textReader(path); if (!loadFromTextReader(textReader, separators, quotes, escapes)) { clear(); return false; } return true; }
int main(int argc, char* argv[]) { std::size_t test_case = 0; std::size_t count_inv; switch (test_case) { case 0: { std::vector<int> inputVec; inputVec.reserve(100000); textReader("D:/cpp_practise/test_cases/IntegerArray.txt",inputVec); count_inv = sort_count_inversion(inputVec,0,inputVec.size()-1); int gh = 0; } break; case 1: { std::vector<int> inputVec; inputVec.reserve(100000); textReader("D:/cpp_practise/test_cases/IntegerArray.txt",inputVec); count_inv = sort_count_inversion(inputVec,0,9); //considering only the first 10 elements } break; case 2: { static const int arr[] = {1, 5, 3, 2, 4, 6}; std::vector<int> inputVec(arr,arr+sizeof(arr)/sizeof(arr[0])); count_inv = sort_count_inversion(inputVec,0,inputVec.size()-1); int gh = 0; } break; } std::cout << "inversions(count): " << count_inv << std::endl; return 0; }
void AcoustidClient::requestFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); if (!reply) return; reply->deleteLater(); if (!m_requests.contains(reply)) return; int id = m_requests.take(reply); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (status != 200) { QTextStream body(reply); qDebug() << "AcoustIdClient POST reply status:" << status << "body:" << body.readAll(); emit(networkError( reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), "AcoustID")); return; } QTextStream textReader(reply); QString body = textReader.readAll(); qDebug() << "AcoustIdClient POST reply status:" << status << "body:" << body; QXmlStreamReader reader(body); QString ID; while (!reader.atEnd()) { if (reader.readNext() == QXmlStreamReader::StartElement && reader.name()== "results") { ID = parseResult(reader); } } emit(finished(id, ID)); }
int main(int argc, char* argv[]) { std::size_t test_case = 2; switch (test_case) { case 0: { //testing priority queue std::priority_queue<int,std::vector<int>,std::less<int> > pq1; std::priority_queue<int,std::vector<int>,std::greater<int> > pq2; pq1.push(1); pq1.push(7); pq1.push(3); pq2.push(8); pq2.push(1); pq2.push(3); std::cout << "top(pq1): " << pq1.top() << std::endl; std::cout << "top(pq2): " << pq2.top() << std::endl; pq2.push(pq1.top()); pq1.pop(); std::cout << "(after)top(pq1): " << pq1.top() << std::endl; std::cout << "(after)top(pq2): " << pq2.top() << std::endl; std::cout << "7 % 10 = " << 7 % 10 << std::endl; std::cout << "(12+8) % 10 = " << (12+8) % 10 << std::endl; std::cout << "(13+8) % 10 = " << (13+8) % 10 << std::endl; int gh = 0; } break; case 1: { std::vector<int> inputVec; inputVec.reserve(10000); textReader("D:/cpp_practise/test_cases/Median.txt",inputVec); int modulus = 10000; int median_sum_modulus = compute_median_sum_modulus(inputVec, modulus); std::cout << "sum of these 10000 medians, modulo 10000: " << median_sum_modulus << std::endl; int gh = 0; } break; case 2: { //https://class.coursera.org/algo-003/forum/thread?thread_id=669#post-3237 std::vector<int> inputVec; inputVec.reserve(5000); textReader("D:/cpp_practise/test_cases/median_sum/mmtest2.txt",inputVec); int modulus = 10000; int median_sum_modulus = compute_median_sum_modulus(inputVec, modulus); std::cout << "sum of these 5000 medians, modulo 10000: " << median_sum_modulus << std::endl; int gh = 0; } break; } return 0; }
int main() { int numValues = 6400000; double* values = new double [numValues]; double value; MersenneTwister rng; for ( int i = 0; i < numValues; ++i ) { values[i] = rng.rand_double_closed(-10000000, 10000000); } std::cout << "Testing big endian read/write" << std::endl; // write big std::ofstream bigFile( "/tmp/binaryBig", std::ios::binary ); DwD bigWriter( bigFile, DwD::Binary, DwD::BigEndian ); for ( int i = 0; i < numValues; ++i ) { bigWriter.write( values + i ); } bigFile.close(); // read big and validate std::ifstream bigFileRead( "/tmp/binaryBig", std::ios::binary ); DrD bigReader( bigFileRead, DrD::Binary, DrD::BigEndian ); int count = 0; while ( bigReader.read( value ) ) { assert( fabs( value - values[count] ) < 1e-8 ); ++count; } assert( count == numValues ); bigFileRead.close(); std::cout << " passed" << std::endl; std::cout << "Testing little endian read/write" << std::endl; // write little std::ofstream littleFile( "/tmp/binaryLittle", std::ios::binary ); DwD littleWriter( littleFile, DwD::Binary, DwD::LittleEndian ); for ( int i = 0; i < numValues; ++i ) { littleWriter.write( values[i] ); } littleFile.close(); // read little and validate std::ifstream littleFileRead( "/tmp/binaryLittle", std::ios::binary ); DrD littleReader( littleFileRead, DrD::Binary, DrD::LittleEndian ); count = 0; while ( littleReader.read( value ) ) { assert( fabs( value - values[count] ) < 1e-8 ); ++count; } assert( count == numValues ); littleFileRead.close(); std::cout << " passed" << std::endl; std::cout << "Testing text read/write" << std::endl; // write text std::ofstream textFile( "/tmp/text" ); textFile.precision(16); textFile.setf( std::ios::scientific ); DwD textWriter( textFile, DwD::Ascii ); for ( int i = 0; i < 1000; ++i ) { textWriter.write( values[i] ); textWriter.linebreak(); } textFile.close(); // read text and validate std::ifstream textFileRead( "/tmp/text" ); DrD textReader( textFileRead, DrD::Ascii ); count = 0; double foo; while( textReader.read( value ) ) { if ( fabs( value - values[ count ] ) >= 1e-8 ) { std::cout << "value:" << value << " values[" << count << "]:" << values[count] << std::endl; } assert( fabs( value - values[ count ] ) < 1e-8 ); ++count; } assert( count == 1000 ); textFileRead.close(); std::cout << " passed" << std::endl; delete [] values; }