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 *  data,
size_t *  err_pos,
size_t *  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, then using the result must assign to a locally-scoped variable as follows:
  • valid: Set to 1 if the lookup was successful. Otherwise 0.
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_INVALID_PACKAGE_TYPE if the data is not a valid PackageTypeCode.
80{
81
82 /*
83 * Allow for a custom replacement of the lookup code to be provided.
84 *
85 */
86#ifdef GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP
87#define GS1_LINTER_PACKAGE_TYPE_LOOKUP(cc) GS1_LINTER_CUSTOM_PACKAGE_TYPE_LOOKUP(cc)
88#else
89
90 /*
91 * Set of valid PackageTypeCode value, in lexicographic order
92 *
93 * MAINTENANCE NOTE:
94 *
95 * Updates must be aligned with the PackageTypeCode code list
96 *
97 */
98 static const char packagetypes[][4] = {
99 "1A", "1B", "1D", "1F", "1G", "1W",
100 "200", "201", "202", "203", "204", "205", "206", "210", "211", "212", "2C",
101 "3A", "3H",
102 "43", "44", "4A", "4B", "4C", "4D", "4F", "4G", "4H",
103 "5H", "5L", "5M",
104 "6H", "6P",
105 "7A", "7B",
106 "8", "8A", "8B", "8C",
107 "9",
108 "AA", "AB", "AC", "AD", "AF", "AG", "AH", "AI", "AJ", "AL", "AM", "AP", "APE","AT", "AV",
109 "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",
110 "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",
111 "DA", "DB", "DC", "DG", "DH", "DI", "DJ", "DK", "DL", "DM", "DN", "DP", "DPE", "DR", "DS", "DT", "DU", "DV", "DW", "DX", "DY",
112 "E1", "E2", "E3", "EC", "ED", "EE", "EF", "EG", "EH", "EI", "EN",
113 "FB", "FC", "FD", "FE", "FI", "FL", "FO", "FOB", "FP", "FPE", "FR", "FT", "FW", "FX",
114 "GB", "GI", "GL", "GR", "GU", "GY", "GZ",
115 "HA", "HB", "HC", "HG", "HN", "HR",
116 "IA", "IB", "IC", "ID", "IE", "IF", "IG", "IH", "IK", "IL", "IN", "IZ",
117 "JB", "JC", "JG", "JR", "JT", "JY",
118 "KG", "KI",
119 "LAB", "LE", "LG", "LT", "LU", "LV", "LZ",
120 "MA", "MB", "MC", "ME", "MPE", "MR", "MS", "MT", "MW", "MX",
121 "NA", "NE", "NF", "NG", "NS", "NT", "NU", "NV",
122 "OA", "OB", "OC", "OD", "OE", "OF", "OK", "OPE", "OT", "OU",
123 "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",
124 "QA", "QB", "QC", "QD", "QF", "QG", "QH", "QJ", "QK", "QL", "QM", "QN", "QP", "QQ", "QR", "QS",
125 "RB1", "RB2", "RB3", "RCB", "RD", "RG", "RJ", "RK", "RL", "RO", "RT", "RZ",
126 "S1", "SA", "SB", "SC", "SD", "SE", "SEC", "SH", "SI", "SK", "SL", "SM", "SO", "SP", "SS", "ST", "STL", "SU", "SV", "SW", "SX", "SY", "SZ",
127 "T1", "TB", "TC", "TD", "TE", "TEV", "TG", "THE", "TI", "TK", "TL", "TN", "TO", "TR", "TRE", "TS", "TT", "TTE", "TU", "TV", "TW", "TWE", "TY", "TZ",
128 "UC", "UN", "UUE",
129 "VA", "VG", "VI", "VK", "VL", "VN", "VO", "VP", "VQ", "VR", "VS", "VY",
130 "WA", "WB", "WC", "WD", "WF", "WG", "WH", "WJ", "WK", "WL", "WM", "WN", "WP", "WQ", "WR", "WRP", "WS", "WT", "WU", "WV", "WW", "WX", "WY", "WZ",
131 "X11", "X12", "X15", "X16", "X17", "X18", "X19", "X20", "X3", "XA", "XB", "XC", "XD", "XF", "XG", "XH", "XJ", "XK",
132 "YA", "YB", "YC", "YD", "YF", "YG", "YH", "YJ", "YK", "YL", "YM", "YN", "YP", "YQ", "YR", "YS", "YT", "YV", "YW", "YX", "YY", "YZ",
133 "ZA", "ZB", "ZC", "ZD", "ZF", "ZG", "ZH", "ZJ", "ZK", "ZL", "ZM", "ZN", "ZP", "ZQ", "ZR", "ZS", "ZT", "ZU", "ZV", "ZW", "ZX", "ZY", "ZZ",
134 };
135
136/// \cond
137#define GS1_LINTER_PACKAGE_TYPE_LOOKUP(cc) GS1_LINTER_BINARY_SEARCH(cc, packagetypes)
138/// \endcond
139
140#endif
141
142 int valid = 0;
143
144 assert(data);
145
146 /*
147 * Ensure that the data is in the list.
148 *
149 */
150 GS1_LINTER_PACKAGE_TYPE_LOOKUP(data);
151 if (valid)
153
154 /*
155 * If not valid then indicate an error.
156 *
157 */
160 0,
161 strlen(data)
162 );
163
164}
#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_INVALID_PACKAGE_TYPE
A valid PackageTypeCode is required.
Definition gs1syntaxdictionary.h:198