[PATCH] test: encoding: simplify BOM addition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux