App/Chart/Texinfo/Util.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 98.0% 51 / 52 CC 5 SCAR 7.4
CC
5
Cov
98%
_escape_char
3.0
node_to_html_anchor
3.0
BEGIN
1.0
CRAP 2.1
« App/Chart/Series/Derived/TypicalPrice.pm ↑ Summary App/Chart/Gtk2/Ex/CellRendererButton.pm »
1 # Copyright 2007, 2008, 2009, 2010, 2011, 2016 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17  
18 package App::Chart::Texinfo::Util;
19 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 @ISA = qw(Exporter);
26 1 @EXPORT_OK = qw(node_to_html_anchor);
27 1 %EXPORT_TAGS = (all => \@EXPORT_OK);
28  
29  
30 # Nodes "HTML Xref Node Name Expansion"
31 # and "HTML Xref 8-bit Character Expansion" in the Texinfo manual
32 # Given $node is wide-char.
33 #
34 7 ▶sub node_to_html_anchor {
Subroutine node_to_html_anchor: called CC=3 SCAR=11.0
Pod documented
35 7 my ($node) = @_;
36  
37 # precomposed characters where possible
38 7 ▶ if ($node =~ /[^[:ascii:]]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node =~ /[^[:ascii:]]/) 2 5 7
39 2 require Unicode::Normalize;
40 2 $node = Unicode::Normalize::NFC ($node);
41 }
42  
43 # rule 3 multiple space,tab,newline become one space
44 7 $node =~ s/[ \t\n]+/ /g;
45  
46 # rule 4 lose leading and trailing space
47 7 $node =~ s/^ +//;
48 7 $node =~ s/ +$//;
49  
50 # rule 6 chars except ascii alnum and the "-" (just inserted) become hex
51 7 $node =~ s/([^ A-Za-z0-9])/_escape_char($1)/ge;
52  
53 # rule 5 remaining spaces become dashes
54 7 $node =~ tr/ /-/;
55  
56 # rule 7 prepend "g_t" if doesn't begin with alpha
57 7 ▶ if ($node =~ /^[^A-Za-z]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node =~ /^[^A-Za-z]/) 3 4 7
58 3 $node = 'g_t' . $node;
59 }
60 7 return $node;
61 }
62 # ENHANCE-ME: For EBCDIC presumably a UTF-EBCDIC -> unicode conversion is
63 # needed here, instead of just ord().
64 16 ▶sub _escape_char {
Subroutine _escape_char: called CC=3 SCAR=11.0
65 16 my ($c) = @_; # single-char string
66 16 $c = ord($c);
67 16 ▶ if ($c <= 0xFFFF) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c <= 65535) { } 15 1 16
elsif ($c <= 16777215) { } 1 0 1
68 15 return sprintf ('_%04x', $c);
69 } elsif ($c <= 0xFF_FFFF) {
70 1 return sprintf ('__%06x', $c);
71 }
72 }
73  
74 1 1;
75 __END__
« App/Chart/Series/Derived/TypicalPrice.pm ↑ Summary App/Chart/Gtk2/Ex/CellRendererButton.pm »