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