Used to validate that an AI component is an ISO 3166 "alpha-2" country code.
77{
78
79
80
81
82
83#ifdef GS1_LINTER_CUSTOM_ISO3166ALPHA2_LOOKUP
84#define GS1_LINTER_ISO3166ALPHA2_LOOKUP(cc, cc_len, valid) GS1_LINTER_CUSTOM_ISO3166ALPHA2_LOOKUP(cc, cc_len, valid)
85#else
86
87
88
89
90
91
92
93
94
95
96
97 static const uint64_t iso3166alpha2[] = {
98#if __STDC_VERSION__ >= 202311L
99 0b0001111010011010111110110111011111110111101111011011101101111011,
100 0b1110010011111100001000011010100000000001001010110000000001110000,
101 0b0000000000111010100100000000110111111001110111111010100000000000,
102 0b1011000101100000000110000001111011110000000000100000001011000000,
103 0b0000000010111000110101000010111110000010100000011111001010111111,
104 0b0011111111111111111010111010010011010010000100000000000010000000,
105 0b0000001000111100111100011100101010000000000000000000000000000010,
106 0b0000000010001010100011111011111111100111010111001101110111111001,
107 0b0101100110000010000010000010000011101010101000010000001000000000,
108 0b0100000000000010000000000000000000000000000000000000100000000000,
109 0b0001000000100000000000100000000010000000000000000000000000000000,
110#else
111
112
113
114
115
116
117
118
119 0x1e9afb77f7bdbb7b, 0xe4fc21a8012b0070, 0x003a900df9dfa800, 0xb160181ef00202c0,
120 0x00b8d42f8281f2bf, 0x3fffeba4d2100080, 0x023cf1ca80000002, 0x008a8fbfe75cddf9,
121 0x59820820eaa10200, 0x4002000000000800, 0x1020020080000000
122#endif
123 };
124
125
126#define GS1_LINTER_ISO3166ALPHA2_LOOKUP(cc, cc_len, valid) do { \
127 valid = 0; \
128 if (cc_len == 2 && cc[0] >= 'A' && cc[0] <= 'Z' && cc[1] >= 'A' && cc[1] <= 'Z') { \
129 int v = (cc[0] - 'A') * 26 + cc[1] - 'A'; \
130 GS1_LINTER_BITFIELD_LOOKUP(v, iso3166alpha2, valid); \
131 } \
132} while (0)
133
134
135#endif
136
137 int valid;
138
139 assert(data);
140
141
142
143
144
145 GS1_LINTER_ISO3166ALPHA2_LOOKUP(data, data_len, valid);
148
149
150
151
152
155 0,
156 data_len
157 );
158
159}
#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_ALPHA2
A valid ISO 3166 two-character country code is required.
Definition gs1syntaxdictionary.h:99