File Coverage

blib/lib/Unicode/Properties.pm
Criterion Covered Total %
statement 24 31 77.4
branch 10 18 55.5
condition n/a
subroutine 5 6 83.3
pod 2 3 66.6
total 41 58 70.6


line stmt bran cond sub pod time code
1             package Unicode::Properties;
2              
3 1     1   14599 use warnings;
  1         1  
  1         28  
4 1     1   3 use strict;
  1         1  
  1         17  
5 1     1   848 use Unicode::UCD;
  1         191713  
  1         4661  
6              
7             require 5.008008;
8             require Exporter;
9             our @ISA = qw(Exporter);
10             our @EXPORT_OK= qw/uniprops matchchars/;
11             our %EXPORT_TAGS = (all => \@EXPORT_OK);
12              
13             our $VERSION = '0.07';
14              
15             my %propnames = qw/
16             Armenian 4.1.0
17             Balinese 5.0.0
18             Bengali 4.1.0
19             Bopomofo 4.1.0
20             Braille 4.1.0
21             Buginese 4.1.0
22             Buhid 4.1.0
23             CanadianAboriginal 4.1.0
24             Cherokee 4.1.0
25             Coptic 4.1.0
26             Cuneiform 5.0.0
27             Cypriot 4.1.0
28             Cyrillic 4.1.0
29             Deseret 4.1.0
30             Devanagari 4.1.0
31             Ethiopic 4.1.0
32             Georgian 4.1.0
33             Glagolitic 4.1.0
34             Gothic 4.1.0
35             Greek 4.1.0
36             Gujarati 4.1.0
37             Gurmukhi 4.1.0
38             Han 4.1.0
39             Hangul 4.1.0
40             Hanunoo 4.1.0
41             Hebrew 4.1.0
42             Hiragana 4.1.0
43             Inherited 4.1.0
44             Kannada 4.1.0
45             Katakana 4.1.0
46             Kharoshthi 4.1.0
47             Khmer 4.1.0
48             Lao 4.1.0
49             Latin 4.1.0
50             Limbu 4.1.0
51             LinearB 4.1.0
52             Malayalam 4.1.0
53             Mongolian 4.1.0
54             Myanmar 4.1.0
55             NewTaiLue 4.1.0
56             Nko 5.0.0
57             Ogham 4.1.0
58             OldItalic 4.1.0
59             OldPersian 4.1.0
60             Oriya 4.1.0
61             Osmanya 4.1.0
62             PhagsPa 5.0.0
63             Phoenician 5.0.0
64             Runic 4.1.0
65             Shavian 4.1.0
66             Sinhala 4.1.0
67             SylotiNagri 4.1.0
68             Syriac 4.1.0
69             Tagalog 4.1.0
70             Tagbanwa 4.1.0
71             TaiLe 4.1.0
72             Tamil 4.1.0
73             Telugu 4.1.0
74             Thaana 4.1.0
75             Thai 4.1.0
76             Tibetan 4.1.0
77             Tifinagh 4.1.0
78             Ugaritic 4.1.0
79             Yi 4.1.0
80             InAegeanNumbers 4.1.0
81             InAlphabeticPresentationForms 4.1.0
82             InAncientGreekMusicalNotation 4.1.0
83             InAncientGreekNumbers 4.1.0
84             InArabic 4.1.0
85             InArabicPresentationFormsA 4.1.0
86             InArabicPresentationFormsB 4.1.0
87             InArabicSupplement 4.1.0
88             InArmenian 4.1.0
89             InArrows 4.1.0
90             InBalinese 5.0.0
91             InBasicLatin 4.1.0
92             InBengali 4.1.0
93             InBlockElements 4.1.0
94             InBopomofo 4.1.0
95             InBopomofoExtended 4.1.0
96             InBoxDrawing 4.1.0
97             InBraillePatterns 4.1.0
98             InBuginese 4.1.0
99             InBuhid 4.1.0
100             InByzantineMusicalSymbols 4.1.0
101             InCJKCompatibility 4.1.0
102             InCJKCompatibilityForms 4.1.0
103             InCJKCompatibilityIdeographs 4.1.0
104             InCJKCompatibilityIdeographsSupplement 4.1.0
105             InCJKRadicalsSupplement 4.1.0
106             InCJKStrokes 4.1.0
107             InCJKSymbolsAndPunctuation 4.1.0
108             InCJKUnifiedIdeographs 4.1.0
109             InCJKUnifiedIdeographsExtensionA 4.1.0
110             InCJKUnifiedIdeographsExtensionB 4.1.0
111             InCherokee 4.1.0
112             InCombiningDiacriticalMarks 4.1.0
113             InCombiningDiacriticalMarksSupplement 4.1.0
114             InCombiningDiacriticalMarksforSymbols 4.1.0
115             InCombiningHalfMarks 4.1.0
116             InControlPictures 4.1.0
117             InCoptic 4.1.0
118             InCountingRodNumerals 5.0.0
119             InCuneiform 5.0.0
120             InCuneiformNumbersAndPunctuation 5.0.0
121             InCurrencySymbols 4.1.0
122             InCypriotSyllabary 4.1.0
123             InCyrillic 4.1.0
124             InCyrillicSupplement 4.1.0
125             InDeseret 4.1.0
126             InDevanagari 4.1.0
127             InDingbats 4.1.0
128             InEnclosedAlphanumerics 4.1.0
129             InEnclosedCJKLettersAndMonths 4.1.0
130             InEthiopic 4.1.0
131             InEthiopicExtended 4.1.0
132             InEthiopicSupplement 4.1.0
133             InGeneralPunctuation 4.1.0
134             InGeometricShapes 4.1.0
135             InGeorgian 4.1.0
136             InGeorgianSupplement 4.1.0
137             InGlagolitic 4.1.0
138             InGothic 4.1.0
139             InGreekExtended 4.1.0
140             InGreekAndCoptic 4.1.0
141             InGujarati 4.1.0
142             InGurmukhi 4.1.0
143             InHalfwidthAndFullwidthForms 4.1.0
144             InHangulCompatibilityJamo 4.1.0
145             InHangulJamo 4.1.0
146             InHangulSyllables 4.1.0
147             InHanunoo 4.1.0
148             InHebrew 4.1.0
149             InHighPrivateUseSurrogates 4.1.0
150             InHighSurrogates 4.1.0
151             InHiragana 4.1.0
152             InIPAExtensions 4.1.0
153             InIdeographicDescriptionCharacters 4.1.0
154             InKanbun 4.1.0
155             InKangxiRadicals 4.1.0
156             InKannada 4.1.0
157             InKatakana 4.1.0
158             InKatakanaPhoneticExtensions 4.1.0
159             InKharoshthi 4.1.0
160             InKhmer 4.1.0
161             InKhmerSymbols 4.1.0
162             InLao 4.1.0
163             InLatin1Supplement 4.1.0
164             InLatinExtendedA 4.1.0
165             InLatinExtendedAdditional 4.1.0
166             InLatinExtendedB 4.1.0
167             InLatinExtendedC 5.0.0
168             InLatinExtendedD 5.0.0
169             InLetterlikeSymbols 4.1.0
170             InLimbu 4.1.0
171             InLinearBIdeograms 4.1.0
172             InLinearBSyllabary 4.1.0
173             InLowSurrogates 4.1.0
174             InMalayalam 4.1.0
175             InMathematicalAlphanumericSymbols 4.1.0
176             InMathematicalOperators 4.1.0
177             InMiscellaneousMathematicalSymbolsA 4.1.0
178             InMiscellaneousMathematicalSymbolsB 4.1.0
179             InMiscellaneousSymbols 4.1.0
180             InMiscellaneousSymbolsAndArrows 4.1.0
181             InMiscellaneousTechnical 4.1.0
182             InModifierToneLetters 4.1.0
183             InMongolian 4.1.0
184             InMusicalSymbols 4.1.0
185             InMyanmar 4.1.0
186             InNKo 5.0.0
187             InNewTaiLue 4.1.0
188             InNumberForms 4.1.0
189             InOgham 4.1.0
190             InOldItalic 4.1.0
191             InOldPersian 4.1.0
192             InOpticalCharacterRecognition 4.1.0
193             InOriya 4.1.0
194             InOsmanya 4.1.0
195             InPhagspa 5.0.0
196             InPhoenician 5.0.0
197             InPhoneticExtensions 4.1.0
198             InPhoneticExtensionsSupplement 4.1.0
199             InPrivateUseArea 4.1.0
200             InRunic 4.1.0
201             InShavian 4.1.0
202             InSinhala 4.1.0
203             InSmallFormVariants 4.1.0
204             InSpacingModifierLetters 4.1.0
205             InSpecials 4.1.0
206             InSuperscriptsAndSubscripts 4.1.0
207             InSupplementalArrowsA 4.1.0
208             InSupplementalArrowsB 4.1.0
209             InSupplementalMathematicalOperators 4.1.0
210             InSupplementalPunctuation 4.1.0
211             InSupplementaryPrivateUseAreaA 4.1.0
212             InSupplementaryPrivateUseAreaB 4.1.0
213             InSylotiNagri 4.1.0
214             InSyriac 4.1.0
215             InTagalog 4.1.0
216             InTagbanwa 4.1.0
217             InTags 4.1.0
218             InTaiLe 4.1.0
219             InTaiXuanJingSymbols 4.1.0
220             InTamil 4.1.0
221             InTelugu 4.1.0
222             InThaana 4.1.0
223             InThai 4.1.0
224             InTibetan 4.1.0
225             InTifinagh 4.1.0
226             InUgaritic 4.1.0
227             InUnifiedCanadianAboriginalSyllabics 4.1.0
228             InVariationSelectors 4.1.0
229             InVariationSelectorsSupplement 4.1.0
230             InVerticalForms 4.1.0
231             InYiRadicals 4.1.0
232             InYiSyllables 4.1.0
233             InYijingHexagramSymbols 4.1.0
234             Alphabetic 4.1.0
235             Lowercase 4.1.0
236             Uppercase 4.1.0
237             Math 4.1.0
238             IDStart 4.1.0
239             IDContinue 4.1.0
240             DefaultIgnorableCodePoint 5.0.0
241             Any 4.1.0
242             Assigned 4.1.0
243             Unassigned 4.1.0
244             ASCII 4.1.0
245             Common 4.1.0
246             /;
247              
248             # Compare 4.1.0 with 5.0.0
249              
250             our $unicode_version = Unicode::UCD::UnicodeVersion();
251             my @uv = split /\./, $unicode_version;
252              
253             sub versionok
254             {
255 2301     2301 0 2269 my ($version) = @_;
256             # print "$version, $unicode_version\n";
257 2301         3339 my @v = split /\./, $version;
258             # print "\@v = @v\n";
259 2301         3228 for (0..2) {
260 2301 50       3984 return undef if $v[$_] > $uv[$_];
261 2301 50       6204 return 1 if $v[$_] < $uv[$_];
262             }
263 0         0 return 1; # equal
264             }
265              
266             sub uniprops
267             {
268 11     11 1 31 my ($inchar) = @_;
269 11 100       32 return if !$inchar;
270 10 100       25 if (length ($inchar) != 1) {
271 2         7 $inchar = substr ($inchar, 0, 1);
272             }
273 10         10 my @matched;
274 10         864 for my $block (sort keys %propnames) {
275             # print "Version $propnames{$block} is ",
276             # versionok ($propnames{$block}) ? "OK" : "Not OK", "\n";
277 2300 50       135647 next unless versionok $propnames{$block};
278 2300 100       19328 if ($inchar =~ /^\p{$block}$/) {
279 72         6848 push @matched, $block;
280             }
281             }
282 10 50       838 return wantarray ? @matched : \@matched;
283             }
284              
285             sub matchchars
286             {
287 0     0 1   my ($re) = @_;
288 0 0         if ($propnames{$re}) {
289 0           $re = "\\p{$re}";
290             }
291 0           my @matches = grep { chr ($_) =~ /$re/ }
  0            
292             (0x00 .. 0xD7FF, 0xE000 .. 0xFDCF, 0xFDF0.. 0xFFFD);
293 0 0         return wantarray ? @matches : \@matches;
294             }
295              
296             1;
297