{"thread":{"id":"59384","subject":"[PATCH] test: encoding: simplify BOM addition","startedAt":"2023-03-13T05:05:06Z","lastAt":"2023-03-13T05:05:06Z","messageCount":1,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"473448","messageId":"20230313050459.3465060-1-felipe.contreras@gmail.com","threadId":"59384","inReplyTo":null,"subject":"[PATCH] test: encoding: simplify BOM addition","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-03-13T05:04:59Z","receivedAt":"2023-03-13T05:05:06Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"In 79444c9294 (utf8: handle systems that don't write BOM for UTF-16,\n2019-02-12) some prereqs were added (NO_UTF16_BOM and NO_UTF32_BOM) in\norder to conditionally add BOMs for the systems that need them.\n\nBut we don't need to check that prereq every time we are going to write\nsome text.\n\nLet's check the requirement only once and generate write_utf{16,32}\naccordingly.\n\nCc: Brian M. Carlson <sandals@crustytoothpaste.net>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/lib-encoding.sh | 28 ++++++++++++++--------------\n 1 file changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/t/lib-encoding.sh b/t/lib-encoding.sh\nindex 2dabc8c73e..15aea597be 100644\n--- a/t/lib-encoding.sh\n+++ b/t/lib-encoding.sh\n@@ -1,25 +1,25 @@\n # Encoding helpers\n \n-test_lazy_prereq NO_UTF16_BOM '\n-\ttest $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6\n-'\n+if test \"$(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c)\" = 6\n+then\n+\tadd_utf16_bom () { printf '\\376\\377'; }\n+else\n+\tadd_utf16_bom () { :; }\n+fi\n \n-test_lazy_prereq NO_UTF32_BOM '\n-\ttest $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12\n-'\n+if test \"$(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c)\" = 12\n+then\n+\tadd_utf32_bom () { printf '\\0\\0\\376\\377'; }\n+else\n+\tadd_utf32_bom () { :; }\n+fi\n \n write_utf16 () {\n-\tif test_have_prereq NO_UTF16_BOM\n-\tthen\n-\t\tprintf '\\376\\377'\n-\tfi &&\n+\tadd_utf16_bom &&\n \ticonv -f UTF-8 -t UTF-16\n }\n \n write_utf32 () {\n-\tif test_have_prereq NO_UTF32_BOM\n-\tthen\n-\t\tprintf '\\0\\0\\376\\377'\n-\tfi &&\n+\tadd_utf32_bom &&\n \ticonv -f UTF-8 -t UTF-32\n }\n-- \n2.39.2.13.g1fb56cf030\n\n"}]}