Skip to content

Commit c276a67

Browse files
committed
url_decoding
1 parent 2cf7eb7 commit c276a67

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

unittest/util_test.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ TEST_F(TestUtil, testVectorWrapper){
173173
auto a = std::make_tuple(std::make_shared<VectorWrapper>(std::move(s)), std::make_shared<VectorWrapper>(std::move(s)));
174174
}
175175
}
176+
char urlDecode(const char* a) {
177+
auto l = a[0];
178+
auto r = a[1];
179+
auto mask = (l - 'A') >> 8;
180+
auto ch = ((l - 'A' + 10) & (~mask)) + ((l - '0') & mask);
181+
mask = (r - 'A') >> 8;
182+
ch = (ch << 4) + ((r - 'A' + 10) & (~mask)) + ((r - '0') & mask);
183+
return ch;
184+
}
185+
TEST_F(TestUtil, testUrlDecode) {
186+
187+
std::string s = "%21\t%23\t%24\t%26\t%27\t%28\t%29\t%2A\t%2B\t%2C\t%2F\t%3A\t%3B\t%3D\t%3F\t%40\t%5B\t%5D";
188+
const char* p = s.data();
189+
while(p < s.data()+s.size()) {
190+
if (*p=='%' || *p == '\t') {
191+
++p;
192+
continue;
193+
}
194+
195+
std::cout<<urlDecode(p)<<std::endl;
196+
p+=2;
197+
}
198+
}
176199

177200

178201

0 commit comments

Comments
 (0)