diff options
author | Peter Powell <petpow@saberuk.com> | 2013-05-17 02:03:16 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2013-06-06 01:44:57 +0100 |
commit | bbeb5ea38686dfeb9537860770bbdb3bd2f9cd3f (patch) | |
tree | 3245e00a5758da375b57223535ecac90c13aea2d /src/configreader.cpp | |
parent | cc79342f50ce345657fca16c90f1d37a9228d8ad (diff) |
Use iostream instead of C-style file operations.
Diffstat (limited to 'src/configreader.cpp')
-rw-r--r-- | src/configreader.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
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) |