]>
Commit | Line | Data |
---|---|---|
f85f8ebb BP |
1 | #! /usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | our %uuids; | |
7 | our $n_uuids = 0; | |
8 | sub lookup_uuid { | |
9 | my ($uuid) = @_; | |
10 | if (!exists($uuids{$uuid})) { | |
11 | $uuids{$uuid} = $n_uuids++; | |
12 | } | |
13 | return "<$uuids{$uuid}>"; | |
14 | } | |
15 | ||
7360012b BP |
16 | sub sort_set { |
17 | my ($s) = @_; | |
18 | my (@uuids) = sort { $a <=> $b } (grep(/\d+/, split(/(\d+)/, $s))); | |
19 | return '["set",[' . join(',', map('["uuid","<' . $_ . '>"]', @uuids)) . ']]'; | |
20 | } | |
21 | ||
f85f8ebb BP |
22 | my $u = '[0-9a-fA-F]'; |
23 | my $uuid_re = "${u}{8}-${u}{4}-${u}{4}-${u}{4}-${u}{12}"; | |
24 | while (<>) { | |
25 | s/($uuid_re)/lookup_uuid($1)/eg; | |
7360012b BP |
26 | |
27 | # Sort sets like this: | |
28 | # [["uuid","<1>"],["uuid","<0>"]] | |
29 | # to look like this: | |
30 | # [["uuid","<0>"],["uuid","<1>"]] | |
31 | s/(\["set",\[(,?\["uuid","<\d+>"\])+\]\])/sort_set($1)/ge; | |
f85f8ebb BP |
32 | print $_; |
33 | } |