diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/function/read_file.cc | 13 | ||||
-rw-r--r-- | src/utility.cc | 54 | ||||
-rw-r--r-- | src/utility.h | 15 |
4 files changed, 9 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4421841..c87ca68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ include_directories( add_executable( test test.cc - src/utility.cc src/transformer_facade.cc src/function/read_file.cc src/function/read_xml_file.cc diff --git a/src/function/read_file.cc b/src/function/read_file.cc index dcbff25..ea7a758 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -1,6 +1,6 @@ #include "read_file.h" -#include "utility.h" +#include <fstream> namespace InputXSLT { @@ -33,10 +33,15 @@ xalan::XObjectPtr FunctionReadFile::execute( fileName.end() ); + std::ifstream file(fileName); + + std::string content( + (std::istreambuf_iterator<char>(file)), + (std::istreambuf_iterator<char>()) + ); + return executionContext.getXObjectFactory().createString( - xalan::XalanDOMString( - InputXSLT::readFile(fileName).data() - ) + xalan::XalanDOMString(content.data()) ); } diff --git a/src/utility.cc b/src/utility.cc deleted file mode 100644 index fb6fe61..0000000 --- a/src/utility.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "utility.h" - -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - -#include <cstddef> -#include <cstdio> - -namespace { - -const int OpenFlags = O_RDONLY; -const mode_t OpenMode = S_IRUSR | S_IWUSR; - -} - -namespace InputXSLT { - -std::string readFile(const std::string& path) { - int descriptor( - open(path.data(), OpenFlags, OpenMode) - ); - - if ( descriptor == -1 ) { - close(descriptor); - - return "io error"; - } else { - struct stat info; - fstat(descriptor, &info); - const std::size_t size(info.st_size); - - char* const buffer(new char[size]); - - ssize_t readSize(read( - descriptor, - static_cast<void*const>(buffer), - size - )); - - close(descriptor); - - std::string content( - buffer, - readSize - ); - - delete[] buffer; - - return content; - } -} - -} diff --git a/src/utility.h b/src/utility.h deleted file mode 100644 index ee39a25..0000000 --- a/src/utility.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef INPUTXSLT_SRC_UTILITY_H_ -#define INPUTXSLT_SRC_UTILITY_H_ - -#include <string> - -namespace xalanc_1_11 { } -namespace xalan = xalanc_1_11; - -namespace InputXSLT { - -std::string readFile(const std::string&); - -} - -#endif // INPUTXSLT_SRC_UTILITY_H_ |