| | |
| | | return stream.str(); |
| | | } |
| | | |
| | | static string to_string(float val) { |
| | | std::stringstream stream; |
| | | stream << std::fixed << std::setprecision(2) << val; |
| | | return stream.str(); |
| | | } |
| | | |
| | | static bool isNumber(const std::string& str) { |
| | | if (str.empty()) { |
| | | return false; |
| | |
| | | return decoded; |
| | | } |
| | | |
| | | static std::string trim(const std::string& str) { |
| | | if (str.empty()) { |
| | | return str; |
| | | } |
| | | |
| | | // 去除前空格 |
| | | size_t start = str.find_first_not_of(" \t\n\r"); |
| | | if (start == std::string::npos) { |
| | | return ""; // 如果全是空格,返回空字符串 |
| | | } |
| | | |
| | | // 去除后空格 |
| | | size_t end = str.find_last_not_of(" \t\n\r"); |
| | | return str.substr(start, end - start + 1); |
| | | } |
| | | |
| | | }; |