summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-11-28 18:30:13 (GMT)
committerBrad King <brad.king@kitware.com>2018-11-28 19:27:22 (GMT)
commit652210e901f5e1e9bf8e25d35423348de8e50c1a (patch)
tree5d61ed11486a6d4dd15f76601fe1f9dff53128ce /Source/cmSystemTools.cxx
parent772edffbf0c08fc0a6fcf74fb98545b7afcfee13 (diff)
downloadCMake-652210e901f5e1e9bf8e25d35423348de8e50c1a.zip
CMake-652210e901f5e1e9bf8e25d35423348de8e50c1a.tar.gz
CMake-652210e901f5e1e9bf8e25d35423348de8e50c1a.tar.bz2
cmSystemTools: Add EncodeURL helper
Factor a URL encoding implementation out of CTest. Add an option to not escape slashes. Suggested-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx29
1 files changed, 29 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 28aa57c..6fbe482 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -3009,6 +3009,35 @@ bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
return (*endp == '\0') && (endp != str) && (errno == 0);
}
+std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes)
+{
+ std::string out;
+ for (char c : in) {
+ char hexCh[4] = { 0, 0, 0, 0 };
+ hexCh[0] = c;
+ switch (c) {
+ case '+':
+ case '?':
+ case '\\':
+ case '&':
+ case ' ':
+ case '=':
+ case '%':
+ sprintf(hexCh, "%%%02X", static_cast<int>(c));
+ break;
+ case '/':
+ if (escapeSlashes) {
+ strcpy(hexCh, "%2F");
+ }
+ break;
+ default:
+ break;
+ }
+ out.append(hexCh);
+ }
+ return out;
+}
+
bool cmSystemTools::CreateSymlink(const std::string& origName,
const std::string& newName)
{