From 11b3c18aed29cf9eb2a31debd66c8fe8a1d77604 Mon Sep 17 00:00:00 2001 From: gitlost Date: Wed, 28 Feb 2024 02:57:43 +0000 Subject: [PATCH] ECI: `get_best_eci()`: just assert `is_valid_utf8()` as checked prior to being called manual: update to latest GS1 General Specifications (v24), pandoc (3.1.12.1) --- backend/eci.c | 10 ++++------ backend/tests/test_eci.c | 35 ++++++++++++++++------------------- docs/README | 12 ++++++------ docs/manual.html | 4 ++-- docs/manual.pmd | 4 ++-- docs/manual.txt | 6 +++--- docs/zint.1 | 4 ++-- docs/zint.1.pmd | 2 +- 8 files changed, 36 insertions(+), 41 deletions(-) diff --git a/backend/eci.c b/backend/eci.c index 4fa22124..31b0afeb 100644 --- a/backend/eci.c +++ b/backend/eci.c @@ -1,7 +1,7 @@ /* eci.c - Extended Channel Interpretations */ /* libzint - the open source barcode library - Copyright (C) 2009-2023 Robin Stuart + Copyright (C) 2009-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -764,7 +764,7 @@ INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned c return 0; } -/* Find the lowest single-byte ECI mode which will encode a given set of Unicode text */ +/* Find the lowest single-byte ECI mode which will encode a given set of Unicode text, assuming valid UTF-8 */ INTERNAL int get_best_eci(const unsigned char source[], int length) { int eci = 3; /* Note: attempting single-byte conversions only, so get_eci_length() unnecessary */ @@ -782,14 +782,12 @@ INTERNAL int get_best_eci(const unsigned char source[], int length) { eci++; } while (eci < 25); - if (!is_valid_utf8(source, length)) { - return 0; - } + assert(is_valid_utf8(source, length)); return 26; /* If all of these fail, use UTF-8! */ } -/* Call `get_best_eci()` for each segment. Returns 0 on failure, first ECI set on success */ +/* Call `get_best_eci()` for each segment, assuming valid UTF-8. Returns 0 on failure, first ECI set on success */ INTERNAL int get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { const int default_eci = symbol->symbology == BARCODE_GRIDMATRIX ? 29 : symbol->symbology == BARCODE_UPNQR ? 4 : 3; int first_eci_set = 0; diff --git a/backend/tests/test_eci.c b/backend/tests/test_eci.c index 213bafbd..b9252368 100644 --- a/backend/tests/test_eci.c +++ b/backend/tests/test_eci.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2019-2022 Robin Stuart + Copyright (C) 2019-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -1381,14 +1381,12 @@ static void test_get_best_eci(const testCtx *const p_ctx) { }; /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ struct item data[] = { - /* 0*/ { "\300\301", -1, 0 }, - /* 1*/ { "ÀÁ", -1, 3 }, - /* 2*/ { "Ђ", -1, 7 }, - /* 3*/ { "Ѐ", -1, 26 }, /* Cyrillic U+0400 not in single-byte code pages */ - /* 4*/ { "β", -1, 9 }, - /* 5*/ { "˜", -1, 23 }, - /* 6*/ { "βЂ", -1, 26 }, - /* 7*/ { "AB\200", -1, 0 }, + /* 0*/ { "ÀÁ", -1, 3 }, + /* 1*/ { "Ђ", -1, 7 }, + /* 2*/ { "Ѐ", -1, 26 }, /* Cyrillic U+0400 not in single-byte code pages */ + /* 3*/ { "β", -1, 9 }, + /* 4*/ { "˜", -1, 23 }, + /* 5*/ { "βЂ", -1, 26 }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; @@ -1417,16 +1415,15 @@ static void test_get_best_eci_segs(const testCtx *const p_ctx) { }; /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ struct item data[] = { - /* 0*/ { { { TU("\300\301"), -1, 0 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, - /* 1*/ { { { TU("A"), -1, 0 }, { TU("\300\301"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, - /* 2*/ { { { TU("A"), -1, 0 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, /* As 1st seg default ECI, 3 not returned */ - /* 3*/ { { { TU("A"), -1, 4 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 3, 0 }, - /* 4*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 }, - /* 5*/ { { { TU("A"), -1, 4 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 }, - /* 6*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("Ѐ"), -1, 0 } }, 26, 0 }, /* Cyrillic U+0400 not in single-byte code pages */ - /* 7*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU("β"), -1, 0 } }, 7, 0 }, - /* 8*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("β"), -1, 0 } }, 9, 0 }, - /* 9*/ { { { TU("˜"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU(""), 0, 0 } }, 23, 23 }, + /* 0*/ { { { TU("A"), -1, 0 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, + /* 1*/ { { { TU("A"), -1, 0 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, /* As 1st seg default ECI, 3 not returned */ + /* 2*/ { { { TU("A"), -1, 4 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 3, 0 }, + /* 3*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 }, + /* 4*/ { { { TU("A"), -1, 4 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 }, + /* 5*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("Ѐ"), -1, 0 } }, 26, 0 }, /* Cyrillic U+0400 not in single-byte code pages */ + /* 6*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU("β"), -1, 0 } }, 7, 0 }, + /* 7*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("β"), -1, 0 } }, 9, 0 }, + /* 8*/ { { { TU("˜"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU(""), 0, 0 } }, 23, 23 }, }; int data_size = ARRAY_SIZE(data); int i, j, seg_count, ret; diff --git a/docs/README b/docs/README index ec7a24e3..2c21b1a3 100644 --- a/docs/README +++ b/docs/README @@ -1,11 +1,11 @@ -% docs/README 2014-01-17 +% docs/README 2014-02-28 For generation of "docs/manual.pdf" and "docs/manual.txt" from "manual.pmd" using a recent version of pandoc On Ubuntu/Debian (tested on Ubuntu 22.04) - wget https://github.com/jgm/pandoc/releases/download/3.1.11.1/pandoc-3.1.11.1-1-amd64.deb - sudo dpkg -i pandoc-3.1.11.1-1-amd64.deb + wget https://github.com/jgm/pandoc/releases/download/3.1.12.1/pandoc-3.1.12.1-1-amd64.deb + sudo dpkg -i pandoc-3.1.12.1-1-amd64.deb sudo apt install python3-pip pip install pandoc-tablenos --user export PATH=~/.local/bin:"$PATH" @@ -20,9 +20,9 @@ On Ubuntu/Debian (tested on Ubuntu 22.04) On Fedora (tested on Fedora Linux 38 (Workstation Edition)) - wget https://github.com/jgm/pandoc/releases/download/3.1.11.1/pandoc-3.1.11.1-linux-amd64.tar.gz - tar xf pandoc-3.1.11.1-linux-amd64.tar.gz - sudo mv -i pandoc-3.1.11.1/bin/pandoc /usr/local/bin + wget https://github.com/jgm/pandoc/releases/download/3.1.12.1/pandoc-3.1.12.1-linux-amd64.tar.gz + tar xf pandoc-3.1.12.1-linux-amd64.tar.gz + sudo mv -i pandoc-3.1.12.1/bin/pandoc /usr/local/bin sudo dnf install python3-pip pip install pandoc-tablenos --user export PATH=~/.local/bin:"$PATH" diff --git a/docs/manual.html b/docs/manual.html index fd641328..381ae9eb 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -332,7 +332,7 @@

Zint Barcode Generator and Zint Barcode Studio User Manual

Version 2.13.0.9

-

January 2024

+

February 2024