| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #pragma once
- #include <string>
- #include <vector>
- #include <string_view>
- #include <algorithm>
- #include <sstream>
- #include <regex>
- #include <unordered_map>
- #include <cstdint>
- #include <iomanip>
- namespace smartbotic::common {
- class StringUtils {
- public:
- // Trim whitespace
- static std::string trim(std::string_view str);
- static std::string trimLeft(std::string_view str);
- static std::string trimRight(std::string_view str);
- // Case conversion
- static std::string toLower(std::string_view str);
- static std::string toUpper(std::string_view str);
- // Split and join
- static std::vector<std::string> split(std::string_view str, char delimiter);
- static std::vector<std::string> split(std::string_view str, std::string_view delimiter);
- static std::string join(const std::vector<std::string>& parts, std::string_view delimiter);
- // String operations
- static bool startsWith(std::string_view str, std::string_view prefix);
- static bool endsWith(std::string_view str, std::string_view suffix);
- static bool contains(std::string_view str, std::string_view substr);
- // Replace
- static std::string replace(std::string_view str, std::string_view from, std::string_view to);
- static std::string replaceAll(std::string_view str, std::string_view from, std::string_view to);
- // Template interpolation: replaces ${VAR} with values from map
- static std::string interpolate(std::string_view tmpl,
- const std::unordered_map<std::string, std::string>& vars);
- // Environment variable expansion: replaces ${VAR:default} with env value or default
- static std::string expandEnvVars(std::string_view str);
- // URL encoding/decoding
- static std::string urlEncode(std::string_view str);
- static std::string urlDecode(std::string_view str);
- // Base64 encoding/decoding
- static std::string base64Encode(std::string_view data);
- static std::string base64Decode(std::string_view encoded);
- // Hex encoding/decoding
- static std::string hexEncode(const std::vector<uint8_t>& data);
- static std::vector<uint8_t> hexDecode(std::string_view hex);
- };
- } // namespace smartbotic::common
|