hstring_test.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "hstring.h"
  2. using namespace hv;
  3. int main(int argc, char** argv) {
  4. std::string str1 = "a1B2*C3d4==";
  5. std::string str2 = "a1B2*C3d4==";
  6. printf("toupper %s\n", toupper(str1).c_str());
  7. printf("tolower %s\n", tolower(str2).c_str());
  8. std::string str3 = "abcdefg";
  9. printf("reverse %s\n", reverse(str3).c_str());
  10. std::string str4 = "123456789";
  11. printf("startswith=%d\nendswith=%d\ncontains=%d\n",
  12. (int)startswith(str4, "123"),
  13. (int)endswith(str4, "789"),
  14. (int)contains(str4, "456"));
  15. std::string str5 = asprintf("%s%d", "hello", 5);
  16. printf("asprintf %s\n", str5.c_str());
  17. std::string str6("123,456,789");
  18. StringList strlist = split(str6, ',');
  19. printf("split %s\n", str6.c_str());
  20. for (auto& str : strlist) {
  21. printf("%s\n", str.c_str());
  22. }
  23. std::string str7("user=admin&pswd=123456");
  24. hv::KeyValue kv = splitKV(str7, '&', '=');
  25. for (auto& pair : kv) {
  26. printf("%s=%s\n", pair.first.c_str(), pair.second.c_str());
  27. }
  28. std::string str8("<stdio.h>");
  29. std::string str9 = trim_pairs(str8);
  30. printf("trim_pairs %s\n", str9.c_str());
  31. std::string str10("<title>{{title}}</title>");
  32. std::string str11 = replace(str10, "{{title}}", "Home");
  33. printf("replace %s\n", str11.c_str());
  34. return 0;
  35. }