GS1 Syntax Dictionary: Linter reference
A reference to the AI component linter routines referred to by the GS1 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.
49{
50
51 size_t len, pos;
52
53 assert(data);
54
55 len = strlen(data);
56
57 /*
58 * Data must be all numeric
59 *
60 */
61 if ((pos = strspn(data, "0123456789")) != len) {
62 if (err_pos) *err_pos = pos;
63 if (err_len) *err_len = 1;
65 }
66
67 /*
68 * Data must contain a non-zero digit
69 *
70 */
71 if (strspn(data, "0") >= len) {
72 if (err_pos) *err_pos = 0;
73 if (err_len) *err_len = len;
75 }
76
77 return GS1_LINTER_OK;
78
79}
@ GS1_LINTER_ILLEGAL_ZERO_VALUE
A non-zero value is required.
Definition gs1syntaxdictionary.h:81
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition gs1syntaxdictionary.h:66
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition gs1syntaxdictionary.h:67