git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim

From
Brian Gesiak <modocache@gmail.com>
Date
Apr 30, 2014, 08:58 UTC
Message-ID
<1398848287-77109-1-git-send-email-modocache@gmail.com>

strbuf_trim strips whitespace from the end, then the beginning of a strbuf. Those operations are duplicated in strbuf_rtrim and strbuf_ltrim.

Replace strbuf_trim implementation with calls to strbuf_rtrim, then strbuf_ltrim.

Signed-off-by: Brian Gesiak <modocache@gmail.com>
---

This is tangential to my GSoC project; I noticed the duplication and thought it could be remedied.

 strbuf.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/strbuf.c b/strbuf.c
index 83caf4a..382cf68 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -96,15 +96,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
 
 void strbuf_trim(struct strbuf *sb)
 {
-	char *b = sb->buf;
-	while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
-		sb->len--;
-	while (sb->len > 0 && isspace(*b)) {
-		b++;
-		sb->len--;
-	}
-	memmove(sb->buf, b, sb->len);
-	sb->buf[sb->len] = '\0';
+	strbuf_rtrim(sb);
+	strbuf_ltrim(sb);
 }
 void strbuf_rtrim(struct strbuf *sb)
 {
-- 
1.9.2.507.g779792a
Next: Brian Gesiak
Message 1 of 3 in “strbuf: Use _rtrim and _ltrim in strbuf_trim”
  1. 1/2 strbuf: Use _rtrim and _ltrim in strbuf_trimBrian Gesiak, Apr 30, 2014
  2. 2/2 api-strbuf.txt: Add docs for _trim and _ltrimBrian Gesiak, Apr 30, 2014
  3. Jeff KingApr 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.