/
country.c
868 lines (854 loc) · 44.5 KB
/
country.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
#include "country.h"
#include "utils/builtins.h"
PG_MODULE_MAGIC;
static inline char *
create_string(const char *chars, size_t sz)
{
char *str = palloc0((sz));
memcpy(str, chars, (sz));
return str;
}
static inline country
country_from_str(const char *str)
{
if (strlen(str) != 2)
elog(ERROR, "invalid country input string %s", str);
switch (tolower(str[0]) | tolower(str[1]) << 8)
{
case AD: return 1;
case AE: return 2;
case AF: return 3;
case AG: return 4;
case AI: return 5;
case AL: return 6;
case AM: return 7;
case AO: return 8;
case AQ: return 9;
case AR: return 10;
case AS: return 11;
case AT: return 12;
case AU: return 13;
case AW: return 14;
case AX: return 15;
case AZ: return 16;
case BA: return 17;
case BB: return 18;
case BD: return 19;
case BE: return 20;
case BF: return 21;
case BG: return 22;
case BH: return 23;
case BI: return 24;
case BJ: return 25;
case BL: return 26;
case BM: return 27;
case BN: return 28;
case BO: return 29;
case BQ: return 30;
case BR: return 31;
case BS: return 32;
case BT: return 33;
case BV: return 34;
case BW: return 35;
case BY: return 36;
case BZ: return 37;
case CA: return 38;
case CC: return 39;
case CD: return 40;
case CF: return 41;
case CG: return 42;
case CH: return 43;
case CI: return 44;
case CK: return 45;
case CL: return 46;
case CM: return 47;
case CN: return 48;
case CO: return 49;
case CR: return 50;
case CU: return 51;
case CV: return 52;
case CW: return 53;
case CX: return 54;
case CY: return 55;
case CZ: return 56;
case DE: return 57;
case DJ: return 58;
case DK: return 59;
case DM: return 60;
case DO: return 61;
case DZ: return 62;
case EC: return 63;
case EE: return 64;
case EG: return 65;
case EH: return 66;
case ER: return 67;
case ES: return 68;
case ET: return 69;
case FI: return 70;
case FJ: return 71;
case FK: return 72;
case FM: return 73;
case FO: return 74;
case FR: return 75;
case GA: return 76;
case GB: return 77;
case GD: return 78;
case GE: return 79;
case GF: return 80;
case GG: return 81;
case GH: return 82;
case GI: return 83;
case GL: return 84;
case GM: return 85;
case GN: return 86;
case GP: return 87;
case GQ: return 88;
case GR: return 89;
case GS: return 90;
case GT: return 91;
case GU: return 92;
case GW: return 93;
case GY: return 94;
case HK: return 95;
case HM: return 96;
case HN: return 97;
case HR: return 98;
case HT: return 99;
case HU: return 100;
case ID: return 101;
case IE: return 102;
case IL: return 103;
case IM: return 104;
case IN: return 105;
case IO: return 106;
case IQ: return 107;
case IR: return 108;
case IS: return 109;
case IT: return 110;
case JE: return 111;
case JM: return 112;
case JO: return 113;
case JP: return 114;
case KE: return 115;
case KG: return 116;
case KH: return 117;
case KI: return 118;
case KM: return 119;
case KN: return 120;
case KP: return 121;
case KR: return 122;
case KW: return 123;
case KY: return 124;
case KZ: return 125;
case LA: return 126;
case LB: return 127;
case LC: return 128;
case LI: return 129;
case LK: return 130;
case LR: return 131;
case LS: return 132;
case LT: return 133;
case LU: return 134;
case LV: return 135;
case LY: return 136;
case MA: return 137;
case MC: return 138;
case MD: return 139;
case ME: return 140;
case MF: return 141;
case MG: return 142;
case MH: return 143;
case MK: return 144;
case ML: return 145;
case MM: return 146;
case MN: return 147;
case MO: return 148;
case MP: return 149;
case MQ: return 150;
case MR: return 151;
case MS: return 152;
case MT: return 153;
case MU: return 154;
case MV: return 155;
case MW: return 156;
case MX: return 157;
case MY: return 158;
case MZ: return 159;
case NA: return 160;
case NC: return 161;
case NE: return 162;
case NF: return 163;
case NG: return 164;
case NI: return 165;
case NL: return 166;
case NO: return 167;
case NP: return 168;
case NR: return 169;
case NU: return 170;
case NZ: return 171;
case OM: return 172;
case PA: return 173;
case PE: return 174;
case PF: return 175;
case PG: return 176;
case PH: return 177;
case PK: return 178;
case PL: return 179;
case PM: return 180;
case PN: return 181;
case PR: return 182;
case PS: return 183;
case PT: return 184;
case PW: return 185;
case PY: return 186;
case QA: return 187;
case RE: return 188;
case RO: return 189;
case RS: return 190;
case RU: return 191;
case RW: return 192;
case SA: return 193;
case SB: return 194;
case SC: return 195;
case SD: return 196;
case SE: return 197;
case SG: return 198;
case SH: return 199;
case SI: return 200;
case SJ: return 201;
case SK: return 202;
case SL: return 203;
case SM: return 204;
case SN: return 205;
case SO: return 206;
case SR: return 207;
case SS: return 208;
case ST: return 209;
case SV: return 210;
case SX: return 211;
case SY: return 212;
case SZ: return 213;
case TC: return 214;
case TD: return 215;
case TF: return 216;
case TG: return 217;
case TH: return 218;
case TJ: return 219;
case TK: return 220;
case TL: return 221;
case TM: return 222;
case TN: return 223;
case TO: return 224;
case TR: return 225;
case TT: return 226;
case TV: return 227;
case TW: return 228;
case TZ: return 229;
case UA: return 230;
case UG: return 231;
case UK: return 232;
case UM: return 233;
case US: return 234;
case UY: return 235;
case UZ: return 236;
case VA: return 237;
case VC: return 238;
case VE: return 239;
case VG: return 240;
case VI: return 241;
case VN: return 242;
case VU: return 243;
case WF: return 244;
case WS: return 245;
case YE: return 246;
case YT: return 247;
case ZA: return 248;
case ZM: return 249;
case ZW: return 250;
case ZZ: return 255;
default: elog(ERROR, "invalid country input string %s", str);
}
}
static inline char *
country_to_str(country c)
{
switch (c)
{
case 1: return create_string(CONST_STRING("ad"));
case 2: return create_string(CONST_STRING("ae"));
case 3: return create_string(CONST_STRING("af"));
case 4: return create_string(CONST_STRING("ag"));
case 5: return create_string(CONST_STRING("ai"));
case 6: return create_string(CONST_STRING("al"));
case 7: return create_string(CONST_STRING("am"));
case 8: return create_string(CONST_STRING("ao"));
case 9: return create_string(CONST_STRING("aq"));
case 10: return create_string(CONST_STRING("ar"));
case 11: return create_string(CONST_STRING("as"));
case 12: return create_string(CONST_STRING("at"));
case 13: return create_string(CONST_STRING("au"));
case 14: return create_string(CONST_STRING("aw"));
case 15: return create_string(CONST_STRING("ax"));
case 16: return create_string(CONST_STRING("az"));
case 17: return create_string(CONST_STRING("ba"));
case 18: return create_string(CONST_STRING("bb"));
case 19: return create_string(CONST_STRING("bd"));
case 20: return create_string(CONST_STRING("be"));
case 21: return create_string(CONST_STRING("bf"));
case 22: return create_string(CONST_STRING("bg"));
case 23: return create_string(CONST_STRING("bh"));
case 24: return create_string(CONST_STRING("bi"));
case 25: return create_string(CONST_STRING("bj"));
case 26: return create_string(CONST_STRING("bl"));
case 27: return create_string(CONST_STRING("bm"));
case 28: return create_string(CONST_STRING("bn"));
case 29: return create_string(CONST_STRING("bo"));
case 30: return create_string(CONST_STRING("bq"));
case 31: return create_string(CONST_STRING("br"));
case 32: return create_string(CONST_STRING("bs"));
case 33: return create_string(CONST_STRING("bt"));
case 34: return create_string(CONST_STRING("bv"));
case 35: return create_string(CONST_STRING("bw"));
case 36: return create_string(CONST_STRING("by"));
case 37: return create_string(CONST_STRING("bz"));
case 38: return create_string(CONST_STRING("ca"));
case 39: return create_string(CONST_STRING("cc"));
case 40: return create_string(CONST_STRING("cd"));
case 41: return create_string(CONST_STRING("cf"));
case 42: return create_string(CONST_STRING("cg"));
case 43: return create_string(CONST_STRING("ch"));
case 44: return create_string(CONST_STRING("ci"));
case 45: return create_string(CONST_STRING("ck"));
case 46: return create_string(CONST_STRING("cl"));
case 47: return create_string(CONST_STRING("cm"));
case 48: return create_string(CONST_STRING("cn"));
case 49: return create_string(CONST_STRING("co"));
case 50: return create_string(CONST_STRING("cr"));
case 51: return create_string(CONST_STRING("cu"));
case 52: return create_string(CONST_STRING("cv"));
case 53: return create_string(CONST_STRING("cw"));
case 54: return create_string(CONST_STRING("cx"));
case 55: return create_string(CONST_STRING("cy"));
case 56: return create_string(CONST_STRING("cz"));
case 57: return create_string(CONST_STRING("de"));
case 58: return create_string(CONST_STRING("dj"));
case 59: return create_string(CONST_STRING("dk"));
case 60: return create_string(CONST_STRING("dm"));
case 61: return create_string(CONST_STRING("do"));
case 62: return create_string(CONST_STRING("dz"));
case 63: return create_string(CONST_STRING("ec"));
case 64: return create_string(CONST_STRING("ee"));
case 65: return create_string(CONST_STRING("eg"));
case 66: return create_string(CONST_STRING("eh"));
case 67: return create_string(CONST_STRING("er"));
case 68: return create_string(CONST_STRING("es"));
case 69: return create_string(CONST_STRING("et"));
case 70: return create_string(CONST_STRING("fi"));
case 71: return create_string(CONST_STRING("fj"));
case 72: return create_string(CONST_STRING("fk"));
case 73: return create_string(CONST_STRING("fm"));
case 74: return create_string(CONST_STRING("fo"));
case 75: return create_string(CONST_STRING("fr"));
case 76: return create_string(CONST_STRING("ga"));
case 77: return create_string(CONST_STRING("gb"));
case 78: return create_string(CONST_STRING("gd"));
case 79: return create_string(CONST_STRING("ge"));
case 80: return create_string(CONST_STRING("gf"));
case 81: return create_string(CONST_STRING("gg"));
case 82: return create_string(CONST_STRING("gh"));
case 83: return create_string(CONST_STRING("gi"));
case 84: return create_string(CONST_STRING("gl"));
case 85: return create_string(CONST_STRING("gm"));
case 86: return create_string(CONST_STRING("gn"));
case 87: return create_string(CONST_STRING("gp"));
case 88: return create_string(CONST_STRING("gq"));
case 89: return create_string(CONST_STRING("gr"));
case 90: return create_string(CONST_STRING("gs"));
case 91: return create_string(CONST_STRING("gt"));
case 92: return create_string(CONST_STRING("gu"));
case 93: return create_string(CONST_STRING("gw"));
case 94: return create_string(CONST_STRING("gy"));
case 95: return create_string(CONST_STRING("hk"));
case 96: return create_string(CONST_STRING("hm"));
case 97: return create_string(CONST_STRING("hn"));
case 98: return create_string(CONST_STRING("hr"));
case 99: return create_string(CONST_STRING("ht"));
case 100: return create_string(CONST_STRING("hu"));
case 101: return create_string(CONST_STRING("id"));
case 102: return create_string(CONST_STRING("ie"));
case 103: return create_string(CONST_STRING("il"));
case 104: return create_string(CONST_STRING("im"));
case 105: return create_string(CONST_STRING("in"));
case 106: return create_string(CONST_STRING("io"));
case 107: return create_string(CONST_STRING("iq"));
case 108: return create_string(CONST_STRING("ir"));
case 109: return create_string(CONST_STRING("is"));
case 110: return create_string(CONST_STRING("it"));
case 111: return create_string(CONST_STRING("je"));
case 112: return create_string(CONST_STRING("jm"));
case 113: return create_string(CONST_STRING("jo"));
case 114: return create_string(CONST_STRING("jp"));
case 115: return create_string(CONST_STRING("ke"));
case 116: return create_string(CONST_STRING("kg"));
case 117: return create_string(CONST_STRING("kh"));
case 118: return create_string(CONST_STRING("ki"));
case 119: return create_string(CONST_STRING("km"));
case 120: return create_string(CONST_STRING("kn"));
case 121: return create_string(CONST_STRING("kp"));
case 122: return create_string(CONST_STRING("kr"));
case 123: return create_string(CONST_STRING("kw"));
case 124: return create_string(CONST_STRING("ky"));
case 125: return create_string(CONST_STRING("kz"));
case 126: return create_string(CONST_STRING("la"));
case 127: return create_string(CONST_STRING("lb"));
case 128: return create_string(CONST_STRING("lc"));
case 129: return create_string(CONST_STRING("li"));
case 130: return create_string(CONST_STRING("lk"));
case 131: return create_string(CONST_STRING("lr"));
case 132: return create_string(CONST_STRING("ls"));
case 133: return create_string(CONST_STRING("lt"));
case 134: return create_string(CONST_STRING("lu"));
case 135: return create_string(CONST_STRING("lv"));
case 136: return create_string(CONST_STRING("ly"));
case 137: return create_string(CONST_STRING("ma"));
case 138: return create_string(CONST_STRING("mc"));
case 139: return create_string(CONST_STRING("md"));
case 140: return create_string(CONST_STRING("me"));
case 141: return create_string(CONST_STRING("mf"));
case 142: return create_string(CONST_STRING("mg"));
case 143: return create_string(CONST_STRING("mh"));
case 144: return create_string(CONST_STRING("mk"));
case 145: return create_string(CONST_STRING("ml"));
case 146: return create_string(CONST_STRING("mm"));
case 147: return create_string(CONST_STRING("mn"));
case 148: return create_string(CONST_STRING("mo"));
case 149: return create_string(CONST_STRING("mp"));
case 150: return create_string(CONST_STRING("mq"));
case 151: return create_string(CONST_STRING("mr"));
case 152: return create_string(CONST_STRING("ms"));
case 153: return create_string(CONST_STRING("mt"));
case 154: return create_string(CONST_STRING("mu"));
case 155: return create_string(CONST_STRING("mv"));
case 156: return create_string(CONST_STRING("mw"));
case 157: return create_string(CONST_STRING("mx"));
case 158: return create_string(CONST_STRING("my"));
case 159: return create_string(CONST_STRING("mz"));
case 160: return create_string(CONST_STRING("na"));
case 161: return create_string(CONST_STRING("nc"));
case 162: return create_string(CONST_STRING("ne"));
case 163: return create_string(CONST_STRING("nf"));
case 164: return create_string(CONST_STRING("ng"));
case 165: return create_string(CONST_STRING("ni"));
case 166: return create_string(CONST_STRING("nl"));
case 167: return create_string(CONST_STRING("no"));
case 168: return create_string(CONST_STRING("np"));
case 169: return create_string(CONST_STRING("nr"));
case 170: return create_string(CONST_STRING("nu"));
case 171: return create_string(CONST_STRING("nz"));
case 172: return create_string(CONST_STRING("om"));
case 173: return create_string(CONST_STRING("pa"));
case 174: return create_string(CONST_STRING("pe"));
case 175: return create_string(CONST_STRING("pf"));
case 176: return create_string(CONST_STRING("pg"));
case 177: return create_string(CONST_STRING("ph"));
case 178: return create_string(CONST_STRING("pk"));
case 179: return create_string(CONST_STRING("pl"));
case 180: return create_string(CONST_STRING("pm"));
case 181: return create_string(CONST_STRING("pn"));
case 182: return create_string(CONST_STRING("pr"));
case 183: return create_string(CONST_STRING("ps"));
case 184: return create_string(CONST_STRING("pt"));
case 185: return create_string(CONST_STRING("pw"));
case 186: return create_string(CONST_STRING("py"));
case 187: return create_string(CONST_STRING("qa"));
case 188: return create_string(CONST_STRING("re"));
case 189: return create_string(CONST_STRING("ro"));
case 190: return create_string(CONST_STRING("rs"));
case 191: return create_string(CONST_STRING("ru"));
case 192: return create_string(CONST_STRING("rw"));
case 193: return create_string(CONST_STRING("sa"));
case 194: return create_string(CONST_STRING("sb"));
case 195: return create_string(CONST_STRING("sc"));
case 196: return create_string(CONST_STRING("sd"));
case 197: return create_string(CONST_STRING("se"));
case 198: return create_string(CONST_STRING("sg"));
case 199: return create_string(CONST_STRING("sh"));
case 200: return create_string(CONST_STRING("si"));
case 201: return create_string(CONST_STRING("sj"));
case 202: return create_string(CONST_STRING("sk"));
case 203: return create_string(CONST_STRING("sl"));
case 204: return create_string(CONST_STRING("sm"));
case 205: return create_string(CONST_STRING("sn"));
case 206: return create_string(CONST_STRING("so"));
case 207: return create_string(CONST_STRING("sr"));
case 208: return create_string(CONST_STRING("ss"));
case 209: return create_string(CONST_STRING("st"));
case 210: return create_string(CONST_STRING("sv"));
case 211: return create_string(CONST_STRING("sx"));
case 212: return create_string(CONST_STRING("sy"));
case 213: return create_string(CONST_STRING("sz"));
case 214: return create_string(CONST_STRING("tc"));
case 215: return create_string(CONST_STRING("td"));
case 216: return create_string(CONST_STRING("tf"));
case 217: return create_string(CONST_STRING("tg"));
case 218: return create_string(CONST_STRING("th"));
case 219: return create_string(CONST_STRING("tj"));
case 220: return create_string(CONST_STRING("tk"));
case 221: return create_string(CONST_STRING("tl"));
case 222: return create_string(CONST_STRING("tm"));
case 223: return create_string(CONST_STRING("tn"));
case 224: return create_string(CONST_STRING("to"));
case 225: return create_string(CONST_STRING("tr"));
case 226: return create_string(CONST_STRING("tt"));
case 227: return create_string(CONST_STRING("tv"));
case 228: return create_string(CONST_STRING("tw"));
case 229: return create_string(CONST_STRING("tz"));
case 230: return create_string(CONST_STRING("ua"));
case 231: return create_string(CONST_STRING("ug"));
case 232: return create_string(CONST_STRING("uk"));
case 233: return create_string(CONST_STRING("um"));
case 234: return create_string(CONST_STRING("us"));
case 235: return create_string(CONST_STRING("uy"));
case 236: return create_string(CONST_STRING("uz"));
case 237: return create_string(CONST_STRING("va"));
case 238: return create_string(CONST_STRING("vc"));
case 239: return create_string(CONST_STRING("ve"));
case 240: return create_string(CONST_STRING("vg"));
case 241: return create_string(CONST_STRING("vi"));
case 242: return create_string(CONST_STRING("vn"));
case 243: return create_string(CONST_STRING("vu"));
case 244: return create_string(CONST_STRING("wf"));
case 245: return create_string(CONST_STRING("ws"));
case 246: return create_string(CONST_STRING("ye"));
case 247: return create_string(CONST_STRING("yt"));
case 248: return create_string(CONST_STRING("za"));
case 249: return create_string(CONST_STRING("zm"));
case 250: return create_string(CONST_STRING("zw"));
case 255: return create_string(CONST_STRING("zz"));
default: elog(ERROR, "unknown output country");
}
}
static inline text *
country_to_name(country c)
{
switch (c)
{
case 1: return cstring_to_text_with_len(CONST_STRING("Andorra"));
case 2: return cstring_to_text_with_len(CONST_STRING("United Arab Emirates"));
case 3: return cstring_to_text_with_len(CONST_STRING("Afghanistan"));
case 4: return cstring_to_text_with_len(CONST_STRING("Antigua and Barbuda"));
case 5: return cstring_to_text_with_len(CONST_STRING("Anguilla"));
case 6: return cstring_to_text_with_len(CONST_STRING("Albania"));
case 7: return cstring_to_text_with_len(CONST_STRING("Armenia"));
case 8: return cstring_to_text_with_len(CONST_STRING("Angola"));
case 9: return cstring_to_text_with_len(CONST_STRING("Antarctica"));
case 10: return cstring_to_text_with_len(CONST_STRING("Argentina"));
case 11: return cstring_to_text_with_len(CONST_STRING("American Samoa"));
case 12: return cstring_to_text_with_len(CONST_STRING("Austria"));
case 13: return cstring_to_text_with_len(CONST_STRING("Australia"));
case 14: return cstring_to_text_with_len(CONST_STRING("Aruba"));
case 15: return cstring_to_text_with_len(CONST_STRING("Åland Islands"));
case 16: return cstring_to_text_with_len(CONST_STRING("Azerbaijan"));
case 17: return cstring_to_text_with_len(CONST_STRING("Bosnia and Herzegovina"));
case 18: return cstring_to_text_with_len(CONST_STRING("Barbados"));
case 19: return cstring_to_text_with_len(CONST_STRING("Bangladesh"));
case 20: return cstring_to_text_with_len(CONST_STRING("Belgium"));
case 21: return cstring_to_text_with_len(CONST_STRING("Burkina Faso"));
case 22: return cstring_to_text_with_len(CONST_STRING("Bulgaria"));
case 23: return cstring_to_text_with_len(CONST_STRING("Bahrain"));
case 24: return cstring_to_text_with_len(CONST_STRING("Burundi"));
case 25: return cstring_to_text_with_len(CONST_STRING("Benin"));
case 26: return cstring_to_text_with_len(CONST_STRING("Saint Barthélemy"));
case 27: return cstring_to_text_with_len(CONST_STRING("Bermuda"));
case 28: return cstring_to_text_with_len(CONST_STRING("Brunei Darussalam"));
case 29: return cstring_to_text_with_len(CONST_STRING("Bolivia (Plurinational State of)"));
case 30: return cstring_to_text_with_len(CONST_STRING("Bonaire, Sint Eustatius and Saba"));
case 31: return cstring_to_text_with_len(CONST_STRING("Brazil"));
case 32: return cstring_to_text_with_len(CONST_STRING("Bahamas"));
case 33: return cstring_to_text_with_len(CONST_STRING("Bhutan"));
case 34: return cstring_to_text_with_len(CONST_STRING("Bouvet Island"));
case 35: return cstring_to_text_with_len(CONST_STRING("Botswana"));
case 36: return cstring_to_text_with_len(CONST_STRING("Belarus"));
case 37: return cstring_to_text_with_len(CONST_STRING("Belize"));
case 38: return cstring_to_text_with_len(CONST_STRING("Canada"));
case 39: return cstring_to_text_with_len(CONST_STRING("Cocos (Keeling) Islands"));
case 40: return cstring_to_text_with_len(CONST_STRING("Congo (the Democratic Republic of the)"));
case 41: return cstring_to_text_with_len(CONST_STRING("Central African Republic"));
case 42: return cstring_to_text_with_len(CONST_STRING("Congo"));
case 43: return cstring_to_text_with_len(CONST_STRING("Switzerland"));
case 44: return cstring_to_text_with_len(CONST_STRING("Côte d'Ivoire"));
case 45: return cstring_to_text_with_len(CONST_STRING("Cook Islands"));
case 46: return cstring_to_text_with_len(CONST_STRING("Chile"));
case 47: return cstring_to_text_with_len(CONST_STRING("Cameroon"));
case 48: return cstring_to_text_with_len(CONST_STRING("China"));
case 49: return cstring_to_text_with_len(CONST_STRING("Colombia"));
case 50: return cstring_to_text_with_len(CONST_STRING("Costa Rica"));
case 51: return cstring_to_text_with_len(CONST_STRING("Cuba"));
case 52: return cstring_to_text_with_len(CONST_STRING("Cabo Verde"));
case 53: return cstring_to_text_with_len(CONST_STRING("Curaçao"));
case 54: return cstring_to_text_with_len(CONST_STRING("Christmas Island"));
case 55: return cstring_to_text_with_len(CONST_STRING("Cyprus"));
case 56: return cstring_to_text_with_len(CONST_STRING("Czechia"));
case 57: return cstring_to_text_with_len(CONST_STRING("Germany"));
case 58: return cstring_to_text_with_len(CONST_STRING("Djibouti"));
case 59: return cstring_to_text_with_len(CONST_STRING("Denmark"));
case 60: return cstring_to_text_with_len(CONST_STRING("Dominica"));
case 61: return cstring_to_text_with_len(CONST_STRING("Dominican Republic"));
case 62: return cstring_to_text_with_len(CONST_STRING("Algeria"));
case 63: return cstring_to_text_with_len(CONST_STRING("Ecuador"));
case 64: return cstring_to_text_with_len(CONST_STRING("Estonia"));
case 65: return cstring_to_text_with_len(CONST_STRING("Egypt"));
case 66: return cstring_to_text_with_len(CONST_STRING("Western Sahara"));
case 67: return cstring_to_text_with_len(CONST_STRING("Eritrea"));
case 68: return cstring_to_text_with_len(CONST_STRING("Spain"));
case 69: return cstring_to_text_with_len(CONST_STRING("Ethiopia"));
case 70: return cstring_to_text_with_len(CONST_STRING("Finland"));
case 71: return cstring_to_text_with_len(CONST_STRING("Fiji"));
case 72: return cstring_to_text_with_len(CONST_STRING("Falkland Islands (the) [Malvinas]"));
case 73: return cstring_to_text_with_len(CONST_STRING("Micronesia (Federated States of)"));
case 74: return cstring_to_text_with_len(CONST_STRING("Faroe Islands"));
case 75: return cstring_to_text_with_len(CONST_STRING("France"));
case 76: return cstring_to_text_with_len(CONST_STRING("Gabon"));
case 77: return cstring_to_text_with_len(CONST_STRING("United Kingdom of Great Britain and Northern Ireland"));
case 78: return cstring_to_text_with_len(CONST_STRING("Grenada"));
case 79: return cstring_to_text_with_len(CONST_STRING("Georgia"));
case 80: return cstring_to_text_with_len(CONST_STRING("French Guiana"));
case 81: return cstring_to_text_with_len(CONST_STRING("Guernsey"));
case 82: return cstring_to_text_with_len(CONST_STRING("Ghana"));
case 83: return cstring_to_text_with_len(CONST_STRING("Gibraltar"));
case 84: return cstring_to_text_with_len(CONST_STRING("Greenland"));
case 85: return cstring_to_text_with_len(CONST_STRING("Gambia"));
case 86: return cstring_to_text_with_len(CONST_STRING("Guinea"));
case 87: return cstring_to_text_with_len(CONST_STRING("Guadeloupe"));
case 88: return cstring_to_text_with_len(CONST_STRING("Equatorial Guinea"));
case 89: return cstring_to_text_with_len(CONST_STRING("Greece"));
case 90: return cstring_to_text_with_len(CONST_STRING("South Georgia and the South Sandwich Islands"));
case 91: return cstring_to_text_with_len(CONST_STRING("Guatemala"));
case 92: return cstring_to_text_with_len(CONST_STRING("Guam"));
case 93: return cstring_to_text_with_len(CONST_STRING("Guinea-Bissau"));
case 94: return cstring_to_text_with_len(CONST_STRING("Guyana"));
case 95: return cstring_to_text_with_len(CONST_STRING("Hong Kong"));
case 96: return cstring_to_text_with_len(CONST_STRING("Heard Island and McDonald Islands"));
case 97: return cstring_to_text_with_len(CONST_STRING("Honduras"));
case 98: return cstring_to_text_with_len(CONST_STRING("Croatia"));
case 99: return cstring_to_text_with_len(CONST_STRING("Haiti"));
case 100: return cstring_to_text_with_len(CONST_STRING("Hungary"));
case 101: return cstring_to_text_with_len(CONST_STRING("Indonesia"));
case 102: return cstring_to_text_with_len(CONST_STRING("Ireland"));
case 103: return cstring_to_text_with_len(CONST_STRING("Israel"));
case 104: return cstring_to_text_with_len(CONST_STRING("Isle of Man"));
case 105: return cstring_to_text_with_len(CONST_STRING("India"));
case 106: return cstring_to_text_with_len(CONST_STRING("British Indian Ocean Territory"));
case 107: return cstring_to_text_with_len(CONST_STRING("Iraq"));
case 108: return cstring_to_text_with_len(CONST_STRING("Iran (Islamic Republic of)"));
case 109: return cstring_to_text_with_len(CONST_STRING("Iceland"));
case 110: return cstring_to_text_with_len(CONST_STRING("Italy"));
case 111: return cstring_to_text_with_len(CONST_STRING("Jersey"));
case 112: return cstring_to_text_with_len(CONST_STRING("Jamaica"));
case 113: return cstring_to_text_with_len(CONST_STRING("Jordan"));
case 114: return cstring_to_text_with_len(CONST_STRING("Japan"));
case 115: return cstring_to_text_with_len(CONST_STRING("Kenya"));
case 116: return cstring_to_text_with_len(CONST_STRING("Kyrgyzstan"));
case 117: return cstring_to_text_with_len(CONST_STRING("Cambodia"));
case 118: return cstring_to_text_with_len(CONST_STRING("Kiribati"));
case 119: return cstring_to_text_with_len(CONST_STRING("Comoros"));
case 120: return cstring_to_text_with_len(CONST_STRING("Saint Kitts and Nevis"));
case 121: return cstring_to_text_with_len(CONST_STRING("Korea (the Democratic People's Republic of)"));
case 122: return cstring_to_text_with_len(CONST_STRING("Korea (the Republic of)"));
case 123: return cstring_to_text_with_len(CONST_STRING("Kuwait"));
case 124: return cstring_to_text_with_len(CONST_STRING("Cayman Islands"));
case 125: return cstring_to_text_with_len(CONST_STRING("Kazakhstan"));
case 126: return cstring_to_text_with_len(CONST_STRING("Lao People's Democratic Republic"));
case 127: return cstring_to_text_with_len(CONST_STRING("Lebanon"));
case 128: return cstring_to_text_with_len(CONST_STRING("Saint Lucia"));
case 129: return cstring_to_text_with_len(CONST_STRING("Liechtenstein"));
case 130: return cstring_to_text_with_len(CONST_STRING("Sri Lanka"));
case 131: return cstring_to_text_with_len(CONST_STRING("Liberia"));
case 132: return cstring_to_text_with_len(CONST_STRING("Lesotho"));
case 133: return cstring_to_text_with_len(CONST_STRING("Lithuania"));
case 134: return cstring_to_text_with_len(CONST_STRING("Luxembourg"));
case 135: return cstring_to_text_with_len(CONST_STRING("Latvia"));
case 136: return cstring_to_text_with_len(CONST_STRING("Libya"));
case 137: return cstring_to_text_with_len(CONST_STRING("Morocco"));
case 138: return cstring_to_text_with_len(CONST_STRING("Monaco"));
case 139: return cstring_to_text_with_len(CONST_STRING("Moldova (the Republic of)"));
case 140: return cstring_to_text_with_len(CONST_STRING("Montenegro"));
case 141: return cstring_to_text_with_len(CONST_STRING("Saint Martin (French part)"));
case 142: return cstring_to_text_with_len(CONST_STRING("Madagascar"));
case 143: return cstring_to_text_with_len(CONST_STRING("Marshall Islands"));
case 144: return cstring_to_text_with_len(CONST_STRING("Republic of North Macedonia"));
case 145: return cstring_to_text_with_len(CONST_STRING("Mali"));
case 146: return cstring_to_text_with_len(CONST_STRING("Myanmar"));
case 147: return cstring_to_text_with_len(CONST_STRING("Mongolia"));
case 148: return cstring_to_text_with_len(CONST_STRING("Macao"));
case 149: return cstring_to_text_with_len(CONST_STRING("Northern Mariana Islands"));
case 150: return cstring_to_text_with_len(CONST_STRING("Martinique"));
case 151: return cstring_to_text_with_len(CONST_STRING("Mauritania"));
case 152: return cstring_to_text_with_len(CONST_STRING("Montserrat"));
case 153: return cstring_to_text_with_len(CONST_STRING("Malta"));
case 154: return cstring_to_text_with_len(CONST_STRING("Mauritius"));
case 155: return cstring_to_text_with_len(CONST_STRING("Maldives"));
case 156: return cstring_to_text_with_len(CONST_STRING("Malawi"));
case 157: return cstring_to_text_with_len(CONST_STRING("Mexico"));
case 158: return cstring_to_text_with_len(CONST_STRING("Malaysia"));
case 159: return cstring_to_text_with_len(CONST_STRING("Mozambique"));
case 160: return cstring_to_text_with_len(CONST_STRING("Namibia"));
case 161: return cstring_to_text_with_len(CONST_STRING("New Caledonia"));
case 162: return cstring_to_text_with_len(CONST_STRING("Niger"));
case 163: return cstring_to_text_with_len(CONST_STRING("Norfolk Island"));
case 164: return cstring_to_text_with_len(CONST_STRING("Nigeria"));
case 165: return cstring_to_text_with_len(CONST_STRING("Nicaragua"));
case 166: return cstring_to_text_with_len(CONST_STRING("Netherlands"));
case 167: return cstring_to_text_with_len(CONST_STRING("Norway"));
case 168: return cstring_to_text_with_len(CONST_STRING("Nepal"));
case 169: return cstring_to_text_with_len(CONST_STRING("Nauru"));
case 170: return cstring_to_text_with_len(CONST_STRING("Niue"));
case 171: return cstring_to_text_with_len(CONST_STRING("New Zealand"));
case 172: return cstring_to_text_with_len(CONST_STRING("Oman"));
case 173: return cstring_to_text_with_len(CONST_STRING("Panama"));
case 174: return cstring_to_text_with_len(CONST_STRING("Peru"));
case 175: return cstring_to_text_with_len(CONST_STRING("French Polynesia"));
case 176: return cstring_to_text_with_len(CONST_STRING("Papua New Guinea"));
case 177: return cstring_to_text_with_len(CONST_STRING("Philippines"));
case 178: return cstring_to_text_with_len(CONST_STRING("Pakistan"));
case 179: return cstring_to_text_with_len(CONST_STRING("Poland"));
case 180: return cstring_to_text_with_len(CONST_STRING("Saint Pierre and Miquelon"));
case 181: return cstring_to_text_with_len(CONST_STRING("Pitcairn"));
case 182: return cstring_to_text_with_len(CONST_STRING("Puerto Rico"));
case 183: return cstring_to_text_with_len(CONST_STRING("Palestine, State of"));
case 184: return cstring_to_text_with_len(CONST_STRING("Portugal"));
case 185: return cstring_to_text_with_len(CONST_STRING("Palau"));
case 186: return cstring_to_text_with_len(CONST_STRING("Paraguay"));
case 187: return cstring_to_text_with_len(CONST_STRING("Qatar"));
case 188: return cstring_to_text_with_len(CONST_STRING("Réunion"));
case 189: return cstring_to_text_with_len(CONST_STRING("Romania"));
case 190: return cstring_to_text_with_len(CONST_STRING("Serbia"));
case 191: return cstring_to_text_with_len(CONST_STRING("Russian Federation"));
case 192: return cstring_to_text_with_len(CONST_STRING("Rwanda"));
case 193: return cstring_to_text_with_len(CONST_STRING("Saudi Arabia"));
case 194: return cstring_to_text_with_len(CONST_STRING("Solomon Islands"));
case 195: return cstring_to_text_with_len(CONST_STRING("Seychelles"));
case 196: return cstring_to_text_with_len(CONST_STRING("Sudan"));
case 197: return cstring_to_text_with_len(CONST_STRING("Sweden"));
case 198: return cstring_to_text_with_len(CONST_STRING("Singapore"));
case 199: return cstring_to_text_with_len(CONST_STRING("Saint Helena, Ascension and Tristan da Cunha"));
case 200: return cstring_to_text_with_len(CONST_STRING("Slovenia"));
case 201: return cstring_to_text_with_len(CONST_STRING("Svalbard and Jan Mayen"));
case 202: return cstring_to_text_with_len(CONST_STRING("Slovakia"));
case 203: return cstring_to_text_with_len(CONST_STRING("Sierra Leone"));
case 204: return cstring_to_text_with_len(CONST_STRING("San Marino"));
case 205: return cstring_to_text_with_len(CONST_STRING("Senegal"));
case 206: return cstring_to_text_with_len(CONST_STRING("Somalia"));
case 207: return cstring_to_text_with_len(CONST_STRING("Suriname"));
case 208: return cstring_to_text_with_len(CONST_STRING("South Sudan"));
case 209: return cstring_to_text_with_len(CONST_STRING("Sao Tome and Principe"));
case 210: return cstring_to_text_with_len(CONST_STRING("El Salvador"));
case 211: return cstring_to_text_with_len(CONST_STRING("Sint Maarten (Dutch part)"));
case 212: return cstring_to_text_with_len(CONST_STRING("Syrian Arab Republic"));
case 213: return cstring_to_text_with_len(CONST_STRING("Eswatini"));
case 214: return cstring_to_text_with_len(CONST_STRING("Turks and Caicos Islands"));
case 215: return cstring_to_text_with_len(CONST_STRING("Chad"));
case 216: return cstring_to_text_with_len(CONST_STRING("French Southern Territories"));
case 217: return cstring_to_text_with_len(CONST_STRING("Togo"));
case 218: return cstring_to_text_with_len(CONST_STRING("Thailand"));
case 219: return cstring_to_text_with_len(CONST_STRING("Tajikistan"));
case 220: return cstring_to_text_with_len(CONST_STRING("Tokelau"));
case 221: return cstring_to_text_with_len(CONST_STRING("Timor-Leste"));
case 222: return cstring_to_text_with_len(CONST_STRING("Turkmenistan"));
case 223: return cstring_to_text_with_len(CONST_STRING("Tunisia"));
case 224: return cstring_to_text_with_len(CONST_STRING("Tonga"));
case 225: return cstring_to_text_with_len(CONST_STRING("Turkey"));
case 226: return cstring_to_text_with_len(CONST_STRING("Trinidad and Tobago"));
case 227: return cstring_to_text_with_len(CONST_STRING("Tuvalu"));
case 228: return cstring_to_text_with_len(CONST_STRING("Taiwan (Province of China)"));
case 229: return cstring_to_text_with_len(CONST_STRING("Tanzania, United Republic of"));
case 230: return cstring_to_text_with_len(CONST_STRING("Ukraine"));
case 231: return cstring_to_text_with_len(CONST_STRING("Uganda"));
case 232: return cstring_to_text_with_len(CONST_STRING("United Kingdom of Great Britain and Northern Ireland"));
case 233: return cstring_to_text_with_len(CONST_STRING("United States Minor Outlying Islands"));
case 234: return cstring_to_text_with_len(CONST_STRING("United States of America"));
case 235: return cstring_to_text_with_len(CONST_STRING("Uruguay"));
case 236: return cstring_to_text_with_len(CONST_STRING("Uzbekistan"));
case 237: return cstring_to_text_with_len(CONST_STRING("Holy See"));
case 238: return cstring_to_text_with_len(CONST_STRING("Saint Vincent and the Grenadines"));
case 239: return cstring_to_text_with_len(CONST_STRING("Venezuela (Bolivarian Republic of)"));
case 240: return cstring_to_text_with_len(CONST_STRING("Virgin Islands (British)"));
case 241: return cstring_to_text_with_len(CONST_STRING("Virgin Islands (U.S.)"));
case 242: return cstring_to_text_with_len(CONST_STRING("Viet Nam"));
case 243: return cstring_to_text_with_len(CONST_STRING("Vanuatu"));
case 244: return cstring_to_text_with_len(CONST_STRING("Wallis and Futuna"));
case 245: return cstring_to_text_with_len(CONST_STRING("Samoa"));
case 246: return cstring_to_text_with_len(CONST_STRING("Yemen"));
case 247: return cstring_to_text_with_len(CONST_STRING("Mayotte"));
case 248: return cstring_to_text_with_len(CONST_STRING("South Africa"));
case 249: return cstring_to_text_with_len(CONST_STRING("Zambia"));
case 250: return cstring_to_text_with_len(CONST_STRING("Zimbabwe"));
case 255: return cstring_to_text_with_len(CONST_STRING("Unknown"));
default: elog(ERROR, "unknown output country");
}
}
static inline text *
country_to_common_name(country c)
{
switch (c)
{
case 28: return cstring_to_text_with_len(CONST_STRING("Brunei"));
case 29: return cstring_to_text_with_len(CONST_STRING("Bolivia"));
case 44: return cstring_to_text_with_len(CONST_STRING("Ivory Coast"));
case 72: return cstring_to_text_with_len(CONST_STRING("Falkland Islands"));
case 77: return cstring_to_text_with_len(CONST_STRING("Great Britain"));
case 108: return cstring_to_text_with_len(CONST_STRING("Iran"));
case 121: return cstring_to_text_with_len(CONST_STRING("North Korea"));
case 122: return cstring_to_text_with_len(CONST_STRING("South Korea"));
case 126: return cstring_to_text_with_len(CONST_STRING("Laos"));
case 139: return cstring_to_text_with_len(CONST_STRING("Moldova"));
case 191: return cstring_to_text_with_len(CONST_STRING("Russia"));
case 212: return cstring_to_text_with_len(CONST_STRING("Syria"));
case 228: return cstring_to_text_with_len(CONST_STRING("Taiwan"));
case 229: return cstring_to_text_with_len(CONST_STRING("Tanzania"));
case 232: return cstring_to_text_with_len(CONST_STRING("Great Britain"));
case 239: return cstring_to_text_with_len(CONST_STRING("Venezuela"));
default: return country_to_name(c);
}
}
PG_FUNCTION_INFO_V1(country_in);
Datum country_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
PG_RETURN_UINT8(country_from_str(str));
}
PG_FUNCTION_INFO_V1(country_out);
Datum country_out(PG_FUNCTION_ARGS)
{
country c = PG_GETARG_UINT8(0);
PG_RETURN_CSTRING(country_to_str(c));
}
PG_FUNCTION_INFO_V1(country_recv);
Datum country_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
const char *str = pq_getmsgstring(buf);
pq_getmsgend(buf);
PG_RETURN_UINT8(country_from_str(str));
}
PG_FUNCTION_INFO_V1(country_send);
Datum country_send(PG_FUNCTION_ARGS)
{
country c = PG_GETARG_UINT8(0);
StringInfoData buf;
pq_begintypsend(&buf);
pq_sendstring(&buf, country_to_str(c));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
PG_FUNCTION_INFO_V1(country_name);
Datum country_name(PG_FUNCTION_ARGS)
{
country c = PG_GETARG_UINT8(0);
PG_RETURN_TEXT_P(country_to_name(c));
}
PG_FUNCTION_INFO_V1(country_common_name);
Datum country_common_name(PG_FUNCTION_ARGS)
{
country c = PG_GETARG_UINT8(0);
PG_RETURN_TEXT_P(country_to_common_name(c));
}