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

Purpose

The iso4217 linter ensures that the data is in the list of ISO 4217 three-digit currency codes.

Remarks
The three-digit currency codes are defined by ISO 4217: Codes for the representation of currencies.

Functional Description

◆ gs1_lint_iso4217()

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

Used to validate that an AI component is an ISO 4217 three-digit currency code.

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 ISO 4217 lookup function (provided by the user) the GS1_LINTER_CUSTOM_ISO4217_LOOKUP_H macro may be set to the name of a header file to be included that defines a custom GS1_LINTER_CUSTOM_ISO4217_LOOKUP macro.
If provided, the GS1_LINTER_CUSTOM_ISO4217_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_NOT_ISO4217 if the data is not a valid three-digit currency code.
78{
79
80 /*
81 * Allow for a custom replacement of the lookup code to be provided.
82 *
83 */
84#ifdef GS1_LINTER_CUSTOM_ISO4217_LOOKUP
85#define GS1_LINTER_ISO4217_LOOKUP(cc) GS1_LINTER_CUSTOM_ISO4217_LOOKUP(cc)
86#else
87
88 /*
89 * Set of ISO 4217 three-digit currency codes
90 *
91 * MAINTENANCE NOTE:
92 *
93 * Updates to the ISO 4217 three-digit currency code list are provided
94 * here:
95 *
96 * https://www.six-group.com/en/products-services/financial-information/data-standards.html
97 *
98 */
99 static const char iso4217[][4] = {
100 "008", "012", "032", "036", "044", "048",
101 "050", "051", "052", "060", "064", "068", "072", "084", "090", "096",
102 "104", "108", "116", "124", "132", "136", "144",
103 "152", "156", "170", "174", "188", "191", "192",
104 "203", "208", "214", "222", "230", "232", "238", "242", "262", "270", "292",
105 "320", "324", "328", "332", "340", "344", "348",
106 "352", "356", "360", "364", "368", "376", "388", "392", "398",
107 "400", "404", "408", "410", "414", "417", "418",
108 "422", "426", "430", "434", "446",
109 "454", "458", "462", "480", "484", "496", "498",
110 "504", "512", "516", "524", "532", "533", "548",
111 "554", "558", "566", "578", "586", "590", "598",
112 "600", "604", "608", "634", "643", "646", "654", "682", "690", "694",
113 "702", "704", "706", "710", "728", "748",
114 "752", "756", "760", "764", "776", "780", "784", "788",
115 "800", "807", "818", "826", "834", "840", "858", "860", "882", "886",
116 "901", "925", "927", "928", "929", "930", "931", "932", "933", "934", "936", "938",
117 "940", "941", "943", "944", "946", "947", "948", "949",
118 "950", "951", "952", "953", "955", "956", "957", "958", "959",
119 "960", "961", "962", "963", "964", "965", "967", "968", "969",
120 "970", "971", "972", "973", "975", "976", "977", "978", "979",
121 "980", "981", "984", "985", "986", "990", "994", "997", "999",
122 };
123
124 /*
125 * Binary search over the above list.
126 *
127 */
128/// \cond
129#define GS1_LINTER_ISO4217_LOOKUP(cc) do { \
130 size_t s = 0; \
131 size_t e = sizeof(iso4217) / sizeof(iso4217[0]); \
132 while (s < e) { \
133 const size_t m = s + (e - s) / 2; \
134 const int cmp = strcmp(iso4217[m], cc); \
135 if (cmp < 0) \
136 s = m + 1; \
137 else if (cmp > 0) \
138 e = m; \
139 else { \
140 valid = 1; \
141 break; \
142 } \
143 } \
144} while (0)
145/// \endcond
146
147#endif
148
149 int valid = 0;
150
151 assert(data);
152
153 /*
154 * Ensure that the data is in the list.
155 *
156 */
157 GS1_LINTER_ISO4217_LOOKUP(data);
158 if (valid)
159 return GS1_LINTER_OK;
160
161 /*
162 * If not valid then indicate an error.
163 *
164 */
165 if (err_pos) *err_pos = 0;
166 if (err_len) *err_len = strlen(data);
168
169}
@ GS1_LINTER_NOT_ISO4217
A valid ISO 4217 three-digit currency code is required.
Definition gs1syntaxdictionary.h:89
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition gs1syntaxdictionary.h:66