GS1 Barcode Syntax Tests reference
A reference to the AI component "linter" routines referred to by the GS1 Barcode Syntax Dictionary. Copyright (c) 2022-2024 GS1 AISBL.
lint_cset82.c File Reference

Purpose

The cset82 linter ensures that the given data contains only characters within the GS1 AI encodable character set 82 ("CSET 82").

Remarks
CSET 82 is defined in the GS1 General Specifications table "GS1 AI encodable character set 82".

Functional Description

◆ gs1_lint_cset82()

GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_cset82 ( const char *const  data,
size_t *const  err_pos,
size_t *const  err_len 
)

Used to validate that an AI component conforms to X..99 syntax.

Note: The length of the component is validated by the framework that calls this function.

Parameters
[in]dataPointer to the null-terminated data to be linted. Must not be NULL.
[out]err_posTo facilitate error highlighting, the start position of the bad data is written to this pointer, if not NULL.
[out]err_lenThe length of the bad data is written to this pointer, if not NULL.
Returns
GS1_LINTER_OK if okay.
GS1_LINTER_INVALID_CSET82_CHARACTER if the data contains a non-CSET 82 character.
57{
58
59 /*
60 * CSET 82 characters: !"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
61 *
62 */
63 static const uint64_t cset82_bitfield[] = {
64 0x0000000067ffffff, // "!", '"', "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", 0-9
65 0x7fffffe17fffffe0, // ":", ";", "<", "=", ">", "?", A-Z, "_", a-z
66 0x0000000000000000,
67 0x0000000000000000
68 };
69
70 size_t pos;
71
72 assert(data);
73
74 /*
75 * Validate character set using bitfield lookup
76 *
77 */
78 for (pos = 0; data[pos] != '\0'; pos++) {
79 int valid = 0;
80 GS1_LINTER_BITFIELD_LOOKUP((unsigned char)data[pos], cset82_bitfield);
81 if (GS1_LINTER_UNLIKELY(!valid))
84 pos,
85 1
86 );
87 }
88
90
91}
#define GS1_LINTER_UNLIKELY(x)
Implemention may provide hint to the compiler that the expression is likely to be false.
Definition gs1syntaxdictionary-utils.h:76
#define GS1_LINTER_RETURN_ERROR(error, position, length)
Return from a linter indicating that a problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:103
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:88
#define GS1_LINTER_BITFIELD_LOOKUP(bit, field)
Perform a lookup of a position in a bit field.
Definition gs1syntaxdictionary-utils.h:125
@ GS1_LINTER_INVALID_CSET82_CHARACTER
A non-CSET 82 character was found where a CSET 82 character is expected.
Definition gs1syntaxdictionary.h:79