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

Purpose

The yymmddhh linter ensures that the data represents a meaningful date and hour of day, in YYMMDDHH format.

Functional Description

◆ gs1_lint_yymmddhh()

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

Used to ensure that an AI component conforms to the YYMMDDHH format.

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_DATE_WITH_HOUR_TOO_SHORT if the data is too short for YYMMDDHH format.
GS1_LINTER_DATE_WITH_HOUR_TOO_LONG if the data is too long for YYMMDDHH format.
GS1_LINTER_NON_DIGIT_CHARACTER if the data contains a non-digit character.
GS1_LINTER_ILLEGAL_MONTH if the data contains an invalid month.
GS1_LINTER_ILLEGAL_DAY if the data contains an invalid day of the month.
GS1_LINTER_ILLEGAL_HOUR if the data contains an illegal hour.
55{
56
57 char yymmdd[7] = {0};
58 size_t pos, len;
60
61 assert(data);
62
63 len = strlen(data);
64
65 /*
66 * Data must be eight characters.
67 *
68 */
69 if (len != 8) {
70 if (err_pos) *err_pos = 0;
71 if (err_len) *err_len = len;
72 return len < 8 ?
75 }
76
77 /*
78 * Data must consist of all digits.
79 *
80 */
81 if ((pos = strspn(data, "0123456789")) != len) {
82 if (err_pos) *err_pos = pos;
83 if (err_len) *err_len = 1;
85 }
86
87 /*
88 * Validate the date component.
89 *
90 */
91 memcpy(yymmdd, data, 6);
92 ret = gs1_lint_yymmdd(yymmdd, err_pos, err_len);
93
94 assert(ret == GS1_LINTER_OK ||
100
101 if (ret != GS1_LINTER_OK)
102 return ret;
103
104 /*
105 * Validate the hour component.
106 *
107 */
108 if ((data[6] - '0') * 10 + (data[7] - '0') > 23) {
109 if (err_pos) *err_pos = 6;
110 if (err_len) *err_len = 2;
112 }
113
114 return GS1_LINTER_OK;
115
116}
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yymmdd(const char *data, size_t *err_pos, size_t *err_len)
Definition lint_yymmdd.c:52
gs1_lint_err_t
Linter return codes other than GS1_LINTER_OK indicate an error condition.
Definition gs1syntaxdictionary.h:65
@ GS1_LINTER_ILLEGAL_DAY
The date contains an illegal day of the month.
Definition gs1syntaxdictionary.h:102
@ GS1_LINTER_DATE_WITH_HOUR_TOO_SHORT
The date with hour is too short for YYMMDDHH format.
Definition gs1syntaxdictionary.h:96
@ GS1_LINTER_DATE_TOO_LONG
The date is too long for YYMMDD format.
Definition gs1syntaxdictionary.h:95
@ GS1_LINTER_DATE_WITH_HOUR_TOO_LONG
The date with hour is too long for YYMMDDHH format.
Definition gs1syntaxdictionary.h:97
@ GS1_LINTER_ILLEGAL_MONTH
The date contains an illegal month of the year.
Definition gs1syntaxdictionary.h:101
@ GS1_LINTER_ILLEGAL_HOUR
The time contains an illegal hour.
Definition gs1syntaxdictionary.h:103
@ GS1_LINTER_DATE_TOO_SHORT
The date is too short for YYMMDD format.
Definition gs1syntaxdictionary.h:94
@ 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