Menu

[r360]: / branches / sew-refactor / postgresql / mk-city-regex.pl  Maximize  Restore  History

Download this file

51 lines (44 with data), 1.1 kB

 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
#! /usr/bin/perl
#!/usr/bin/perl -w
use strict;
use Regexp::Assemble;
my @cities = split(/[\r\n]+/, qx(cat usps-st-city-name.txt));
my %st= ();
for my $x (@cities) {
my ($st, $ct) = split(/\t/, $x);
push @{$st{$st}}, $ct;
}
my $re;
my $ra = Regexp::Assemble->new(flags => "i");
my %re =();
for my $x (sort keys %st) {
$ra->add(@{$st{$x}});
$re = $ra->re;
$re =~ s/\\/\\\\/g;
$re{$x} = $re;
}
print "#define NUM_STATES " . scalar (keys %re) . "\n\n";
print " static const char *states[NUM_STATES] = \n";
print " {\"" . join('","', sort keys %re) . "\"};\n\n";
print " static const char *stcities[NUM_STATES] = {\n";
my $cnt = 0;
my $a = '';
my $b = '';
for my $x (sort keys %re) {
$re = "(?:\\\\b)($re{$x})\$";
print " ,\n" if $cnt;
print " /* -- $x -- $x -- $x -- $x -- $x -- $x -- $x -- $x -- $x -- $x -- */\n";
while ($re =~ s/^(.{1,65})//) {
$a = $1;
if ($a =~ s/(\\+)$//) {
print " \"$b$a\"\n";
$b = $1;
}
else {
print " \"$b$a\"\n";
$b = '';
}
}
$cnt++;
}
print " };\n";
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.