ConnectionManager: Document tracking functions.
[thrasher.git] / perl / lib / Thrasher / Nodeprep.pm
blob21753d9cf483f2a793c143e923661346826f1c2b
1 package Thrasher::Nodeprep;
2 use strict;
3 use warnings;
5 # This module uses the Unicode::Stringprep module, combined with the
6 # specification in RFC3920, to define "nodeprep" and "stringprep"
7 # functions that can be used for converting strings of unknown safety
8 # into JIDs.
10 use Unicode::Stringprep;
11 use Unicode::Stringprep::Mapping;
12 use Unicode::Stringprep::Prohibited;
14 use base 'Exporter';
16 use Data::Dumper;
18 our @EXPORT_OK = qw(nodeprep stringprep);
19 our %EXPORT_TAGS = (all => \@EXPORT_OK);
21 *nodeprep = Unicode::Stringprep->new
22 (3.2,
25 # In accordance with RFC3920 section A.3
26 @Unicode::Stringprep::Mapping::B1,
27 @Unicode::Stringprep::Mapping::B2,
29 # The standard specifies these as banned in A.5, but I'm going to map
30 # them to blank strings instead, so they are eliminated instead
31 # of causing "die"s.
32 (map { defined($_) ? ($_, '') : () }
33 @Unicode::Stringprep::Prohibited::C11,
34 @Unicode::Stringprep::Prohibited::C12,
35 @Unicode::Stringprep::Prohibited::C21,
36 @Unicode::Stringprep::Prohibited::C22,
37 @Unicode::Stringprep::Prohibited::C3,
38 @Unicode::Stringprep::Prohibited::C4,
39 @Unicode::Stringprep::Prohibited::C5,
40 @Unicode::Stringprep::Prohibited::C6,
41 @Unicode::Stringprep::Prohibited::C7,
42 @Unicode::Stringprep::Prohibited::C8,
43 @Unicode::Stringprep::Prohibited::C9,
46 0x22, # double-quote
47 0x26, # ampersand
48 0x27, # apostrophe
49 0x2f, # backslash,
50 0x3a, # colon
51 0x3c, # less than
52 0x3e, # greater than
53 )),
55 ord('@') => '%' # I don't really like this but it's traditional
58 # Section A.4 specifies normalization form KC
59 'KC',
61 # Prohibited characters are replaced with blanks
65 # Section A.6 specifies handling bi-directional strings.
71 *resource_prep = Unicode::Stringprep->new
72 (3.2,
74 # Section B.3
76 @Unicode::Stringprep::Mapping::B1,
77 (map { defined($_) ? ($_, '') : () }
78 @Unicode::Stringprep::Prohibited::C12,
79 @Unicode::Stringprep::Prohibited::C21,
80 @Unicode::Stringprep::Prohibited::C22,
81 @Unicode::Stringprep::Prohibited::C3,
82 @Unicode::Stringprep::Prohibited::C4,
83 @Unicode::Stringprep::Prohibited::C5,
84 @Unicode::Stringprep::Prohibited::C6,
85 @Unicode::Stringprep::Prohibited::C7,
86 @Unicode::Stringprep::Prohibited::C8,
87 @Unicode::Stringprep::Prohibited::C9
91 # Section B.4
92 'KC',
97 # Section B.6
98 1);