static bool replace(std::string fn, std::string const &s1, std::string const &s2) { if (!fn.length() || !s1.length() || !s2.length()) { std::cerr << "Error: empty arg." << std::endl; return false; } std::ifstream rStream(fn.c_str()); fn += ".replace"; std::ofstream wStream(fn.c_str()); if (!rStream || !wStream) { std::cerr << "Error: could not open file." << std::endl; return false; } size_t i; while (getline(rStream, fn)) { i = 0; while ((i = fn.find(s1, i)) != std::string::npos) { fn.replace(i, s1.length(), s2); i += s2.length(); } wStream << fn << std::endl; } return true; }
void SerializeTask::draw() { SkPicture recorded; RecordPicture(fGM.get(), &recorded); SkDynamicMemoryWStream wStream; recorded.serialize(&wStream, &trivial_bitmap_encoder); SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream)); SkBitmap bitmap; SetupBitmap(fReference.config(), fGM.get(), &bitmap); DrawPicture(reconstructed, &bitmap); if (!BitmapsEqual(bitmap, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); } }
void form_UserRegistration::loadCfgFile() { QFile cfgFile; QTextStream rStream(&cfgFile); QString line; vector <QString> str; //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("cp1251")); cfgFile.setFileName("ovd.cfg"); cfgFile.open(QIODevice::ReadOnly | QIODevice::Text); do // загружаем названия частоиспользуемых ОВД { line = rStream.readLine(); if (line.contains("len_ovd")) { len_ovd.ovd = line.remove(QRegExp("(.*=)")); // cout << len_ovd.toAscii().data() << endl; } else if (line.contains("okt_ovd")) { okt_ovd.ovd = line.remove(QRegExp("(.*=)")); // cout << okt_ovd.toAscii().data() << endl; } else if (line.contains("perv_ovd")) { perv_ovd.ovd = line.remove(QRegExp("(.*=)")); // cout << perv_ovd.toAscii().data() << endl; } else if (line.contains("len_oufms")) { len_oufms.ovd = line.remove(QRegExp("(.*=)")); // cout << len_oufms.toAscii().data() << endl; } else if (line.contains("okt_oufms")) { okt_oufms.ovd = line.remove(QRegExp("(.*=)")); // cout << okt_oufms.toAscii().data() << endl; } else if (line.contains("perv_oufms")) { perv_oufms.ovd = line.remove(QRegExp("(.*=)")); // cout << perv_oufms.toAscii().data() << endl; } } while (!line.isNull()); cfgFile.close(); cfgFile.setFileName("streets.cfg"); cfgFile.open(QIODevice::ReadOnly | QIODevice::Text); do // загружаем списки улиц и распределяем их по овд { // так в лень было переписывать все в одну функцию... поэтому пока что так =) str.clear(); line = rStream.readLine(); if (line.contains("len_ovd=")) { int amount = line.remove(QRegExp("(.*=)")).toInt() - 1; for (int i = 0; i <= amount; i++) // пока не указанное количество улиц { line = rStream.readLine(); str.push_back(line); } len_ovd.streets = str; } else if (line.contains("okt_ovd=")) { int amount = line.remove(QRegExp("(.*=)")).toInt() - 1; for (int i = 0; i <= amount; i++) // пока не указанное количество улиц { line = rStream.readLine(); str.push_back(line); } okt_ovd.streets = str; } else if (line.contains("perv_ovd=")) { int amount = line.remove(QRegExp("(.*=)")).toInt() - 1; for (int i = 0; i <= amount; i++) // пока не указанное количество улиц { line = rStream.readLine(); str.push_back(line); } perv_ovd.streets = str; } } while (!line.isNull()); //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); }