From bbeb5ea38686dfeb9537860770bbdb3bd2f9cd3f Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 17 May 2013 02:03:16 +0100 Subject: Use iostream instead of C-style file operations. --- src/configreader.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/configreader.cpp') diff --git a/src/configreader.cpp b/src/configreader.cpp index bd8320137..905eb786a 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -773,14 +773,31 @@ bool ServerConfig::FileExists(const char* file) if ((sb.st_mode & S_IFDIR) > 0) return false; - FILE *input = fopen(file, "r"); - if (input == NULL) - return false; - else + return !access(file, F_OK); +} + +std::string ServerConfig::Escape(const std::string& str, bool xml) +{ + std::string escaped; + for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) { - fclose(input); - return true; + switch (*it) + { + case '"': + escaped += xml ? """ : "\""; + break; + case '&': + escaped += xml ? "&" : "&"; + break; + case '\\': + escaped += xml ? "\\" : "\\\\"; + break; + default: + escaped += *it; + break; + } } + return escaped; } const char* ServerConfig::CleanFilename(const char* name) -- cgit v1.2.3