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

Purpose

The couponposoffer linter ensures that the data conforms to the modernised North American positive offer file coupon code standard, as carried in AI (8112).

Remarks
Refer to the document "GS1 AI (8112) Coupon Data Specification" for a description of the positive offer file coupon code data contents.

Functional Description

◆ gs1_lint_couponposoffer()

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

Used to ensure that an AI component conforms to the modernised North American positive offer file coupon code standard, as carried in AI (8112).

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_COUPON_MISSING_FORMAT_CODE if the data is missing a Format Code.
GS1_LINTER_COUPON_INVALID_FORMAT_CODE if the data contains an invalid Format Code, neither "0" or "1".
GS1_LINTER_COUPON_MISSING_FUNDER_VLI if the data is missing a Funder ID length indicator.
GS1_LINTER_COUPON_INVALID_FUNDER_LENGTH if the data contains a Funder ID length indicator that is not within the range "0" to "6".
GS1_LINTER_COUPON_TRUNCATED_FUNDER if the data contains a Funder ID is that is shorter than specified by its length indicator.
GS1_LINTER_COUPON_TRUNCATED_OFFER_CODE if the data contains an Offer Code that is shorter than six digits.
GS1_LINTER_COUPON_MISSING_SERIAL_NUMBER_VLI if the data is missing a Serial Number length indicator.
GS1_LINTER_COUPON_TRUNCATED_SERIAL_NUMBER if the data contains a Serial Number that is shorter than specified by its length indicator.
GS1_LINTER_COUPON_EXCESS_DATA if the data contains excess data following the Serial Number.
72{
73
74 size_t pos;
75 int vli;
76 const char *p, *q;
77
78 assert(data);
79
80
81 /*
82 * Data must consist of all digits.
83 *
84 */
85 if ((pos = strspn(data, "0123456789")) != strlen(data)) {
86 if (err_pos) *err_pos = pos;
87 if (err_len) *err_len = 1;
89 }
90
91 p = data;
92 q = data + strlen(data);
93
94
95 /*
96 * Validate the Format ID.
97 *
98 * Valid Format IDs are "0" and "1".
99 *
100 */
101 if (p == q) {
102 if (err_pos) *err_pos = 0;
103 if (err_len) *err_len = (size_t)(q - data);
105 }
106
107 if (*p != '0' && *p != '1') {
108 if (err_pos) *err_pos = (size_t)(p - data);
109 if (err_len) *err_len = 1;
111 }
112
113
114 /*
115 * Validate the Funder VLI is in the range "0" to "6" and that the
116 * following Funder ID has the corresponding length (plus 6).
117 *
118 */
119 if (++p == q) {
120 if (err_pos) *err_pos = 0;
121 if (err_len) *err_len = (size_t)(q - data);
123 }
124 if (*p > '6') {
125 if (err_pos) *err_pos = (size_t)(p - data);
126 if (err_len) *err_len = 1;
128 }
129 vli = *p - '0' + 6;
130
131 if (q - ++p < vli) {
132 if (err_pos) *err_pos = (p == q) ? 0 : (size_t)(p - data);
133 if (err_len) *err_len = (p == q) ? (size_t)(q - data) : (size_t)(q - p);
135 }
136
137 p += vli;
138
139
140 /*
141 * Validate the existence of the six digit Offer Code.
142 *
143 */
144 if (q - p < 6) {
145 if (err_pos) *err_pos = (p == q) ? 0 : (size_t)(p - data);
146 if (err_len) *err_len = (p == q) ? (size_t)(q - data) : (size_t)(q - p);
148 }
149
150 p += 6;
151
152
153 /*
154 * Validate that the Serial Number follows its VLI and has the
155 * corresponding length (plus 6).
156 *
157 */
158 if (p == q) {
159 if (err_pos) *err_pos = 0;
160 if (err_len) *err_len = (size_t)(q - data);
162 }
163 vli = *p - '0' + 6;
164
165 if (q - ++p < vli) {
166 if (err_pos) *err_pos = (p == q) ? 0 : (size_t)(p - data);
167 if (err_len) *err_len = (p == q) ? (size_t)(q - data) : (size_t)(q - p);
169 }
170
171 p += vli;
172
173
174 /*
175 * Report any excess data that follows the Serial Number.
176 *
177 */
178 if (p != q) {
179 if (err_pos) *err_pos = (size_t)(p - data);
180 if (err_len) *err_len = (size_t)(q - p);
182 }
183
184 return GS1_LINTER_OK;
185
186}
@ GS1_LINTER_COUPON_MISSING_FORMAT_CODE
The coupon's Format Code is missing.
Definition gs1syntaxdictionary.h:111
@ GS1_LINTER_COUPON_INVALID_FORMAT_CODE
The coupon's Format Code must be "0" or "1".
Definition gs1syntaxdictionary.h:112
@ GS1_LINTER_COUPON_MISSING_SERIAL_NUMBER_VLI
The coupon's Serial Number VLI is missing.
Definition gs1syntaxdictionary.h:117
@ GS1_LINTER_COUPON_TRUNCATED_SERIAL_NUMBER
The coupon's Serial Number is shorter than what is indicated by its VLI.
Definition gs1syntaxdictionary.h:118
@ GS1_LINTER_COUPON_MISSING_FUNDER_VLI
The coupon's Funder VLI is missing.
Definition gs1syntaxdictionary.h:113
@ GS1_LINTER_COUPON_TRUNCATED_OFFER_CODE
The coupon's Offer Code is shorter than the required six digits.
Definition gs1syntaxdictionary.h:116
@ GS1_LINTER_COUPON_EXCESS_DATA
The coupon contains excess data after the recognised optional fields.
Definition gs1syntaxdictionary.h:166
@ GS1_LINTER_COUPON_INVALID_FUNDER_LENGTH
The coupon's Funder VLI must be "0" to "6".
Definition gs1syntaxdictionary.h:114
@ 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
@ GS1_LINTER_COUPON_TRUNCATED_FUNDER
The coupon's Funder is shorter than what is indicated by its VLI.
Definition gs1syntaxdictionary.h:115