« blib/lib/Text/NumericData/App/txdfromtcad.pm
↑ Summary
blib/lib/Text/NumericData/App/txdextrema.pm »
| 1 | package Text::NumericData; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # TODO: optimize those regexes, compile once in constructor | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # major.minor.bugfix, the latter two with 3 digits each | ||||||||||||||||||||||||||||
| 9 | # It's not pretty, but I gave up on 1.2.3 style. | ||||||||||||||||||||||||||||
| 10 | 14 | our $VERSION = '2.004000'; | |||||||||||||||||||||||||||
| 11 | 14 | our $version = $VERSION; | |||||||||||||||||||||||||||
| 12 | 14 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 14 | our $years = '2005-2023'; | |||||||||||||||||||||||||||
| 15 | 14 | our $copyright = 'Copyright (c) '.$years.' Thomas Orgis, Free Software licensed under the same terms as Perl 5.10'; | |||||||||||||||||||||||||||
| 16 | 14 | our $author = 'Thomas Orgis <thomas@orgis.org>'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # TODO: More smarts in separator search. | ||||||||||||||||||||||||||||
| 19 | # One should find ', ' as separator in | ||||||||||||||||||||||||||||
| 20 | # a / c, d /e | ||||||||||||||||||||||||||||
| 21 | 14 | my $newhite = '[^\S\015\012]'; # whitespace that is no line end character | |||||||||||||||||||||||||||
| 22 | 14 | my $trenner = $newhite.'+|,'.$newhite.'*|;'.$newhite.'*'; | |||||||||||||||||||||||||||
| 23 | 14 | my $ntrenner = '[^\s,;]+'; # also excludes CR LF | |||||||||||||||||||||||||||
| 24 | 14 | my $lend = '[\012\015]+'; | |||||||||||||||||||||||||||
| 25 | 14 | my $nlend = '[^\012\015]'; | |||||||||||||||||||||||||||
| 26 | 14 | my $quotematch = "['\"]"; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 14 | my %endname = ("\015\012"=>'DOS', "\012"=>'UNIX', "\015"=>'MAC'); | |||||||||||||||||||||||||||
| 29 | 14 | my %endstring = reverse %endname; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Fallback defaults if anything else fails. | ||||||||||||||||||||||||||||
| 32 | 14 | our $default_sep = "\t"; | |||||||||||||||||||||||||||
| 33 | 14 | our $default_eol = $/; | |||||||||||||||||||||||||||
| 34 | 14 | our $default_comchar = '#'; | |||||||||||||||||||||||||||
| 35 | 14 | our $default_quote = 1; | |||||||||||||||||||||||||||
| 36 | 14 | our $default_quotechar = '"'; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | our %help = | ||||||||||||||||||||||||||||
| 39 | ( | ||||||||||||||||||||||||||||
| 40 | separator=>'use this separator for input (otherwise deduce from data; TAB is another way to say "tabulator", fallback is'.$default_sep.')' | ||||||||||||||||||||||||||||
| 41 | ,outsep=>'use this separator for output (leave undefined to use input separator, fallback to '.($default_sep eq "\t" ? 'TAB' : $default_sep).')' | ||||||||||||||||||||||||||||
| 42 | 14 | ▶ | ,lineend=>'line ending to use: ('.join(', ', sort keys %endstring).' or be explicit if you can, taken from data if undefined, finally resorting to '.(defined $endname{$default_eol} ? $endname{$default_eol} : $default_eol).')' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | ,comchar=>'comment character (if not set, deduce from data or use '.$default_comchar.')' | ||||||||||||||||||||||||||||
| 44 | ,numregex=>'regex for matching numbers' | ||||||||||||||||||||||||||||
| 45 | ,numformat=>'printf formats to use (if there is no "%" present at all, one will be prepended)' | ||||||||||||||||||||||||||||
| 46 | ,comregex=>'regex for matching comments' | ||||||||||||||||||||||||||||
| 47 | ,quote=>'quote titles' | ||||||||||||||||||||||||||||
| 48 | ,quotechar=>'quote character to use (derived from input or '.$default_quotechar.')' | ||||||||||||||||||||||||||||
| 49 | ,strict=>'strictly split data lines at configured separator (otherwise more fuzzy logic is involved)' | ||||||||||||||||||||||||||||
| 50 | ,text=>'allow text as data (not first column)' | ||||||||||||||||||||||||||||
| 51 | ,fill=>'fill value for undefined data' | ||||||||||||||||||||||||||||
| 52 | ,black=>'ignore whitespace at beginning and end of line (disables strict mode)' | ||||||||||||||||||||||||||||
| 53 | ,empty=>'treat empty lines as empty data sets, preserving them in output' | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # These are defaults for user settings. | ||||||||||||||||||||||||||||
| 57 | 14 | our %defaults = | |||||||||||||||||||||||||||
| 58 | ( | ||||||||||||||||||||||||||||
| 59 | 'separator',undef, | ||||||||||||||||||||||||||||
| 60 | 'outsep', undef, | ||||||||||||||||||||||||||||
| 61 | 'lineend', undef, | ||||||||||||||||||||||||||||
| 62 | 'comchar', undef, | ||||||||||||||||||||||||||||
| 63 | 'numregex', '[\+\-]?\d*\.?\d*[eE]?\+?\-?\d*', | ||||||||||||||||||||||||||||
| 64 | 'numformat',[], | ||||||||||||||||||||||||||||
| 65 | 'comregex','[#%]*'.$newhite.'*', | ||||||||||||||||||||||||||||
| 66 | 'quote',undef, | ||||||||||||||||||||||||||||
| 67 | 'quotechar',undef, | ||||||||||||||||||||||||||||
| 68 | 'strict', 0, | ||||||||||||||||||||||||||||
| 69 | 'text', 1 | ||||||||||||||||||||||||||||
| 70 | ,'fill',undef # a value to fill in for non-existent but still demanded data | ||||||||||||||||||||||||||||
| 71 | ,'black', 0 | ||||||||||||||||||||||||||||
| 72 | ,'empty',0 | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub new | ||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 60 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 60 | my $self = {}; | |||||||||||||||||||||||||||
| 79 | 60 | bless $self, $class; | |||||||||||||||||||||||||||
| 80 | # Only pick the parts of the config hash that are of interest here. | ||||||||||||||||||||||||||||
| 81 | 60 | my $gotconf = shift; | |||||||||||||||||||||||||||
| 82 | 60 | $self->{gotconfig} = {}; | |||||||||||||||||||||||||||
| 83 | 60 | for my $n (keys %defaults) | |||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | 840 | ▶ | if(ref $gotconf->{$n}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | 58 | $self->{gotconfig}{$n} = dclone($gotconf->{$n}); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 782 | $self->{gotconfig}{$n} = $gotconf->{$n}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 60 | foreach my $n (@{$self->{gotconfig}->{numformat}}) | |||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 41 | ▶ | $n = '%'.$n unless $n =~ /\%/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | # Expand named special characters for line ending. | ||||||||||||||||||||||||||||
| 99 | 60 | ▶ | if(defined $gotconf->{lineend}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | $self->{gotconfig}{lineend} = defined $endstring{$gotconf->{lineend}} | ||||||||||||||||||||||||||||
| 102 | ? $endstring{$gotconf->{lineend}} | ||||||||||||||||||||||||||||
| 103 | 37 | ▶ | : $gotconf->{lineend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 60 | for (qw(separator outsep)) | |||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||
| 107 | 120 | ▶ | if(defined $gotconf->{$_} and $gotconf->{$_} eq 'TAB'){ $self->{gotconfig}{$_} = "\t"; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $gotconf->{$_} and $gotconf->{$_} eq "TAB"
MC/DC100%2/2
defined $gotconf->{$_} and $gotconf->{$_} eq "TAB"
defined $gotconf->{$_}
$gotconf->{$_} eq "TAB"
Truth table100%3/3
A and B
A= defined $gotconf->{$_}B= $gotconf->{$_} eq "TAB"
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | $self->{gotconfig}{strict} = 0 | ||||||||||||||||||||||||||||
| 111 | 60 | ▶ | if $self->{gotconfig}{black}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 60 | $self->init(); | |||||||||||||||||||||||||||
| 113 | 60 | return $self; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub init | ||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||
| 118 | 77 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 77 | %{$self->{config}} = %{$self->{gotconfig}}; | |||||||||||||||||||||||||||
| 120 | 77 | $self->{comments} = []; #some comment in header | |||||||||||||||||||||||||||
| 121 | 77 | $self->{guessquote} = undef; | |||||||||||||||||||||||||||
| 122 | 77 | $self->{titles} = []; #column titles | |||||||||||||||||||||||||||
| 123 | 77 | $self->{title} = undef; #file title | |||||||||||||||||||||||||||
| 124 | 77 | foreach my $k ('numregex','numformat','comregex','fill') | |||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 308 | ▶ | $self->{config}{$k} = $defaults{$k} unless defined $self->{config}{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | # Strict mode needs some set separator. | ||||||||||||||||||||||||||||
| 129 | 77 | ▶ | if($self->{config}{strict} and not defined $self->{config}{separator}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"config"}{"strict"} and not defined $self->{"config"}{"separator"}
MC/DC100%2/2
$self->{"config"}{"strict"} and not defined $self->{"config"}{"separator"}
$self->{"config"}{"strict"}
not defined $self->{"config"}{"separator"}
Truth table100%3/3
A and not(B)
A= $self->{"config"}{"strict"}B= not defined $self->{"config"}{"separator"}
| |||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | 1 | $self->{config}{separator} = $default_sep; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | #line_check($line, $onlycheck) | ||||||||||||||||||||||||||||
| 136 | #$onlycheck: 0/undef: do full search for file/line titles and line end, etc. | ||||||||||||||||||||||||||||
| 137 | # 1: only determine if data or not | ||||||||||||||||||||||||||||
| 138 | sub line_check #return 1 and set separator and line ending if data line and 0 otherwise | ||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||
| 140 | 101 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
line_check: called CC=40 SCAR=40.1
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | # temporary hack until fully switching to value instead of ref, which is a ref anyway | ||||||||||||||||||||||||||||
| 142 | 101 | ▶ | my $lr = ref $_[0] ? $_[0] : \$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 101 | my $oc = $_[1]; | |||||||||||||||||||||||||||
| 144 | 101 | my $zahl = $self->{config}{numregex}; | |||||||||||||||||||||||||||
| 145 | 101 | my $seppl = $trenner; | |||||||||||||||||||||||||||
| 146 | 101 | ▶ | $seppl = $self->{config}{separator} if $self->{config}{strict}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | #the leading whitespace is a workaround for TISEAN | ||||||||||||||||||||||||||||
| 148 | #good or bad? It should not break any files that worked before... | ||||||||||||||||||||||||||||
| 149 | 101 | ▶ | if( ${$lr} =~ /^\s*$/ and ${$lr} =~ /^($nlend*)($lend)$/o ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
${$lr;} =~ /^\s*$/ and ${$lr;} =~ /^($nlend*)($lend)$/o
MC/DC50%1/2
${$lr;} =~ /^\s*$/ and ${$lr;} =~ /^($nlend*)($lend)$/o
${$lr;} =~ /^\s*$/
${$lr;} =~ /^($nlend*)($lend)$/o
Truth table66%2/3
A and B
A= ${$lr;} =~ /^\s*$/B= ${$lr;} =~ /^($nlend*)($lend)$/o
| |||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||
| 151 | 2 | ▶ | $self->{config}{lineend} = $2 unless defined $self->{config}{lineend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | # An empty line counts as comment when it comes after a title. | ||||||||||||||||||||||||||||
| 153 | 2 | push(@{$self->{comments}},$1) | |||||||||||||||||||||||||||
| 154 | 2 | ▶ | if defined $self->{title}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 2 | return 0; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 99 | ▶ | if(${$lr} =~ /^\s*($zahl)(($seppl)$nlend*|)($lend)$/) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | 41 | my ($num, $end, $sep) = ($1, $4, $3); | |||||||||||||||||||||||||||
| 160 | 41 | my $piece = $1.$2; | |||||||||||||||||||||||||||
| 161 | 41 | ▶ | unless(not defined $end or defined $self->{config}{lineend}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $end or defined $self->{"config"}{"lineend"}
MC/DC50%1/2
not defined $end or defined $self->{"config"}{"lineend"}
not defined $end
defined $self->{"config"}{"lineend"}
Truth table66%2/3
not(A) or B
A= not defined $endB= defined $self->{"config"}{"lineend"}
| |||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||
| 163 | 1 | $self->{config}{lineend} = $end; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 41 | ▶ | unless($self->{config}{text}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | # If text is not allowed, we strictly only want | ||||||||||||||||||||||||||||
| 168 | # numbers and separators and line end. | ||||||||||||||||||||||||||||
| 169 | # Let's get expensive: Remove everything we know. if there is something | ||||||||||||||||||||||||||||
| 170 | # left, we got text. | ||||||||||||||||||||||||||||
| 171 | 2 | my $linecopy = ${$lr}; | |||||||||||||||||||||||||||
| 172 | 2 | $linecopy =~ s/$seppl//g; | |||||||||||||||||||||||||||
| 173 | 2 | $linecopy =~ s/($zahl|\s+|$lend)//g; | |||||||||||||||||||||||||||
| 174 | 2 | ▶ | if($linecopy ne '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||
| 176 | 1 | ▶ | if( defined $self->{title} ){ push(@{$self->{comments}},$piece); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | else{ $self->{title} = $piece; } | |||||||||||||||||||||||||||
| 178 | 1 | return 0; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | # sanity check for loosened definition of number... at least one digit shall be there | ||||||||||||||||||||||||||||
| 182 | 40 | ▶ | if($num =~ /\d/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||
| 184 | 40 | ▶ | unless(not defined $sep or defined $self->{config}{separator}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $sep or defined $self->{"config"}{"separator"}
MC/DC100%2/2
not defined $sep or defined $self->{"config"}{"separator"}
not defined $sep
defined $self->{"config"}{"separator"}
Truth table100%3/3
not(A) or B
A= not defined $sepB= defined $self->{"config"}{"separator"}
| |||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||
| 186 | 33 | $self->{config}{separator} = $sep; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 40 | ▶ | if($#{$self->{comments}} > -1 and $#{$self->{titles}} > -1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$#{$$self{"comments"};} > -1 and $#{$$self{"titles"};} > -1
MC/DC50%1/2
$#{$$self{"comments"};} > -1 and $#{$$self{"titles"};} > -1
$#{$$self{"comments"};} > -1
$#{$$self{"titles"};} > -1
Truth table66%2/3
A and B
A= $#{$$self{"comments"};} > -1B= $#{$$self{"titles"};} > -1
| |||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||
| 190 | 23 | pop(@{$self->{comments}}); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 40 | return 1; # Yeah, found a number line. | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 0 | elsif($oc){ return 0; } | |||||||||||||||||||||||||||
| 196 | else | ||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 58 | ▶ | if(${$lr} =~ /^($self->{config}{comregex})($lend)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | $self->{config}{comchar} = $1 | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | unless defined $self->{config}{comchar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | $self->{config}{lineend} = $2 | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | unless defined $self->{config}{lineend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | return 0; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | #first non-empty line is some kind of title or comment | ||||||||||||||||||||||||||||
| 207 | #first means: we didn't have content up to now | ||||||||||||||||||||||||||||
| 208 | 58 | ▶ | if(${$lr} =~ /^($self->{config}{comregex})($nlend+)($lend)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||
| 210 | 58 | ▶ | if( defined $self->{title} ){ push(@{$self->{comments}},$2); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 25 | else{ $self->{title} = $2; } | |||||||||||||||||||||||||||
| 212 | $self->{config}{lineend} = $3 | ||||||||||||||||||||||||||||
| 213 | 58 | ▶ | unless defined $self->{config}{lineend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | $self->{config}{comchar} = $1 | ||||||||||||||||||||||||||||
| 215 | 58 | ▶ | unless defined $self->{config}{comchar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | #attention: I take " or ' just as quotes, do distinction! | ||||||||||||||||||||||||||||
| 218 | 58 | my $quote = $self->{config}{quotechar}; | |||||||||||||||||||||||||||
| 219 | 58 | ▶ | $quote = $quotematch | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | unless defined $quote; | ||||||||||||||||||||||||||||
| 221 | 58 | ▶ | if(${$lr} =~ /^($self->{config}{comregex})($quote)($nlend*\2($seppl)\2*$nlend*)\2*($lend)$/) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | $self->{config}{quote} = 1 | ||||||||||||||||||||||||||||
| 224 | 20 | ▶ | unless defined $self->{config}{quote}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | $self->{config}{quotechar} = $2 | ||||||||||||||||||||||||||||
| 226 | 20 | ▶ | unless defined $self->{config}{quotechar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | # "axis title"\t"axis title"\t"..." | ||||||||||||||||||||||||||||
| 228 | # allow flexible space in separator | ||||||||||||||||||||||||||||
| 229 | 20 | my $sep = $4; | |||||||||||||||||||||||||||
| 230 | 20 | my $q = $2; | |||||||||||||||||||||||||||
| 231 | 20 | my $rest = $3; | |||||||||||||||||||||||||||
| 232 | 20 | $rest =~ s:$q$::; | |||||||||||||||||||||||||||
| 233 | $sep =~ s:\s+$:\\s+: | ||||||||||||||||||||||||||||
| 234 | 20 | ▶ | unless($self->{config}{strict}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 20 | my @ax = split($q.$sep.$q,$rest); | |||||||||||||||||||||||||||
| 236 | 20 | $self->{titles} = \@ax; | |||||||||||||||||||||||||||
| 237 | $self->{config}{lineend} = $5 | ||||||||||||||||||||||||||||
| 238 | 20 | ▶ | unless defined $self->{config}{lineend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | $self->{config}{comchar} = $1 | ||||||||||||||||||||||||||||
| 240 | 20 | ▶ | unless defined $self->{config}{comchar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | #either no quotes at all or maybe quotes but single item without separator | ||||||||||||||||||||||||||||
| 243 | 38 | elsif(${$lr} =~ /^($self->{config}{comregex})($quote?)($nlend*)($lend)$/) | |||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||
| 245 | 38 | ▶ | if($2 ne '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||
| 247 | $self->{config}{quotechar} = $2 | ||||||||||||||||||||||||||||
| 248 | 0 | ▶ | unless defined $self->{config}{quotechar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | $self->{config}{quote} = 1 | ||||||||||||||||||||||||||||
| 250 | 0 | ▶ | unless defined $self->{config}{quote}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | else | ||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||
| 254 | 38 | $self->{guessquote} = 0 | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | $self->{config}{lineend} = $4 | ||||||||||||||||||||||||||||
| 257 | 38 | ▶ | unless defined $self->{config}{lineend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | $self->{config}{comchar} = $1 | ||||||||||||||||||||||||||||
| 259 | 38 | ▶ | unless defined $self->{config}{comchar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 38 | my $d = $3; | |||||||||||||||||||||||||||
| 261 | 38 | $d =~ s/$quote$//; | |||||||||||||||||||||||||||
| 262 | 38 | my @ax = (); | |||||||||||||||||||||||||||
| 263 | 38 | ▶ | if($d =~ /($seppl)/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||
| 265 | 24 | @ax = split($1, $d); | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | 14 | else{ @ax = ($d); } | |||||||||||||||||||||||||||
| 268 | 38 | $self->{titles} = \@ax; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | 58 | return 0; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | sub get_insep | ||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||
| 276 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_insep: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 277 | return defined $self->{config}{separator} | ||||||||||||||||||||||||||||
| 278 | ? $self->{config}{separator} | ||||||||||||||||||||||||||||
| 279 | 3 | ▶ | : $default_sep; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | sub get_outsep | ||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||
| 284 | 1922 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_outsep: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 285 | return defined $self->{config}{outsep} | ||||||||||||||||||||||||||||
| 286 | ? $self->{config}{outsep} | ||||||||||||||||||||||||||||
| 287 | : ( | ||||||||||||||||||||||||||||
| 288 | defined $self->{config}{separator} | ||||||||||||||||||||||||||||
| 289 | ? $self->{config}{separator} | ||||||||||||||||||||||||||||
| 290 | 1922 | ▶ | : $default_sep | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | sub get_end | ||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||
| 296 | 2709 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_end: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 297 | return defined $self->{config}{lineend} | ||||||||||||||||||||||||||||
| 298 | ? $self->{config}{lineend} | ||||||||||||||||||||||||||||
| 299 | 2709 | ▶ | : $default_eol; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | sub get_quote | ||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||
| 304 | 25 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_quote: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 305 | my $want = defined $self->{config}{quote} | ||||||||||||||||||||||||||||
| 306 | ? $self->{config}{quote} | ||||||||||||||||||||||||||||
| 307 | : ( defined $self->{guessquote} | ||||||||||||||||||||||||||||
| 308 | ? $self->{guessquote} | ||||||||||||||||||||||||||||
| 309 | 25 | ▶ | : $default_quote ); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 310 | return $want | ||||||||||||||||||||||||||||
| 311 | ? ( defined $self->{config}{quotechar} | ||||||||||||||||||||||||||||
| 312 | ? $self->{config}{quotechar} | ||||||||||||||||||||||||||||
| 313 | 25 | ▶ | : $default_quotechar ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 314 | : ''; | ||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | sub get_comchar | ||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||
| 319 | 809 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_comchar: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 320 | return defined $self->{config}{comchar} | ||||||||||||||||||||||||||||
| 321 | ? $self->{config}{comchar} | ||||||||||||||||||||||||||||
| 322 | 809 | ▶ | : $default_comchar; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | sub line_data | ||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||
| 327 | 1456 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
line_data: called CC=11 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||
| 328 | 1456 | ▶ | my $lr = ref $_[0] ? $_[0] : \$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 1456 | my @ar = (); | |||||||||||||||||||||||||||
| 330 | 1456 | my $zahl = $self->{config}{numregex}; | |||||||||||||||||||||||||||
| 331 | # empty lines | ||||||||||||||||||||||||||||
| 332 | 1456 | ▶ | return ($self->{config}{empty} ? [] : undef) if(${$lr} =~ /^$lend$/); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 333 | 1456 | ▶ | if($self->{config}{strict}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | #just split with defined or found separator | ||||||||||||||||||||||||||||
| 336 | 3 | @ar = split($self->get_insep(), ${$lr}); | |||||||||||||||||||||||||||
| 337 | #remove line end | ||||||||||||||||||||||||||||
| 338 | 3 | ▶ | if($#ar > -1){ $ar[$#ar] =~ s/$lend//o; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | else | ||||||||||||||||||||||||||||
| 341 | { | ||||||||||||||||||||||||||||
| 342 | 1453 | my $l = ${$lr}; | |||||||||||||||||||||||||||
| 343 | 1453 | ▶ | if($self->{config}{black}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||
| 345 | 3 | $l =~ s/^\s*//; | |||||||||||||||||||||||||||
| 346 | # s/\s*$// deletes the line end -- no problem here | ||||||||||||||||||||||||||||
| 347 | 3 | $l =~ s/\s*$//; | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | 1453 | ▶ | if($l =~ /^($zahl)(.*)$/){ push(@ar, $1); $l = $2; }else{ return undef; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 1453 | ▶ | unless($self->{config}{text}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | { | ||||||||||||||||||||||||||||
| 352 | 3 | ▶ | while($l =~ /^($trenner)($zahl)(.*)$/o) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||
| 354 | 6 | push(@ar, $2); | |||||||||||||||||||||||||||
| 355 | 6 | $l = $3; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | else | ||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||
| 360 | 1450 | ▶ | while($l =~ /^($trenner)($ntrenner)(.*)$/o) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||
| 362 | 2004 | push(@ar, $2); | |||||||||||||||||||||||||||
| 363 | 2004 | $l = $3; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 1456 | return \@ar; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | sub data_line | ||||||||||||||||||||||||||||
| 371 | { | ||||||||||||||||||||||||||||
| 372 | 1897 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
data_line: called CC=16 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||
| 373 | 1897 | my $ar = shift; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 1897 | my $cols_include = shift; | |||||||||||||||||||||||||||
| 376 | 1897 | my $cols_exclude = shift; | |||||||||||||||||||||||||||
| 377 | 1897 | my $l = ''; | |||||||||||||||||||||||||||
| 378 | 1897 | my $zahl = $self->{config}{numregex}; | |||||||||||||||||||||||||||
| 379 | 1897 | my $end = $self->get_end(); | |||||||||||||||||||||||||||
| 380 | 1897 | my $sep = $self->get_outsep(); | |||||||||||||||||||||||||||
| 381 | 1897 | my @vals; | |||||||||||||||||||||||||||
| 382 | my @cols; | ||||||||||||||||||||||||||||
| 383 | 1897 | my $i = -1; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 1897 | ▶ | unless(defined $cols_include) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||
| 387 | 1885 | @vals = @{$ar}; | |||||||||||||||||||||||||||
| 388 | 1885 | @cols = (0..$#vals); | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | else | ||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||
| 392 | 12 | for my $k (@{$cols_include}) | |||||||||||||||||||||||||||
| 393 | { | ||||||||||||||||||||||||||||
| 394 | 28 | push(@vals, ($k > -1 and $k < @{$ar}) | |||||||||||||||||||||||||||
| 395 | ? $ar->[$k] | ||||||||||||||||||||||||||||
| 396 | 28 | ▶ | : $self->{config}{fill}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$k > -1 and $k < @{$ar;}
MC/DC0%0/2
$k > -1 and $k < @{$ar;}
$k > -1
$k < @{$ar;}
Truth table33%1/3
A and B
A= $k > -1B= $k < @{$ar;}
| |||||||||||||||||||||||||||||
| 397 | 28 | ▶ | push(@cols, $k > -1 ? $k : 0); # ... for numerformat ... arrg | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 1897 | ▶ | if(defined $cols_exclude) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | { | ||||||||||||||||||||||||||||
| 403 | 0 | my @oldvals = @vals; | |||||||||||||||||||||||||||
| 404 | 0 | my @oldcols = @cols; | |||||||||||||||||||||||||||
| 405 | 0 | @vals = (); | |||||||||||||||||||||||||||
| 406 | 0 | @cols = (); | |||||||||||||||||||||||||||
| 407 | 0 | ▶ | for(my $i=0; $i<=$#oldvals; ++$i) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if(not grep {$_ == $i} @{$cols_exclude}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | { | ||||||||||||||||||||||||||||
| 411 | 0 | push(@vals, $oldvals[$i]); | |||||||||||||||||||||||||||
| 412 | 0 | push(@cols, $oldcols[$i]); | |||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 1897 | ▶ | if(defined $self->{config}{numformat}->[0]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | { | ||||||||||||||||||||||||||||
| 419 | 1433 | foreach my $i (0..$#vals) | |||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||
| 421 | 3586 | my $v = $vals[$i]; | |||||||||||||||||||||||||||
| 422 | 3586 | my $c = $cols[$i]; | |||||||||||||||||||||||||||
| 423 | 3586 | ▶ | unless(defined $v){ $l .= $sep; next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 3586 | my $numform = $self->{config}{numformat}->[$c]; | |||||||||||||||||||||||||||
| 426 | 3586 | ▶ | $numform = $self->{config}{numformat}->[0] unless defined $numform; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 3586 | ▶ | if($numform ne '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||
| 429 | 3586 | ▶ | $l .= ($v ne '' and $v =~ /^$zahl$/ ? sprintf($numform, $v) : $v).$sep; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$v ne '' && ($v =~ /^$zahl$/ ? sprintf($numform, $v) : $v)
MC/DC0%0/2
$v ne '' && ($v =~ /^$zahl$/ ? sprintf($numform, $v) : $v)
$v ne ''
($v =~ /^$zahl$/ ? sprintf($numform, $v) : $v)
Truth table33%1/3
A && B
A= $v ne ''B= ($v =~ /^$zahl$/ ? sprintf($numform, $v) : $v)
| |||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | 0 | else{ $l .= $v.$sep; } | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | 1433 | $l =~ s/$sep$/$end/; | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | else | ||||||||||||||||||||||||||||
| 436 | { | ||||||||||||||||||||||||||||
| 437 | # do I want to care for undefs? | ||||||||||||||||||||||||||||
| 438 | # not here ... failure is not communicated from here, you shall handle bad columns externally | ||||||||||||||||||||||||||||
| 439 | 464 | $l = join($sep, @vals).$end; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | 1897 | return \$l; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | sub title_line | ||||||||||||||||||||||||||||
| 445 | { | ||||||||||||||||||||||||||||
| 446 | 25 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
title_line: called CC=8 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||
| 447 | 25 | my $cols_include = shift; | |||||||||||||||||||||||||||
| 448 | 25 | my $cols_exclude = shift; | |||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 25 | ▶ | my @cols = defined $cols_include ? @{$cols_include} : (0..$#{$self->{titles}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 25 | ▶ | if(defined $cols_exclude) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | { | ||||||||||||||||||||||||||||
| 453 | 0 | my @oldcols = @cols; | |||||||||||||||||||||||||||
| 454 | 0 | @cols = (); | |||||||||||||||||||||||||||
| 455 | 0 | ▶ | for(my $i=0; $i<=$#oldcols; ++$i) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | { | ||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if(not grep {$_ == $i} @{$cols_exclude}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | { | ||||||||||||||||||||||||||||
| 459 | 0 | push(@cols, $oldcols[$i]); | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 25 | my $end = $self->get_end(); | |||||||||||||||||||||||||||
| 465 | 25 | my $sep = $self->get_outsep(); | |||||||||||||||||||||||||||
| 466 | 25 | my $com = $self->get_comchar(); | |||||||||||||||||||||||||||
| 467 | 25 | my $q = $self->get_quote(); | |||||||||||||||||||||||||||
| 468 | 25 | my $l = $com.$q; | |||||||||||||||||||||||||||
| 469 | #print STDERR "titles: @{$self->{titles}}\n"; | ||||||||||||||||||||||||||||
| 470 | #print STDERR "titles for @{$ar}\n" if defined $ar; | ||||||||||||||||||||||||||||
| 471 | 25 | foreach my $k (@cols) | |||||||||||||||||||||||||||
| 472 | { | ||||||||||||||||||||||||||||
| 473 | # should match for title containing $q | ||||||||||||||||||||||||||||
| 474 | 172 | ▶ | my $t = $k > -1 ? $self->{titles}->[$k] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 475 | 172 | ▶ | $t = "" unless defined $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 476 | 172 | $l .= $t.$q.$sep.$q; | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | 25 | $l =~ s/$q$//; | |||||||||||||||||||||||||||
| 479 | 25 | $l =~ s/$sep$/$end/; | |||||||||||||||||||||||||||
| 480 | 25 | return \$l; | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | sub comment_line | ||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||
| 485 | 784 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
comment_line: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 486 | 784 | ▶ | my $line = ref $_[0] ? $_[0] : \$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | 784 | my $cline = $self->get_comchar().${$line}.$self->get_end(); | |||||||||||||||||||||||||||
| 488 | 784 | return \$cline; | |||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | sub chomp_line | ||||||||||||||||||||||||||||
| 492 | { | ||||||||||||||||||||||||||||
| 493 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
chomp_line: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $string = ref $_[0] ? $_[0] : \$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if(defined $string) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||
| 497 | 0 | ${$string} =~ s/$lend$//; | |||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | sub make_naked | ||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||
| 503 | 35 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
make_naked: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 504 | 35 | ▶ | my $string = ref $_[0] ? $_[0] : \$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 505 | 35 | ▶ | if(defined $string) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | { | ||||||||||||||||||||||||||||
| 507 | 35 | ${$string} =~ s/$lend$//; | |||||||||||||||||||||||||||
| 508 | 35 | ${$string} =~ s/^$self->{config}{comregex}//; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | # Not well supported, but possible: Text in between numeric data. | ||||||||||||||||||||||||||||
| 513 | # To make it a bit safer, this filter will replace everything that would count as separator. | ||||||||||||||||||||||||||||
| 514 | # It's only a bit safer... supsequent parsers are supposed to work in strict mode if we're in strict mode here. | ||||||||||||||||||||||||||||
| 515 | sub filter_text | ||||||||||||||||||||||||||||
| 516 | { | ||||||||||||||||||||||||||||
| 517 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
filter_text: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 518 | 0 | my $match; | |||||||||||||||||||||||||||
| 519 | 0 | ▶ | if($self->{config}{strict}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | { | ||||||||||||||||||||||||||||
| 521 | 0 | my $sep = $self->get_outsep(); | |||||||||||||||||||||||||||
| 522 | 0 | $match = qr/$sep/; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | else | ||||||||||||||||||||||||||||
| 525 | { | ||||||||||||||||||||||||||||
| 526 | 0 | $match = qr/$trenner/; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | 0 | for(@_){ s:$match:_:g; } | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 14 | 1; | |||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | __END__ | ||||||||||||||||||||||||||||