| 10 | namespace fl { |
| 11 | |
| 12 | fl::string formatJsonResponse(const fl::json& response, const char* prefix) { |
| 13 | // Use sstream to minimize allocations |
| 14 | fl::sstream ss; |
| 15 | |
| 16 | // Add prefix if provided |
| 17 | if (prefix && prefix[0] != '\0') { |
| 18 | ss << prefix; |
| 19 | } |
| 20 | |
| 21 | // Serialize to compact JSON |
| 22 | fl::string jsonStr = response.to_string(); |
| 23 | |
| 24 | // Stream copy with inline filtering (replace newlines with spaces) |
| 25 | for (size_t i = 0; i < jsonStr.size(); ++i) { |
| 26 | char c = jsonStr[i]; |
| 27 | ss << ((c == '\n' || c == '\r') ? ' ' : c); |
| 28 | } |
| 29 | |
| 30 | return ss.str(); |
| 31 | } |
| 32 | |
| 33 | } // namespace fl |
no test coverage detected