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

Purpose

The nonzero linter ensures that the given data has a non-zero value.

Functional Description

◆ gs1_lint_nonzero()

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

Used to validate that a numeric AI component has a non-zero value.

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_ILLEGAL_ZERO_VALUE if the data has a zero value.
GS1_LINTER_NON_DIGIT_CHARACTER if the data contains non-digit characters.
50{
51
52 size_t pos;
53 int has_nonzero = 0;
54
55 assert(data);
56
57 for (pos = 0; data[pos]; pos++) {
58 if (GS1_LINTER_UNLIKELY(data[pos] < '0' || data[pos] > '9'))
61 pos,
62 1
63 );
64 if (data[pos] != '0')
65 has_nonzero = 1;
66 }
67
68 if (GS1_LINTER_UNLIKELY(!has_nonzero))
71 0,
72 pos
73 );
74
76
77}
#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
@ GS1_LINTER_ILLEGAL_ZERO_VALUE
A non-zero value is required.
Definition gs1syntaxdictionary.h:92
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition gs1syntaxdictionary.h:78