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_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
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 uint64_t iso4217[] = {
100#if __STDC_VERSION__ >= 202311L
101 0b0000000010001000000000000000000010001000000010001011100000001000, // 000-063: 008 012 032 036 044 048 050-052 060
102 0b1000100010000000000010000010000010000000100010000000100000001000, // 064-127: 064 068 072 084 090 096 104 108 116 124
103 0b0000100010000000100000001000100000000000001000100000000000001001, // 128-191: 132 136 144 152 156 170 174 188 191-192
104 0b1000000000010000100000100000001000000010100000100010000000000000, // 192-255: 192 203 208 214 222 230 232 238 242
105 0b0000001000000010000000000000000000001000000000000000000000000000, // 256-319: 262 270 292
106 0b1000100010001000000010001000100010001000100010001000000010000000, // 320-383: 320 324 328 332 340 344 348 352 356 360 364 368 376
107 0b0000100010000010100010001010001001100010001000100010000000000010, // 384-447: 388 392 398 400 404 408 410 414 417-418 422 426 430 434 446
108 0b0000001000100010000000000000000010001000000000001010000010000000, // 448-511: 454 458 462 480 484 496 498 504
109 0b1000100000001000000011000000000000001000001000100000001000000000, // 512-575: 512 516 524 532-533 548 554 558 566
110 0b0010000000100010000000101000100010000000000000000000000000100000, // 576-639: 578 586 590 598 600 604 608 634
111 0b0001001000000010000000000000000000000000001000000010001000000010, // 640-703: 643 646 654 682 690 694 702
112 0b1010001000000000000000001000000000000000000010001000100010001000, // 704-767: 704 706 710 728 748 752 756 760 764
113 0b0000000010001000100010000000000010000001000000000010000000100000, // 768-831: 776 780 784 788 800 807 818 826
114 0b0010000010000000000000000010100000000000000000000010001000000000, // 832-895: 834 840 858 860 882 886
115 0b0000010000000000000000000000110111111110101011011011111111011111, // 896-959: 901 924-925 927-934 936 938 940-941 943-944 946-953 955-959
116 0b1111110111111101111111001110001000100101000000000000000000000000, // 960-999: 960-965 967-973 975-981 984-986 990 994 997 999
117#else
118 /*
119 * Fallback for compilers lacking binary literal support.
120 *
121 * Generated from the above data with:
122 *
123 * for (size_t i = 0; i < sizeof(iso4217) / sizeof(iso4217[0]); i++) { printf("%lx ", iso4217[i]); };
124 *
125 */
126 0x008800008808b808, 0x8880082080880808, 0x0880808800220009, 0x8010820202822000,
127 0x0202000008000000, 0x8888088888888080, 0x088288a262222002, 0x022200008800a080,
128 0x88080c0008220200, 0x2022028880000020, 0x1202000000202202, 0xa200008000088888,
129 0x0088880081002020, 0x2080002800002200, 0x0400000dfeadbfdf, 0xfdfdfce225000000,
130#endif
131 };
132
133/// \cond
134#define GS1_LINTER_ISO4217_LOOKUP(cc) do { \
135 if (strlen(cc) == 3 && isdigit(cc[0]) && isdigit(cc[1]) && isdigit(cc[2])) { \
136 int v = (cc[0] - '0') * 100 + (cc[1] - '0') * 10 + cc[2] - '0'; \
137 GS1_LINTER_BITFIELD_LOOKUP(v, iso4217); \
138 } \
139} while (0)
140/// \endcond
141
142#endif
143
144 int valid = 0;
145
146 assert(data);
147
148 /*
149 * Ensure that the data is in the list.
150 *
151 */
152 GS1_LINTER_ISO4217_LOOKUP(data);
153 if (valid)
155
156 /*
157 * If not valid then indicate an error.
158 *
159 */
162 0,
163 strlen(data)
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: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_NOT_ISO4217
A valid ISO 4217 three-digit currency code is required.
Definition gs1syntaxdictionary.h:100