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

Purpose

The ss linter ensures that the given data is a meaningful second number in a minute.

Functional Description

◆ gs1_lint_ss()

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

Used to ensure that an AI component conforms to SS format for seconds within a minute.

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_SECOND_TOO_SHORT if the data is too short for MM format.
GS1_LINTER_SECOND_TOO_LONG if the data is too long for MM format.
GS1_LINTER_NON_DIGIT_CHARACTER if the data contains a non-digit character.
GS1_LINTER_ILLEGAL_SECOND if the data contains an invalid second.
55{
56
57 int pos;
58
59 assert(data);
60
61 /*
62 * Data must be exactly two characters.
63 *
64 */
65 if (GS1_LINTER_UNLIKELY(!data[0] || !data[1]))
68 0,
69 data[0] ? 1 : 0
70 );
71
72 if (GS1_LINTER_UNLIKELY(data[2] != '\0'))
75 0,
76 strlen(data)
77 );
78
79 /*
80 * Data must consist of all digits.
81 */
82 for (pos = 0; pos < 2; pos++)
83 if (GS1_LINTER_UNLIKELY(data[pos] < '0' || data[pos] > '9'))
86 (size_t)pos,
87 1
88 );
89
90 /*
91 * Validate the second (00-59).
92 */
93 if (GS1_LINTER_UNLIKELY((data[0] - '0') * 10 + (data[1] - '0') > 59))
96 0,
97 2
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
@ GS1_LINTER_SECOND_TOO_SHORT
The second is too short for SS format.
Definition gs1syntaxdictionary.h:196
@ GS1_LINTER_SECOND_TOO_LONG
The second is too long for SS format.
Definition gs1syntaxdictionary.h:197
@ GS1_LINTER_ILLEGAL_SECOND
The time contains an illegal seconds.
Definition gs1syntaxdictionary.h:117
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition gs1syntaxdictionary.h:78