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

Purpose

The nozeroprefix linter ensures that the given data does not start with a zero.

Functional Description

◆ gs1_lint_nozeroprefix()

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

Used to validate that a numeric AI component does not start with zero.

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_PREFIX if the data starts with zero.
GS1_LINTER_NON_DIGIT_CHARACTER if the data contains non-digit characters.
48{
49
50 size_t pos;
51
52 assert(data);
53
54 /*
55 * Data must be all numeric
56 *
57 */
58 if ((pos = strspn(data, "0123456789")) != strlen(data)) {
59 if (err_pos) *err_pos = pos;
60 if (err_len) *err_len = 1;
62 }
63
64 /*
65 * Data must not start with a zero
66 *
67 */
68 if (*data == '0') {
69 if (err_pos) *err_pos = 0;
70 if (err_len) *err_len = 1;
72 }
73
74 return GS1_LINTER_OK;
75
76}
@ GS1_LINTER_ILLEGAL_ZERO_PREFIX
A zero prefix is not permitted.
Definition gs1syntaxdictionary.h:83
@ 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