summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-12-06 14:06:08 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-12-06 14:06:13 (GMT)
commit81bea69bd1d52977c3782d26560f34563394f487 (patch)
tree119ff003d2fe9fe9e34b181c7af24c09f7625d6d /Source/cmSystemTools.cxx
parentd69877fe8617031a4077bb2b97d76af6b2e7b088 (diff)
parent7954ba9bc196b34ced6c3359c464afbd0678c2e0 (diff)
downloadCMake-81bea69bd1d52977c3782d26560f34563394f487.zip
CMake-81bea69bd1d52977c3782d26560f34563394f487.tar.gz
CMake-81bea69bd1d52977c3782d26560f34563394f487.tar.bz2
Merge topic 'productbuild-encode-pkg-url-ref'
7954ba9bc1 productbuild: escape pkg-ref urls 652210e901 cmSystemTools: Add EncodeURL helper Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2681
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)
{