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.
60{
61
62 /*
63 * Importer index characters: -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
64 *
65 */
66 static const uint64_t importeridx_bitfield[] = {
67 0x000000000004ffc0, // "-", 0-9
68 0x7fffffe17fffffe0, // A-Z, "_", a-z
69 0x0000000000000000,
70 0x0000000000000000
71 };
72
73 int valid;
74
75 assert(data);
76
77
78 /*
79 * Data must be a single character.
80 *
81 */
82 if (GS1_LINTER_UNLIKELY(data_len != 1))
85 0,
86 data_len
87 );
88
89 /*
90 * Validate character using bitfield lookup
91 *
92 */
93 GS1_LINTER_BITFIELD_LOOKUP((unsigned char)data[0], importeridx_bitfield, valid);
94 if (GS1_LINTER_UNLIKELY(!valid))
97 0,
98 1
99 );
100
102
103}
#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