Ensures normalization on waitfe/fc-xml operations
[anna.git] / source / core / functions.cpp
index 8a77994..217fd0a 100644 (file)
@@ -30,6 +30,8 @@
 #include <anna/core/util/Tokenizer.hpp>
 
 #include <algorithm>
+#include <fstream>
+#include <sstream>
 
 
 using namespace anna;
@@ -1612,3 +1614,18 @@ std::string functions::decodeBase64(const std::string & encodedString) {
   return ret;
 }
 
+bool functions::getContentFromFile(const std::string &pathfile, std::string &content) throw(anna::RuntimeException) {
+
+  std::ifstream inFile(pathfile.c_str(), std::ifstream::in);
+  if(!inFile.good()) {
+    throw RuntimeException(anna::functions::asString("Unable to open file '%s'", pathfile.c_str()), ANNA_FILE_LOCATION);
+  }
+
+  std::stringstream strStream;
+  strStream << inFile.rdbuf(); //read the file
+  content = strStream.str(); // holds the content of the file
+  inFile.close();
+
+  return true;
+}
+