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

[PATCH 3/4] utf8.c: remove strbuf_write()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Feb 19, 2010, 22:16 UTC
Message-ID
<4B7F0DCD.6040006@lsrfire.ath.cx>
In-Reply-To
<4B7F0D08.6040608@lsrfire.ath.cx>

The patch before the previous one made sure that all callers of strbuf_add_wrapped_text() supply a strbuf. Replace all calls of strbuf_write() with regular strbuf functions and remove it.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 utf8.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/utf8.c b/utf8.c
index 5146d30..87437b0 100644
--- a/utf8.c
+++ b/utf8.c
@@ -280,14 +280,6 @@ int is_utf8(const char *text)
 	return 1;
 }
 
-static inline void strbuf_write(struct strbuf *sb, const char *buf, int len)
-{
-	if (sb)
-		strbuf_insert(sb, sb->len, buf, len);
-	else
-		fwrite(buf, len, 1, stdout);
-}
-
 static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
 {
 	strbuf_grow(sb, n);
@@ -305,7 +297,7 @@ static void strbuf_add_indented_text(struct strbuf *buf, const char *text,
 		if (*eol == '\n')
 			eol++;
 		strbuf_addchars(buf, ' ', indent);
-		strbuf_write(buf, text, eol - text);
+		strbuf_add(buf, text, eol - text);
 		text = eol;
 		indent = indent2;
 	}
@@ -364,7 +356,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
 					start = space;
 				else
 					strbuf_addchars(buf, ' ', indent);
-				strbuf_write(buf, start, text - start);
+				strbuf_add(buf, start, text - start);
 				if (!c)
 					return w;
 				space = text;
@@ -373,20 +365,20 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
 				else if (c == '\n') {
 					space++;
 					if (*space == '\n') {
-						strbuf_write(buf, "\n", 1);
+						strbuf_addch(buf, '\n');
 						goto new_line;
 					}
 					else if (!isalnum(*space))
 						goto new_line;
 					else
-						strbuf_write(buf, " ", 1);
+						strbuf_addch(buf, ' ');
 				}
 				w++;
 				text++;
 			}
 			else {
 new_line:
-				strbuf_write(buf, "\n", 1);
+				strbuf_addch(buf, '\n');
 				text = bol = space + isspace(*space);
 				space = NULL;
 				w = indent = indent2;
-- 
1.7.0
Previous: René ScharfeNext: René Scharfe
Message 4 of 8 in “utf8.c: strbuf'ify strbuf_add_wrapped_text()”
  1. 0/4 utf8.c: strbuf'ify strbuf_add_wrapped_text()René Scharfe, Feb 19, 2010
  2. 1/4 utf8.c: remove print_wrapped_text()René Scharfe, Feb 19, 2010
  3. 2/4 utf8.c: remove print_spaces()René Scharfe, Feb 19, 2010
  4. 3/4 utf8.c: remove strbuf_write()René Scharfe, Feb 19, 2010
  5. 4/4 utf8.c: speculatively assume utf-8 in strbuf_add_wrapped_text()René Scharfe, Feb 19, 2010
  6. Johannes SchindelinFeb 20, 2010
  7. Junio C HamanoFeb 20, 2010
  8. Johannes SchindelinFeb 20, 2010

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.