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

Purpose

The packagetype linter ensures that the data represents a valid UN/ECE Recommendation 21 alphanumeric code, extended with additional GS1 code values.

Remarks
The set of valid codes is maintained by GS1 in the PackageTypeCode code list.

Functional Description

◆ gs1_lint_packagetype()

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

Used to validate that an AI component is a valid package type as defined by the PackageTypeCode code list.

Note
The default lookup function provided by this linter is a binary search over a static list this is maintained in this file.
To enable this linter to hook into an alternative PackageTypeCode lookup function (provided by the user) the GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP_H macro may be set to the name of a header file to be included that defines a custom GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP macro.
If provided, the GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP macro shall invoke whatever functionality is available in the user-provided lookup function using the first and second arguments, then using the result must assign to third (output) argument as follows:
  • valid: Set to 1 if the lookup was successful. Otherwise 0.
Parameters
[in]dataPointer to the data to be linted. Must not be NULL.
[in]data_lenLength of the data to be linted.
[in]data_lenLength of the data parameter.
[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_INVALID_PACKAGE_TYPE if the data is not a valid PackageTypeCode.
81{
82
83 /*
84 * Allow for a custom replacement of the lookup code to be provided.
85 *
86 */
87#ifdef GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP
88#define GS1_LINTER_PACKAGE_TYPE_LOOKUP(cc, cc_len, valid) GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP(cc, cc_len, valid)
89#else
90
91 /*
92 * Set of valid PackageTypeCode value, in lexicographic order
93 *
94 * MAINTENANCE NOTE:
95 *
96 * Updates must be aligned with the PackageTypeCode code list
97 *
98 */
99 static const char packagetypes[][4] = {
100 "1A", "1B", "1D", "1F", "1G", "1W",
101 "200", "201", "202", "203", "204", "205", "206", "210", "211", "212", "2C",
102 "3A", "3H",
103 "43", "44", "4A", "4B", "4C", "4D", "4F", "4G", "4H",
104 "5H", "5L", "5M",
105 "6H", "6P",
106 "7A", "7B",
107 "8", "8A", "8B", "8C",
108 "9",
109 "AA", "AB", "AC", "AD", "AF", "AG", "AH", "AI", "AJ", "AL", "AM", "AP", "APE","AT", "AV",
110 "B4", "BB", "BC", "BD", "BE", "BF", "BG", "BGE", "BH", "BI", "BJ", "BK", "BL", "BM", "BME", "BN", "BO", "BP", "BQ", "BR", "BRI", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "BZ",
111 "CA", "CB", "CBL", "CC", "CCE", "CD", "CE", "CF", "CG", "CH", "CI", "CJ", "CK", "CL", "CM", "CN", "CO", "CP", "CQ", "CR", "CS", "CT", "CU", "CV", "CW", "CX", "CY", "CZ",
112 "DA", "DB", "DC", "DG", "DH", "DI", "DJ", "DK", "DL", "DM", "DN", "DP", "DPE", "DR", "DS", "DT", "DU", "DV", "DW", "DX", "DY",
113 "E1", "E2", "E3", "EC", "ED", "EE", "EF", "EG", "EH", "EI", "EN",
114 "FB", "FC", "FD", "FE", "FI", "FL", "FO", "FOB", "FP", "FPE", "FR", "FT", "FW", "FX",
115 "GB", "GI", "GL", "GR", "GU", "GY", "GZ",
116 "HA", "HB", "HC", "HG", "HN", "HR",
117 "IA", "IB", "IC", "ID", "IE", "IF", "IG", "IH", "IK", "IL", "IN", "IZ",
118 "JB", "JC", "JG", "JR", "JT", "JY",
119 "KG", "KI",
120 "LAB", "LE", "LG", "LT", "LU", "LV", "LZ",
121 "MA", "MB", "MC", "ME", "MPE", "MR", "MS", "MT", "MW", "MX",
122 "NA", "NE", "NF", "NG", "NS", "NT", "NU", "NV",
123 "OA", "OB", "OC", "OD", "OE", "OF", "OK", "OPE", "OT", "OU",
124 "P2", "PA", "PAE", "PB", "PC", "PD", "PE", "PF", "PG", "PH", "PI", "PJ", "PK", "PL", "PLP", "PN", "PO", "POP", "PP", "PPE", "PR", "PT", "PU", "PUE", "PV", "PX", "PY", "PZ",
125 "QA", "QB", "QC", "QD", "QF", "QG", "QH", "QJ", "QK", "QL", "QM", "QN", "QP", "QQ", "QR", "QS",
126 "RB1", "RB2", "RB3", "RCB", "RD", "RG", "RJ", "RK", "RL", "RO", "RT", "RZ",
127 "S1", "SA", "SB", "SC", "SD", "SE", "SEC", "SH", "SI", "SK", "SL", "SM", "SO", "SP", "SS", "ST", "STL", "SU", "SV", "SW", "SX", "SY", "SZ",
128 "T1", "TB", "TC", "TD", "TE", "TEV", "TG", "THE", "TI", "TK", "TL", "TN", "TO", "TR", "TRE", "TS", "TT", "TTE", "TU", "TV", "TW", "TWE", "TY", "TZ",
129 "UC", "UN", "UUE",
130 "VA", "VG", "VI", "VK", "VL", "VN", "VO", "VP", "VQ", "VR", "VS", "VY",
131 "WA", "WB", "WC", "WD", "WF", "WG", "WH", "WJ", "WK", "WL", "WM", "WN", "WP", "WQ", "WR", "WRP", "WS", "WT", "WU", "WV", "WW", "WX", "WY", "WZ",
132 "X11", "X12", "X15", "X16", "X17", "X18", "X19", "X20", "X3", "XA", "XB", "XC", "XD", "XF", "XG", "XH", "XJ", "XK",
133 "YA", "YB", "YC", "YD", "YF", "YG", "YH", "YJ", "YK", "YL", "YM", "YN", "YP", "YQ", "YR", "YS", "YT", "YV", "YW", "YX", "YY", "YZ",
134 "ZA", "ZB", "ZC", "ZD", "ZF", "ZG", "ZH", "ZJ", "ZK", "ZL", "ZM", "ZN", "ZP", "ZQ", "ZR", "ZS", "ZT", "ZU", "ZV", "ZW", "ZX", "ZY", "ZZ",
135 };
136
137/// \cond
138#define GS1_LINTER_PACKAGE_TYPE_LOOKUP(cc, cc_len, valid) GS1_LINTER_BINARY_SEARCH(cc, cc_len, packagetypes, valid)
139/// \endcond
140
141#endif
142
143 int valid;
144
145 assert(data);
146
147
148 /*
149 * Ensure that the data is in the list.
150 *
151 */
152 GS1_LINTER_PACKAGE_TYPE_LOOKUP(data, data_len, valid);
153 if (GS1_LINTER_LIKELY(valid))
155
156 /*
157 * If not valid then indicate an error.
158 *
159 */
162 0,
163 data_len
164 );
165
166}
#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
#define GS1_LINTER_LIKELY(x)
Implementation may provide hint to the compiler that the expression is likely to be true.
Definition gs1syntaxdictionary-utils.h:63
@ GS1_LINTER_INVALID_PACKAGE_TYPE
A valid PackageTypeCode is required.
Definition gs1syntaxdictionary.h:198