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