File Coverage

blib/lib/App/Asciio/String.pm
Criterion Covered Total %
statement 15 33 45.4
branch 0 4 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 44 45.4


line stmt bran cond sub pod time code
1              
2             package App::Asciio::String ;
3              
4             require Exporter ;
5             @ISA = qw(Exporter) ;
6             @EXPORT = qw(
7             unicode_length
8             make_vertical_text
9             ) ;
10              
11             #-----------------------------------------------------------------------------
12              
13 4     4   31 use strict ; use warnings ;
  4     4   6  
  4         168  
  4         21  
  4         7  
  4         264  
14 4     4   25 use utf8 ;
  4         8  
  4         24  
15              
16 4     4   2809 use App::Asciio::Markup ;
  4         13  
  4         653  
17              
18             #-----------------------------------------------------------------------------
19              
20 4     4   34 use Memoize ;
  4         8  
  4         3052  
21             memoize('unicode_length') ;
22              
23             sub unicode_length
24             {
25             my ($string) = @_ ;
26              
27             $string = $USE_MARKUP_CLASS->delete_markup_characters($string) ;
28              
29             my $east_asian_double_width_chars_cnt = grep {$_ =~ /\p{EA=W}|\p{EA=F}/} split('', $string) ;
30             my $nonspacing_chars_cnt = grep {$_ =~ /\p{gc:Mn}/} split('', $string) ;
31              
32             return length($string) + $east_asian_double_width_chars_cnt - $nonspacing_chars_cnt ;
33             }
34              
35             #-----------------------------------------------------------------------------
36              
37             sub make_vertical_text
38             {
39 0     0 0   my ($text) = @_ ;
40              
41 0           my @lines = map{[split '', $_]} split "\n", $text ;
  0            
42              
43 0           my $vertical = '' ;
44 0           my $found_character = 1 ;
45 0           my $index = 0 ;
46              
47 0           while($found_character)
48             {
49 0           my $line ;
50 0           $found_character = 0 ;
51            
52 0           for(@lines)
53             {
54 0 0         if(defined $_->[$index])
55             {
56 0           $line.= $_->[$index] ;
57 0           $found_character++ ;
58             }
59             else
60             {
61 0           $line .= ' ' ;
62             }
63             }
64            
65 0           $line =~ s/\s+$//;
66 0 0         $vertical .= "$line\n" if $found_character ;
67 0           $index++ ;
68             }
69              
70 0           return $vertical ;
71             }
72              
73             #-----------------------------------------------------------------------------
74              
75             1 ;