From 625c8a53cc05d3c668444947c50da4d49cedbf52 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 19:37:21 +0000 Subject: [PATCH 1/3] Add string_truncate utility function Co-Authored-By: Jake Cosme --- common/common.cpp | 11 +++++++++++ common/common.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/common/common.cpp b/common/common.cpp index b0591e84b06..35134707ffa 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -527,6 +527,17 @@ std::string string_repeat(const std::string & str, size_t n) { return result; } +// Truncate a string to a maximum length, adding ellipsis if truncated +std::string string_truncate(const std::string & str, size_t max_len) { + if (str.length() <= max_len) { + return str; + } + if (max_len < 3) { + return str.substr(0, max_len); + } + return str.substr(0, max_len - 3) + "..."; +} + std::string string_from(bool value) { return value ? "true" : "false"; } diff --git a/common/common.h b/common/common.h index a8cb630ea58..de7ddf75e27 100644 --- a/common/common.h +++ b/common/common.h @@ -587,6 +587,9 @@ bool string_ends_with(const std::string_view & str, const std::string_view & suf bool string_remove_suffix(std::string & str, const std::string_view & suffix); size_t string_find_partial_stop(const std::string_view & str, const std::string_view & stop); +// Truncate a string to a maximum length, adding ellipsis if truncated +std::string string_truncate(const std::string & str, size_t max_len); + bool string_parse_kv_override(const char * data, std::vector & overrides); void string_process_escapes(std::string & input); From 538cf12793836219578b69a3df3d9d9ed156be28 Mon Sep 17 00:00:00 2001 From: Jake Cosme <227240413+jakexcosme@users.noreply.github.com> Date: Mon, 15 Dec 2025 11:46:47 -0800 Subject: [PATCH 2/3] Add test comment in common.cpp Add comment to test if changes are detected --- common/common.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/common.cpp b/common/common.cpp index 35134707ffa..688c6c3a0dc 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1,3 +1,5 @@ +##testing if devin picks up changes + #if defined(_MSC_VER) #define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING #endif From c5e26d41030898884c94799f0c1ae3bf385c6796 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 19:50:49 +0000 Subject: [PATCH 3/3] Add Doxygen documentation for string_truncate function Co-Authored-By: Jake Cosme --- common/common.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/common/common.cpp b/common/common.cpp index 688c6c3a0dc..26997ec790f 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -529,7 +529,27 @@ std::string string_repeat(const std::string & str, size_t n) { return result; } -// Truncate a string to a maximum length, adding ellipsis if truncated +/** + * @brief Truncates a string to a maximum length, appending ellipsis if truncated. + * + * This function shortens a string to fit within a specified maximum length. + * If truncation occurs, "..." is appended to indicate the string was shortened. + * + * @param str The input string to truncate. + * @param max_len The maximum allowed length of the output string (including ellipsis). + * + * @return The original string if its length is <= max_len. + * If max_len < 3, returns the first max_len characters without ellipsis. + * Otherwise, returns the first (max_len - 3) characters followed by "...". + * + * @note This function operates on bytes, not Unicode code points. Truncating + * UTF-8 strings may result in invalid sequences if cut mid-character. + * + * @example + * string_truncate("Hello World", 8) -> "Hello..." + * string_truncate("Hi", 10) -> "Hi" + * string_truncate("Hello", 2) -> "He" + */ std::string string_truncate(const std::string & str, size_t max_len) { if (str.length() <= max_len) { return str;