From dcef688ccc0ae60b001ce40fd591a2dfafbac294 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 9 Aug 2014 22:34:59 +0200 Subject: WebAdmin: Added GetURLEncodedString(). --- src/WebAdmin.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/WebAdmin.cpp') diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index f5dc6fde7..ab6925e55 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -444,6 +444,38 @@ AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input) +AString cWebAdmin::GetURLEncodedString(const AString & a_Input) +{ + // Translation table from nibble to hex: + static const char Hex[] = "0123456789abcdef"; + + // Preallocate the output to match input: + AString dst; + size_t len = a_Input.length(); + dst.reserve(len); + + // Loop over input and substitute whatever is needed: + for (size_t i = 0; i < len; i++) + { + char ch = a_Input[i]; + if (isalnum(ch) || (ch == '-') || (ch == '_') || (ch == '.') || (ch == '~')) + { + dst.push_back(ch); + } + else + { + dst.push_back('%'); + dst.push_back(Hex[(ch >> 4) & 0x0f]); + dst.push_back(Hex[ch & 0x0f]); + } + } // for i - a_Input[] + return dst; +} + + + + + AString cWebAdmin::GetBaseURL(const AStringVector & a_URLSplit) { AString BaseURL = "./"; -- cgit v1.2.3