#pragma once #include #include #include #include #include #include #include #include #include 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 split(std::string_view str, char delimiter); static std::vector split(std::string_view str, std::string_view delimiter); static std::string join(const std::vector& 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& 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& data); static std::vector hexDecode(std::string_view hex); /// Hex SHA-256 of the given bytes. /// /// A binary object's `checksum` is the hash of its base64 text, not of the /// raw bytes - `http-request.js:457` does `sha256(base64Data)`. An upload /// and a download of the same image must produce the same checksum or /// deduplication downstream silently stops working, so hash the same input. static std::string sha256Hex(std::string_view data); }; } // namespace smartbotic::common