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)
This commit is contained in:
gitlost 2024-02-28 02:57:43 +00:00
parent f0d8901d9e
commit 11b3c18aed
8 changed files with 36 additions and 41 deletions

View File

@ -1,7 +1,7 @@
/* eci.c - Extended Channel Interpretations */
/*
libzint - the open source barcode library
Copyright (C) 2009-2023 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2024 Robin Stuart <rstuart114@gmail.com>
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;

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2019-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019-2024 Robin Stuart <rstuart114@gmail.com>
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;

View File

@ -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"

View File

@ -332,7 +332,7 @@
<h1 class="title">Zint Barcode Generator and Zint Barcode Studio User
Manual</h1>
<p class="author">Version 2.13.0.9</p>
<p class="date">January 2024</p>
<p class="date">February 2024</p>
</header>
<nav id="TOC" role="doc-toc">
<ul>
@ -8185,7 +8185,7 @@ Interpretations Part 1: Identification Schemes and Protocol (Released
24th May 2004)</li>
<li>AIM ITS/04-023 International Technical Standard - Extended Channel
Interpretations Part 3: Register (Version 2, February 2022)</li>
<li>GS1 General Specifications Release 23.0 (Jan 2023)</li>
<li>GS1 General Specifications Release 24.0 (Jan 2024)</li>
<li>ANSI/HIBC 2.6-2016 - The Health Industry Bar Code (HIBC) Supplier
Labeling Standard</li>
</ul>

View File

@ -1,6 +1,6 @@
% Zint Barcode Generator and Zint Barcode Studio User Manual
% Version 2.13.0.9
% January 2024
% February 2024
# 1. Introduction
@ -4841,7 +4841,7 @@ company references in particular.
May 2004)
- AIM ITS/04-023 International Technical Standard - Extended Channel
Interpretations Part 3: Register (Version 2, February 2022)
- GS1 General Specifications Release 23.0 (Jan 2023)
- GS1 General Specifications Release 24.0 (Jan 2024)
- ANSI/HIBC 2.6-2016 - The Health Industry Bar Code (HIBC) Supplier Labeling
Standard

View File

@ -1,6 +1,6 @@
Zint Barcode Generator and Zint Barcode Studio User Manual
Version 2.13.0.9
January 2024
February 2024
*******************************************************************************
* For reference the following is a text-only version of the Zint manual, *
@ -4662,7 +4662,7 @@ company references in particular.
May 2004)
- AIM ITS/04-023 International Technical Standard - Extended Channel
Interpretations Part 3: Register (Version 2, February 2022)
- GS1 General Specifications Release 23.0 (Jan 2023)
- GS1 General Specifications Release 24.0 (Jan 2024)
- ANSI/HIBC 2.6-2016 - The Health Industry Bar Code (HIBC) Supplier Labeling
Standard
@ -4814,7 +4814,7 @@ configured barcode is displayed once the "Generate" button is pressed.
Annex D. Man Page ZINT(1)
% ZINT(1) Version 2.13.0.9 % % January 2024
% ZINT(1) Version 2.13.0.9 % % February 2024
NAME

View File

@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.1.11.1
.\" Automatically generated by Pandoc 3.1.12
.\"
.TH "ZINT" "1" "January 2024" "Version 2.13.0.9" ""
.TH "ZINT" "1" "February 2024" "Version 2.13.0.9" ""
.SH NAME
\f[CR]zint\f[R] \- encode data as a barcode image
.SH SYNOPSIS

View File

@ -1,6 +1,6 @@
% ZINT(1) Version 2.13.0.9
%
% January 2024
% February 2024
# NAME