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

[PATCH] test: encoding: simplify BOM addition

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Mar 13, 2023, 05:04 UTC
Message-ID
<20230313050459.3465060-1-felipe.contreras@gmail.com>

In 79444c9294 (utf8: handle systems that don't write BOM for UTF-16, 2019-02-12) some prereqs were added (NO_UTF16_BOM and NO_UTF32_BOM) in order to conditionally add BOMs for the systems that need them.

But we don't need to check that prereq every time we are going to write some text.

Let's check the requirement only once and generate write_utf{16,32} accordingly.

Cc: Brian M. Carlson <sandals@crustytoothpaste.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 t/lib-encoding.sh | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/t/lib-encoding.sh b/t/lib-encoding.sh
index 2dabc8c73e..15aea597be 100644
--- a/t/lib-encoding.sh
+++ b/t/lib-encoding.sh
@@ -1,25 +1,25 @@
 # Encoding helpers
 
-test_lazy_prereq NO_UTF16_BOM '
-	test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6
-'
+if test "$(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c)" = 6
+then
+	add_utf16_bom () { printf '\376\377'; }
+else
+	add_utf16_bom () { :; }
+fi
 
-test_lazy_prereq NO_UTF32_BOM '
-	test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12
-'
+if test "$(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c)" = 12
+then
+	add_utf32_bom () { printf '\0\0\376\377'; }
+else
+	add_utf32_bom () { :; }
+fi
 
 write_utf16 () {
-	if test_have_prereq NO_UTF16_BOM
-	then
-		printf '\376\377'
-	fi &&
+	add_utf16_bom &&
 	iconv -f UTF-8 -t UTF-16
 }
 
 write_utf32 () {
-	if test_have_prereq NO_UTF32_BOM
-	then
-		printf '\0\0\376\377'
-	fi &&
+	add_utf32_bom &&
 	iconv -f UTF-8 -t UTF-32
 }
-- 
2.39.2.13.g1fb56cf030
Message 1 of 1 in “test: encoding: simplify BOM addition”
  1. test: encoding: simplify BOM additionFelipe Contreras, Mar 13, 2023

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.