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

Purpose

The hh linter ensures that the given data is a meaningful hour number in a day.

Functional Description

◆ gs1_lint_hh()

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

Used to ensure that an AI component conforms to HH format for hours within a day.

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_HOUR_TOO_SHORT if the data is too short for HH format.
GS1_LINTER_HOUR_TOO_LONG if the data is too long for HH format.
GS1_LINTER_NON_DIGIT_CHARACTER if the data contains a non-digit character.
GS1_LINTER_ILLEGAL_HOUR if the data contains an invalid hour.
55{
56
57 size_t len, pos;
58
59 assert(data);
60
61 len = strlen(data);
62
63 /*
64 * Data must be two characters.
65 *
66 */
67 if (len != 2)
70 0,
71 len
72 );
73
74 /*
75 * Data must consist of all digits.
76 *
77 */
78 if ((pos = strspn(data, "0123456789")) != len)
81 pos,
82 1
83 );
84
85 /*
86 * Validate the minute.
87 *
88 */
89 if ((data[0] - '0') * 10 + (data[1] - '0') > 23)
92 0,
93 2
94 );
95
97
98}
#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:77
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:62
@ GS1_LINTER_HOUR_TOO_SHORT
The hour is too short for HH format.
Definition gs1syntaxdictionary.h:192
@ GS1_LINTER_HOUR_TOO_LONG
The hour is too long for HH format.
Definition gs1syntaxdictionary.h:193
@ GS1_LINTER_ILLEGAL_HOUR
The time contains an illegal hour.
Definition gs1syntaxdictionary.h:115
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition gs1syntaxdictionary.h:78