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.
Macros
gs1syntaxdictionary-utils.h File Reference

Macros

#define GS1_LINTER_LIKELY(x)   (x)
 Implementation may provide hint to the compiler that the expression is likely to be true.
 
#define GS1_LINTER_UNLIKELY(x)   (x)
 Implementation may provide hint to the compiler that the expression is likely to be false.
 
#define GS1_LINTER_RETURN_OK
 Return from a linter indicating that no problem was detected with the given data.
 
#define GS1_LINTER_RETURN_ERROR(error, position, length)
 Return from a linter indicating that a problem was detected with the given data.
 
#define GS1_LINTER_BITFIELD_LOOKUP(bit, field, valid)
 Perform a lookup of a position in a bit field.
 
#define GS1_LINTER_BINARY_SEARCH(needle, needle_len, haystack, valid)
 Perform a binary search for a search term in a sorted set of strings.
 

Purpose

This header provides utility macros used by the reference linter functions.

Macro Definition Documentation

◆ GS1_LINTER_BINARY_SEARCH

#define GS1_LINTER_BINARY_SEARCH (   needle,
  needle_len,
  haystack,
  valid 
)
Value:
do { \
size_t s = 0; \
size_t e = sizeof(haystack) / sizeof(haystack[0]); \
valid = 0; \
while (s < e) { \
const size_t m = s + (e - s) / 2; \
const size_t haystack_len = strlen(haystack[m]); \
const size_t min_len = needle_len < haystack_len ? \
needle_len : haystack_len; \
int cmp = memcmp(needle, haystack[m], min_len); \
if (cmp == 0 && needle_len != haystack_len) \
cmp = needle_len < haystack_len ? -1 : 1; \
if (cmp == 0) { \
valid = 1; \
break; \
} else if (cmp < 0) \
e = m; \
else \
s = m + 1; \
} \
} while (0)

Perform a binary search for a search term in a sorted set of strings.

Parameters
[in]needleA search term string to be exactly matched.
[in]needle_lenLength of the needle string.
[in]haystackA array of strings to be searched. The array must be sorted, otherwise the matching behaviour is undefined.
[out]validSet to 1 if needle is found in haystack, otherwise set to 0.

◆ GS1_LINTER_BITFIELD_LOOKUP

#define GS1_LINTER_BITFIELD_LOOKUP (   bit,
  field,
  valid 
)
Value:
do { \
int w = CHAR_BIT * sizeof(field[0]); \
assert((size_t)(bit/w) < sizeof(field) / sizeof(field[0])); \
valid = (field[bit/w] & (UINT64_C(1) << (w-1) >> (bit%w))) ? 1 : 0; \
} while (0)

Perform a lookup of a position in a bit field.

Parameters
[in]bitThe bit position in the field to lookup. The position must be in the field otherwise the behaviour is undefined.
[in]fieldAn array whose elements (of type with arbitrary size) when concatenated produce a single bit field whose positions are numbered from left to right (MSB of first element to LSB of last element).
[out]validSet to 1 if the position numbered bit is set in the field, otherwise set to 0.

◆ GS1_LINTER_RETURN_ERROR

#define GS1_LINTER_RETURN_ERROR (   error,
  position,
  length 
)
Value:
do { \
if (err_pos) *err_pos = position; \
if (err_len) *err_len = length; \
return error; \
} while (0)

Return from a linter indicating that a problem was detected with the given data.

Parameters
[in]errorAn error of type gs1_lint_err_t to return.
[in]positionThe starting position of the invalid data.
[in]lengthThe length of the invalid data segment.

◆ GS1_LINTER_RETURN_OK

#define GS1_LINTER_RETURN_OK
Value:
do { \
return GS1_LINTER_OK; \
} while (0)
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition gs1syntaxdictionary.h:77

Return from a linter indicating that no problem was detected with the given data.

Note
For many linters this does not guarantee that the data is valid, only that it satisfies all of the checks performed by the linter.