From 3f4064f7ac672a511937b0a8aba04f87eb831294 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Feb 2009 15:43:06 -0500 Subject: [PATCH] ENH: Add cmCTest::DecodeURL method This new method decodes the "percent-encoding" used in URL syntax. --- Source/cmCTest.cxx | 21 +++++++++++++++++++++ Source/cmCTest.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index df7c11039..c1f2752e4 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -47,6 +47,7 @@ #include #include #include +#include #include // auto_ptr @@ -180,6 +181,26 @@ std::string cmCTest::MakeURLSafe(const std::string& str) return ost.str(); } +//---------------------------------------------------------------------------- +std::string cmCTest::DecodeURL(const std::string& in) +{ + std::string out; + for(const char* c = in.c_str(); *c; ++c) + { + if(*c == '%' && isxdigit(*(c+1)) && isxdigit(*(c+2))) + { + char buf[3] = {*(c+1), *(c+2), 0}; + out.append(1, char(strtoul(buf, 0, 16))); + c += 2; + } + else + { + out.append(1, *c); + } + } + return out; +} + //---------------------------------------------------------------------- cmCTest::cmCTest() { diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 2839f307b..5e1612ec4 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -310,6 +310,9 @@ public: //! Make string safe to be send as an URL static std::string MakeURLSafe(const std::string&); + /** Decode a URL to the original string. */ + static std::string DecodeURL(const std::string&); + //! Should ctect configuration be updated. When using new style ctest // script, this should be true. void SetSuppressUpdatingCTestConfiguration(bool val)