@@ -385,13 +385,23 @@ std::string& WSJCppCore::trim(std::string& str, const std::string& chars) {
385385// ---------------------------------------------------------------------
386386
387387std::string& WSJCppCore::to_lower (std::string& str) {
388+ WSJCppLog::warn (" WSJCppCore::to_lower" , " Deprecated function, please use " );
388389 std::transform (str.begin (), str.end (), str.begin (), ::tolower);
389390 return str;
390391}
391392
392393// ---------------------------------------------------------------------
393394// will worked only with latin
394395
396+ std::string WSJCppCore::toLower (const std::string& str) {
397+ std::string sRet = str;
398+ std::transform (sRet .begin (), sRet .end (), sRet .begin (), ::tolower);
399+ return sRet ;
400+ }
401+
402+ // ---------------------------------------------------------------------
403+ // will worked only with latin
404+
395405std::string WSJCppCore::toUpper (const std::string& str) {
396406 std::string sRet = str;
397407 std::transform (sRet .begin (), sRet .end (), sRet .begin (), ::toupper);
@@ -400,6 +410,19 @@ std::string WSJCppCore::toUpper(const std::string& str) {
400410
401411// ---------------------------------------------------------------------
402412
413+ void WSJCppCore::replaceAll (std::string& str, const std::string& sFrom , const std::string& sTo ) {
414+ if (sFrom .empty ()) {
415+ return ;
416+ }
417+ size_t start_pos = 0 ;
418+ while ((start_pos = str.find (sFrom , start_pos)) != std::string::npos) {
419+ str.replace (start_pos, sFrom .length (), sTo );
420+ start_pos += sTo .length (); // In case 'to' contains 'sFrom', like replacing 'x' with 'yx'
421+ }
422+ }
423+
424+ // ---------------------------------------------------------------------
425+
403426void WSJCppCore::initRandom () {
404427 std::srand (std::rand () + std::time (0 ));
405428}
@@ -421,6 +444,17 @@ std::string WSJCppCore::createUuid() {
421444
422445// ---------------------------------------------------------------------
423446
447+ std::string WSJCppCore::uint2hexString (unsigned int n) {
448+ std::string sRet ;
449+ for (int i = 0 ; i < 8 ; i++) {
450+ sRet += " 0123456789abcdef" [n % 16 ];
451+ n >>= 4 ;
452+ }
453+ return std::string (sRet .rbegin (), sRet .rend ());
454+ }
455+
456+ // ---------------------------------------------------------------------
457+
424458unsigned long WSJCppCore::convertVoidToULong (void *p) {
425459 std::uintptr_t ret = reinterpret_cast <std::uintptr_t >(p);
426460 return (unsigned long )ret;
@@ -457,6 +491,51 @@ bool WSJCppCore::getEnv(const std::string& sName, std::string& sValue) {
457491 return false ;
458492}
459493
494+ // ---------------------------------------------------------------------
495+
496+ std::string WSJCppCore::encodeUriComponent (const std::string& sValue ) {
497+ std::stringstream ssRet;
498+ for (int i = 0 ; i < sValue .length (); i++) {
499+ char c = sValue [i];
500+ if (
501+ c == ' -' || c == ' _' || c == ' .' || c == ' !'
502+ || c == ' ~' || c == ' *' || c == ' \' '
503+ || c == ' (' || c == ' )' || (c >= ' 0' && c <= ' 9' )
504+ || (c >= ' a' && c <= ' z' ) || (c >= ' A' && c <= ' Z' )
505+ ) {
506+ ssRet << c;
507+ } else {
508+ ssRet << ' %' << std::uppercase << std::hex << (int )c;
509+ }
510+ }
511+ return ssRet.str ();
512+ }
513+
514+ // ---------------------------------------------------------------------
515+
516+ std::string WSJCppCore::decodeUriComponent (const std::string& sValue ) {
517+ std::string sRet = " " ;
518+ std::string sHex = " " ;
519+ int nLen = sValue .length ();
520+ for (int i = 0 ; i < sValue .length (); i++) {
521+ char c = sValue [i];
522+ if (c == ' %' ) {
523+ if (i+2 >= nLen) {
524+ WSJCppLog::throw_err (" WSJCppCore::decodeUriElement" , " Wrong format of string" );
525+ }
526+ sHex = " 0x" ;
527+ sHex += sValue [i+1 ];
528+ sHex += sValue [i+2 ];
529+ i = i + 2 ;
530+ char c1 = std::stoul (sHex , nullptr , 16 );
531+ sRet += c1;
532+ } else {
533+ sRet += c;
534+ }
535+ }
536+ return sRet ;
537+ }
538+
460539// ---------------------------------------------------------------------
461540// WSJCppLog
462541
0 commit comments