diff options
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r-- | crawl-ref/source/libutil.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index 58f6661805..d6064e7bbc 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -153,6 +153,36 @@ std::string make_stringf(const char *s, ...) return (buf); } +std::string &escape_path_spaces(std::string &s) +{ + std::string result; + result.clear(); +#ifdef UNIX + for (const char* ch = s.c_str(); *ch != '\0'; ++ch) + { + if (*ch == ' ') + { + result += '\\'; + } + result += *ch; + } +#elif defined(WIN32CONSOLE) || defined(WIN32TILES) + if (s.find(" ") != std::string::npos && + s.find("\"") == std::string::npos) + { + result = "\"" + s + "\""; + } else { + return s; + } +#else + // Not implemented for this platform. Assume that + // escaping isn't necessary. + return s; +#endif + s = result; + return s; +} + std::string &uppercase(std::string &s) { for (unsigned i = 0, sz = s.size(); i < sz; ++i) |