- Timestamp:
- 10/01/21 22:46:49 (3 years ago)
- Location:
- cpp/frams/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/sstringutils.cpp
r973 r1156 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 367 367 return false; 368 368 } 369 370 bool sstringURLEncode(SString& target) 371 { 372 const char* x = target.c_str(); 373 bool changed = 0; 374 SString tmp; 375 tmp.reserve(target.length()); 376 static constexpr const char* ALLOWED_CHARS = "-_.~"; 377 for (; *x; x++) 378 { 379 if (!(isalnum(*x) || strchr(ALLOWED_CHARS, *x))) 380 { 381 tmp += "%"; 382 tmp += SString::sprintf("%02x", *x); 383 changed = 1; 384 } 385 else 386 tmp += *x; 387 } 388 if (changed) target = tmp; 389 return changed; 390 } 391 392 bool sstringURLDecode(SString &target) 393 { 394 const char* x = target.c_str(); 395 SString tmp; 396 char *f; 397 while (1) 398 { 399 f = strchr((char*)x, '%'); 400 if (f) 401 { 402 tmp.append(x, f - x); 403 char hex[3] = { f[1],f[2],0 }; 404 char* after; 405 unsigned long intvalue = strtoul(hex, &after, 16); 406 tmp += (char)intvalue; 407 x = f + 3; 408 } 409 else 410 { 411 if (tmp.length() == 0) return false; // nothing was changed! 412 tmp += x; 413 target = tmp; 414 return true; 415 } 416 } 417 } -
cpp/frams/util/sstringutils.h
r973 r1156 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 22 22 const char* skipQuoteString(const char* txt, const char* limit); 23 23 int sstringUnquote(SString &target); 24 25 bool sstringURLEncode(SString& target); 26 bool sstringURLDecode(SString &target); 24 27 25 28 int strFindField(const SString& txt, const SString& name, int &end);
Note: See TracChangeset
for help on using the changeset viewer.