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_importeridx.c File Reference

Purpose

The importeridx linter ensures that the given data is a valid Importer Index, as included in a Facility ID or Machine ID used in the EU 2018/574 system.

Remarks
The Facility ID and Machine ID data elements used in the EU 2018/574 system are described in the GS1 General Specification section "European Regulation 2018/574, traceability of tobacco products".

Functional Description

◆ gs1_lint_importeridx()

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

Used to validate that an AI component is a valid Importer Index.

Parameters
[in]dataPointer to the data to be linted. Must not be NULL.
[in]data_lenLength of the data to be linted.
[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_IMPORT_IDX_CHARACTER if the data is not a valid Importer Index character.
GS1_LINTER_IMPORTER_IDX_MUST_BE_ONE_CHARACTER if the data isn't a single character.
59{
60
61 /*
62 * Importer index characters: -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
63 *
64 */
65 static const uint64_t importeridx_bitfield[] = {
66 0x000000000004ffc0, // "-", 0-9
67 0x7fffffe17fffffe0, // A-Z, "_", a-z
68 0x0000000000000000,
69 0x0000000000000000
70 };
71
72 int valid;
73
74 assert(data);
75
76
77 /*
78 * Data must be a single character.
79 *
80 */
81 if (GS1_LINTER_UNLIKELY(data_len != 1))
84 0,
85 data_len
86 );
87
88 /*
89 * Validate character using bitfield lookup
90 *
91 */
92 GS1_LINTER_BITFIELD_LOOKUP((unsigned char)data[0], importeridx_bitfield, valid);
93 if (GS1_LINTER_UNLIKELY(!valid))
96 0,
97 1
98 );
99
101
102}
#define GS1_LINTER_UNLIKELY(x)
Implementation 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_BITFIELD_LOOKUP(bit, field, valid)
Perform a lookup of a position in a bit field.
Definition gs1syntaxdictionary-utils.h:124
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:88
@ GS1_LINTER_INVALID_IMPORT_IDX_CHARACTER
The Importer Index is an invalid character.
Definition gs1syntaxdictionary.h:91
@ GS1_LINTER_IMPORTER_IDX_MUST_BE_ONE_CHARACTER
The Importer Index must be a single character.
Definition gs1syntaxdictionary.h:90