blob: cdf38dd26777b7deb6fae62273a810f6f8c86f37 [file] [log] [blame]
kurtis.heimerl5a872472013-05-31 21:47:25 +00001/* Copyright 2011, Range Networks, Inc. */
dburgess82c46ff2011-10-07 02:40:51 +00002
3#include <URLEncode.h>
4#include <string>
5#include <string.h>
6#include <ctype.h>
7
8using namespace std;
9
10//based on javascript encodeURIComponent()
11string URLEncode(const string &c)
12{
13 static const char *digits = "01234567890ABCDEF";
14 string retVal="";
kurtis.heimerl1a2d2442012-12-22 04:30:56 +000015 for (size_t i=0; i<c.length(); i++)
dburgess82c46ff2011-10-07 02:40:51 +000016 {
17 const char ch = c[i];
18 if (isalnum(ch) || strchr("-_.!~'()",ch)) {
19 retVal += ch;
20 } else {
21 retVal += '%';
22 retVal += digits[(ch>>4) & 0x0f];
23 retVal += digits[ch & 0x0f];
24 }
25 }
26 return retVal;
27}
28