Used to validate that an AI component is an ISO 3166 "num-3" country code.
78{
79
80
81
82
83
84#ifdef GS1_LINTER_CUSTOM_ISO3166_LOOKUP
85#define GS1_LINTER_ISO3166_LOOKUP(cc, cc_len, valid) GS1_LINTER_CUSTOM_ISO3166_LOOKUP(cc, cc_len, valid)
86#else
87
88
89
90
91
92
93
94
95
96
97
98 static const uint64_t iso3166[] = {
99#if __STDC_VERSION__ >= 202311L
100 0b0000100010101000100010001000100110001000100010001011100010001000,
101 0b1000101010101000000010100010100010001000100010001000100010001000,
102 0b0000100010001000100010001000101000100010001000110010100010001001,
103 0b1000100000011000100010100010001000100001111000110010001010100010,
104 0b0010101000101010000110000000000010001000100010001000100010001000,
105 0b1000100010001010100010001000100010001000100010001000100010001000,
106 0b1000100010000010100010001010001001100010001010100010001010100010,
107 0b0010001000100010001000100010001010001000000010001011100010001000,
108 0b1000100010001000100101110000100000001000001000100010001000100010,
109 0b0010110111100001000000101000100010001000100010001010001000100010,
110 0b0011001000001010000110110010001000100010001000101010001000000011,
111 0b1110001000001000000010001100100000001000100010001000100010101000,
112 0b1000100010001000100010001001101010001001000000000010000000100001,
113 0b1110000010000000001000100010101000000000000010000010000100000010,
114 0b0000000000000000000000000000000000000000000000000000000000000000,
115 0b0000000000000000000000000000000000000000000000000000000000000000,
116#else
117
118
119
120
121
122
123
124
125 0x08a888898888b888, 0x8aa80a2888888888, 0x0888888a22232889, 0x88188a2221e322a2,
126 0x2a2a180088888888, 0x888a888888888888, 0x888288a2622a22a2, 0x222222228808b888,
127 0x8888970808222222, 0x2de102888888a222, 0x320a1b222222a203, 0xe20808c8088888a8,
128 0x8888889a89002021, 0xe080222a00082102, 0x0000000000000000, 0x0000000000000000,
129#endif
130 };
131
132
133#define GS1_LINTER_ISO3166_LOOKUP(cc, cc_len, valid) do { \
134 valid = 0; \
135 if (cc_len == 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, iso3166, valid); \
138 } \
139} while (0)
140
141
142#endif
143
144 int valid;
145
146 assert(data);
147
148
149
150
151
152
153 GS1_LINTER_ISO3166_LOOKUP(data, data_len, valid);
156
157
158
159
160
163 0,
164 data_len
165 );
166
167}
#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_NOT_ISO3166
A valid ISO 3166 three-digit country code is required.
Definition gs1syntaxdictionary.h:97