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