string_utils.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <string_view>
  5. #include <algorithm>
  6. #include <sstream>
  7. #include <regex>
  8. #include <unordered_map>
  9. #include <cstdint>
  10. #include <iomanip>
  11. namespace smartbotic::common {
  12. class StringUtils {
  13. public:
  14. // Trim whitespace
  15. static std::string trim(std::string_view str);
  16. static std::string trimLeft(std::string_view str);
  17. static std::string trimRight(std::string_view str);
  18. // Case conversion
  19. static std::string toLower(std::string_view str);
  20. static std::string toUpper(std::string_view str);
  21. // Split and join
  22. static std::vector<std::string> split(std::string_view str, char delimiter);
  23. static std::vector<std::string> split(std::string_view str, std::string_view delimiter);
  24. static std::string join(const std::vector<std::string>& parts, std::string_view delimiter);
  25. // String operations
  26. static bool startsWith(std::string_view str, std::string_view prefix);
  27. static bool endsWith(std::string_view str, std::string_view suffix);
  28. static bool contains(std::string_view str, std::string_view substr);
  29. // Replace
  30. static std::string replace(std::string_view str, std::string_view from, std::string_view to);
  31. static std::string replaceAll(std::string_view str, std::string_view from, std::string_view to);
  32. // Template interpolation: replaces ${VAR} with values from map
  33. static std::string interpolate(std::string_view tmpl,
  34. const std::unordered_map<std::string, std::string>& vars);
  35. // Environment variable expansion: replaces ${VAR:default} with env value or default
  36. static std::string expandEnvVars(std::string_view str);
  37. // URL encoding/decoding
  38. static std::string urlEncode(std::string_view str);
  39. static std::string urlDecode(std::string_view str);
  40. // Base64 encoding/decoding
  41. static std::string base64Encode(std::string_view data);
  42. static std::string base64Decode(std::string_view encoded);
  43. // Hex encoding/decoding
  44. static std::string hexEncode(const std::vector<uint8_t>& data);
  45. static std::vector<uint8_t> hexDecode(std::string_view hex);
  46. };
  47. } // namespace smartbotic::common