On Wed, Jul 31, 2024 at 10:29:00AM -0700, Junio C Hamano wrote: > > Let's introduce a new strbuf_trim_trailing_ch() function that can be > > used to remove any trailing character, and let's refactor existing code > > that manually removed trailing characters using this new function. > > It is disappointing that this new one is not adequate to rewrite any > of the existing strbuf_trim* functions in terms of it, but that's > probably OK. I don't think it's possible without some awkwardness. strbuf_[lr]trim() both trim characters for which isspace(c) is true, and this new function only trims a single character (also from the right-hand side of the string, so strbuf_ltrim() would not be a candidate[^1]). Likewise for strbuf_trim_trailing_dir_sep(), which uses the platform-dependent is_dir_sep(). strbuf_trim_trailing_newline() is also complicated because it only removes '\n' or '\r\n' from the end of a buffer, but not a lone '\r' character. Thanks, Taylor [^1]: Unless you had a function to swap the order of the underlying buffer, then call the trim function on the right-hand side, before swapping it back. But that's obviously disgusting and clearly a bad idea.