File Coverage

blib/lib/Lingua/JA/Halfwidth.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Lingua::JA::Halfwidth;
2              
3 2     2   874 use warnings;
  2         5  
  2         115  
4 2     2   10 use strict;
  2         2  
  2         55  
5 2     2   12 use Carp;
  2         4  
  2         154  
6 2     2   10 use base qw(Exporter);
  2         2  
  2         190  
7              
8             our $VERSION = '0.0.6';
9              
10             our @EXPORT = qw(is_japanese_halfwidth);
11              
12             sub is_japanese_halfwidth {
13 240     240 1 803 my $str = shift;
14 240 100       592 if ( $str =~ /[\x{FF61}-\x{FF9F}]/ ) {
15 63         167 return 1;
16             }
17             else {
18 177         409 return 0;
19             }
20             }
21              
22             1;
23              
24             __END__
25              
26             =encoding utf-8
27              
28             =head1 NAME
29              
30             Lingua::JA::Halfwidth - judge given single character is japanese halfwidth or not
31              
32             =head1 SYNOPSIS
33              
34             use strict;
35             use warnings;
36             use Lingua::JA::Halfwidth;
37             use Encode qw(encode_utf8);
38             use utf8;
39            
40             my $string = qw/aあウ9波ヲ/;
41             for (split //, $string) {
42             print encode_utf8($_), ": ";
43             print is_japanese_halfwidth($_), "\n";
44             }
45            
46             # a: 0
47             # あ: 0
48             # ï½³: 1
49             # ï¼™: 0
50             # æ³¢: 0
51             # ヲ: 1
52              
53             =head1 DESCRIPTION
54              
55             This module is aimed to check easily whether given single character is japanese halfwidth or not.
56              
57             Target characters are japanese halfwidth katakana, punctuation, voice marks and bracket.
58             (See also t/01.is_japanese_halfwidth.t)
59              
60             Unicode block is very useful.
61             When judging japanese halfwidth katakana and character used japanese halfwidth, we use \p{InHalfwidthAndFullwidthForms}.
62             But, this unicode block contains fullwidth number and so on...
63              
64             So, I made this module :-)
65              
66             =head1 METHODS
67              
68             =head2 is_japanese_halfwidth
69            
70             is_japanese_halfwidth($str);
71              
72             This method can judge given single character is japanese halfwidth or not.
73             Return value is 1 (japanese halfwidth) or 0 (not japanese halfwidth).
74              
75             =head1 AUTHOR
76              
77             sasata299 C<< <sasata299@livedoor.com> >>
78              
79             http://blog.livedoor.jp/sasata299/
80              
81             =head1 LICENCE AND COPYRIGHT
82              
83             Copyright (c) 2009, sasata299 C<< <sasata299@livedoor.com> >>. All rights reserved.
84              
85             This module is free software; you can redistribute it and/or
86             modify it under the same terms as Perl itself. See L<perlartistic>.
87              
88             =cut