Skip to content

v0.2.49..v0.2.50 changeset FileUtils.cpp

Garret Voltz edited this page Nov 6, 2019 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/util/FileUtils.cpp b/hoot-core/src/main/cpp/hoot/core/util/FileUtils.cpp
index b5a89aa..ec35a6b 100644
--- a/hoot-core/src/main/cpp/hoot/core/util/FileUtils.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/util/FileUtils.cpp
@@ -140,6 +140,22 @@ void FileUtils::writeFully(const QString& path, const QString& text)
   outFile.close();
 }
 
+void FileUtils::replaceFully(const QString& path, const QStringList& textsToReplace,
+                             const QStringList& replacementTexts)
+{
+  if (textsToReplace.size() != replacementTexts.size())
+  {
+    throw IllegalArgumentException("Texts to replace not the same size as the replacements texts.");
+  }
+
+  QString input = readFully(path);
+  for (int i = 0; i < textsToReplace.size(); i++)
+  {
+    input = input.replace(textsToReplace.at(i), replacementTexts.at(i));
+  }
+  writeFully(path, input);
+}
+
 long FileUtils::getNumberOfLinesInFile(const QString& file)
 {
   std::ifstream inFile(file.toStdString().c_str());
Clone this wiki locally