CBStringList StringExplode(Bstrlib::CBString str, string separator){ //remove a lot of junk charecters so we can just explode on , //if the user sends some funky charecters it might break stuff but that's the users fault Bstrlib::CBString emtpy = ""; str.findreplace("{",emtpy); str.findreplace("}",emtpy); str.findreplace("(",emtpy); str.findreplace(")",emtpy); str.findreplace(".",emtpy); str.findreplace(" ",emtpy); str.findreplace("\\",emtpy); str.findreplace("/",emtpy); str.findreplace("&",emtpy); CBStringList params; params.split(str, ","); return params; }
int test28 (void) { int ret = 0; printf ("TEST: split(), join() mechanisms\n"); try { CBString c0, c1("a b c d e f"); struct CBStringList s; s.split (c1, ' '); c0.writeprotect (); EXCEPTION_EXPECTED (c0.join (s)); } catch (struct CBStringException err) { printf ("Exception thrown [%d]: %s\n", __LINE__, err.what()); ret ++; } try { CBString c0, c1("a b c d e f"); struct CBStringList s; printf ("\t\"%s\".split (' ')\n", (const char *) c1); s.split (c1, ' '); CBString c2(s), c3(s, ','); printf ("\tc.join (<...>)\n"); ret += c2 != "abcdef"; ret += c3 != "a,b,c,d,e,f"; c0.join (s); ret += c0 != "abcdef"; c0.join (s, ','); ret += c0 != "a,b,c,d,e,f"; CBString strPepe = "valor1@valor2@valor3@@@valor6"; for (unsigned char c = (unsigned char) '\0';;c++) { CBStringList sl; CBString x; sl.split (strPepe, c); x.join (sl, c); if (x != strPepe) { printf ("\tfailure[%d] split/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x); ret++; break; } if (UCHAR_MAX == c) break; } { CBStringList sl; CBString x; sl.splitstr (strPepe, CBString ("or")); x.join (sl, CBString ("or")); if (x != strPepe) { printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x); ret++; } } { CBStringList sl; CBString x; sl.splitstr (strPepe, CBString ("6")); x.join (sl, CBString ("6")); if (x != strPepe) { printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x); ret++; } } { CBStringList sl; CBString x; sl.splitstr (strPepe, CBString ("val")); x.join (sl, CBString ("val")); if (x != strPepe) { printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x); ret++; } } { CBStringList sl; CBString x; sl.splitstr (strPepe, CBString ("@@")); x.join (sl, CBString ("@@")); if (x != strPepe) { printf ("\tfailure[%d] splitstr/join mismatch\n\t\t%s\n\t\t%s\n", __LINE__, (const char *) strPepe, (const char *) x); ret++; } } } catch (struct CBStringException err) { printf ("Exception thrown [%d]: %s\n", __LINE__, err.what()); ret ++; } printf ("\t# failures: %d\n", ret); return ret; }