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