diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/function/read_file.cc | 13 | ||||
| -rw-r--r-- | src/utility.cc | 54 | ||||
| -rw-r--r-- | src/utility.h | 15 | 
3 files changed, 9 insertions, 73 deletions
| 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_ | 
