@@ -38,6 +38,28 @@ extern "C" {
3838 */
3939int fossil_io_getc (fossil_fstream_t *input_stream);
4040
41+ /* *
42+ * @brief Trim leading and trailing whitespace from a string in place.
43+ *
44+ * This function removes all whitespace characters (spaces, tabs, newlines, etc.)
45+ * from the beginning and end of the input string. The trimming is done **in place**,
46+ * modifying the original string, and the result is always null-terminated.
47+ *
48+ * @param str Pointer to the null-terminated string to be trimmed.
49+ * Must not be NULL. If the string is empty or contains only whitespace,
50+ * it will be converted to an empty string ("").
51+ *
52+ * @note This function does not allocate memory; it simply shifts characters within
53+ * the existing string buffer. The caller is responsible for ensuring that
54+ * the buffer is writable and large enough to hold the original string.
55+ *
56+ * @example
57+ * char s[] = " hello world \n";
58+ * fossil_io_trim(s);
59+ * // s now contains "hello world"
60+ */
61+ void fossil_io_trim (char *str);
62+
4163/* *
4264 * Reads a line from the input stream and stores it into the buffer pointed to by 'buf'.
4365 *
@@ -339,6 +361,30 @@ namespace fossil {
339361 return fossil_io_getc (input_stream);
340362 }
341363
364+ /* *
365+ * @brief Trim leading and trailing whitespace from a string in place.
366+ *
367+ * This function removes all whitespace characters (spaces, tabs, newlines, etc.)
368+ * from the beginning and end of the input string. The trimming is done **in place**,
369+ * modifying the original string, and the result is always null-terminated.
370+ *
371+ * @param str Pointer to the null-terminated string to be trimmed.
372+ * Must not be NULL. If the string is empty or contains only whitespace,
373+ * it will be converted to an empty string ("").
374+ *
375+ * @note This function does not allocate memory; it simply shifts characters within
376+ * the existing string buffer. The caller is responsible for ensuring that
377+ * the buffer is writable and large enough to hold the original string.
378+ *
379+ * @example
380+ * char s[] = " hello world \n";
381+ * fossil_io_trim(s);
382+ * // s now contains "hello world"
383+ */
384+ static void trim (char *str) {
385+ fossil_io_trim (str);
386+ }
387+
342388 /* *
343389 * Reads a line from the input stream and stores it into the buffer pointed to by 'buf'.
344390 *
0 commit comments