| 1 | # /=====================================================================\ # | ||||||||||||||||||||||||||||||||||||||
| 2 | # | LaTeXML::Common::Locator | # | ||||||||||||||||||||||||||||||||||||||
| 3 | # | Locators | # | ||||||||||||||||||||||||||||||||||||||
| 4 | # |=====================================================================| # | ||||||||||||||||||||||||||||||||||||||
| 5 | # | Part of LaTeXML: | # | ||||||||||||||||||||||||||||||||||||||
| 6 | # | Public domain software, produced as part of work done by the | # | ||||||||||||||||||||||||||||||||||||||
| 7 | # | United States Government & not subject to copyright in the US. | # | ||||||||||||||||||||||||||||||||||||||
| 8 | # |---------------------------------------------------------------------| # | ||||||||||||||||||||||||||||||||||||||
| 9 | # | Bruce Miller <bruce.miller@nist.gov> #_# | # | ||||||||||||||||||||||||||||||||||||||
| 10 | # | http://dlmf.nist.gov/LaTeXML/ (o o) | # | ||||||||||||||||||||||||||||||||||||||
| 11 | # \=========================================================ooo==U==ooo=/ # | ||||||||||||||||||||||||||||||||||||||
| 12 | package LaTeXML::Common::Locator; | ||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use LaTeXML::Global; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use base qw(LaTeXML::Common::Object); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use LaTeXML::Util::Pathname; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use LaTeXML::Util::WWW; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ($class, $source, $fromLine, $fromCol, $toLine, $toCol) = @_; | |||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $locator = bless { source => $source, | |||||||||||||||||||||||||||||||||||||
| 24 | fromLine => $fromLine, fromCol => $fromCol, | ||||||||||||||||||||||||||||||||||||||
| 25 | toLine => $toLine, toCol => $toCol | ||||||||||||||||||||||||||||||||||||||
| 26 | }, $class; | ||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return $locator; } | |||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | # creates a new locator range from a given start and end | ||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub newRange { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
newRange: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my ($class, $from, $to) = @_; | |||||||||||||||||||||||||||||||||||||
| 32 | # make sure that either parameters are defined | ||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | return $to unless defined($from); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return $from unless defined($to); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 35 | # bail if we have differnt sources | ||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return unless ($$from{source} || '') eq ($$to{source} || ''); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$from->{'source'} || ''
$to->{'source'} || ''
MC/DC0%0/1
$from->{'source'} || ''
$from->{'source'}
MC/DC0%0/1
$to->{'source'} || ''
$to->{'source'}
Truth table0%0/2
A
A= $from->{'source'}
Truth table0%0/2
A
A= $to->{'source'}
| |||||||||||||||||||||||||||||||||||||||
| 37 | # the end coordinates depend on | ||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ($toLine, $toCol); | |||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($to->isRange) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $toLine = $$to{toLine}; | |||||||||||||||||||||||||||||||||||||
| 41 | 0 | $toCol = $$to{toCol}; } | |||||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $toLine = $$to{fromLine}; | |||||||||||||||||||||||||||||||||||||
| 44 | 0 | $toCol = $$to{fromCol}; } | |||||||||||||||||||||||||||||||||||||
| 45 | 0 | return new($class, $$from{source}, $$from{fromLine}, $$from{fromCol}, $toLine, $toCol); } | |||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub isRange { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
isRange: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return defined($$self{toLine}) || defined($$self{toCol}); } | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $self->{'toLine'} || defined $self->{'toCol'}
MC/DC0%0/2
defined $self->{'toLine'} || defined $self->{'toCol'}
defined $self->{'toLine'}
defined $self->{'toCol'}
Truth table0%0/3
A || B
A= defined $self->{'toLine'}B= defined $self->{'toCol'}
| |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub getShortSource { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getShortSource: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ($self, $stringSource) = @_; | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $source = $$self{source}; | |||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return ($stringSource || 'String') unless ((defined $source) && $source); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
defined $source and $source
$stringSource || 'String'
MC/DC0%0/2
defined $source and $source
defined $source
$source
MC/DC0%0/1
$stringSource || 'String'
$stringSource
Truth table0%0/3
A and B
A= defined $sourceB= $source
Truth table0%0/2
A
A= $stringSource
| |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (index($source, ':') > 1) { # assuming legit protocols are more than 1 char (NOT windows C:/) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my ($path, $base, $ext) = url_split($source); | |||||||||||||||||||||||||||||||||||||
| 57 | 0 | return "$base.$ext"; } | |||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ($path, $base, $ext) = pathname_split($source); | |||||||||||||||||||||||||||||||||||||
| 60 | 0 | return "$base.$ext"; } } | |||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub toString { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
toString: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $loc = $self->getShortSource; | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $loc .= "; line $$self{fromLine}" if defined($$self{fromLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $loc .= " col $$self{fromCol}" if defined($$self{fromLine}) && defined($$self{fromCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"fromLine"} and defined $self->{"fromCol"}
MC/DC0%0/2
defined $self->{"fromLine"} and defined $self->{"fromCol"}
defined $self->{"fromLine"}
defined $self->{"fromCol"}
Truth table0%0/3
A and B
A= defined $self->{"fromLine"}B= defined $self->{"fromCol"}
| |||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $loc .= " - line $$self{toLine}" if defined($$self{toLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $loc .= " col $$self{toCol}" if defined($$self{toLine}) && defined($$self{toCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"toLine"} and defined $self->{"toCol"}
MC/DC0%0/2
defined $self->{"toLine"} and defined $self->{"toCol"}
defined $self->{"toLine"}
defined $self->{"toCol"}
Truth table0%0/3
A and B
A= defined $self->{"toLine"}B= defined $self->{"toCol"}
| |||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return $loc; } | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $loc = defined $$self{source} ? ($$self{source} || 'Literal String') : 'Anonymous String'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"source"} or "Literal String"
MC/DC0%0/1
$self->{"source"} or "Literal String"
$self->{"source"}
Truth table0%0/2
A
A= $self->{"source"}
| |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $rangeFrom = $self->isRange ? ' from' : ''; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $loc .= ";$rangeFrom line $$self{fromLine}" if defined($$self{fromLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $loc .= " col $$self{fromCol}" if defined($$self{fromLine}) && defined($$self{fromCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"fromLine"} and defined $self->{"fromCol"}
MC/DC0%0/2
defined $self->{"fromLine"} and defined $self->{"fromCol"}
defined $self->{"fromLine"}
defined $self->{"fromCol"}
Truth table0%0/3
A and B
A= defined $self->{"fromLine"}B= defined $self->{"fromCol"}
| |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $loc .= " to line $$self{toLine}" if defined($$self{toLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $loc .= " col $$self{toCol}" if defined($$self{toLine}) && defined($$self{toCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"toLine"} and defined $self->{"toCol"}
MC/DC0%0/2
defined $self->{"toLine"} and defined $self->{"toCol"}
defined $self->{"toLine"}
defined $self->{"toCol"}
Truth table0%0/3
A and B
A= defined $self->{"toLine"}B= defined $self->{"toCol"}
| |||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return $loc; } | |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub toAttribute { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
toAttribute: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $loc = $self->getShortSource('anonymous_string') . '#text'; | |||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($self->isRange) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $loc .= 'range(from='; | |||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $loc .= "$$self{fromLine}" if defined($$self{fromLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $loc .= ";$$self{fromCol}" if defined($$self{fromCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $loc .= ',to='; | |||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $loc .= "$$self{toLine}" if defined($$self{toLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $loc .= ";$$self{toCol}" if defined($$self{toCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $loc .= ')'; | |||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $loc; } | |||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $loc .= 'point('; | |||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $loc .= "$$self{fromLine}" if defined($$self{fromLine}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $loc .= ";$$self{fromCol}" if defined($$self{fromCol}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $loc .= ')'; | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | return $loc; } } | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub getLocator { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getLocator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 101 | # getting the locator of a locator should return itself | ||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $self; } | |||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub getSource { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getSource: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 107 | 0 | return $self; } | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub getFromLocator { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getFromLocator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 111 | 0 | return LaTeXML::Common::Locator->new($$self{source}, $$self{fromLine}, $$self{fromCol}); } | |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub getToLocator { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getToLocator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 115 | 0 | return LaTeXML::Common::Locator->new($$self{source}, $$self{toLine}, $$self{toCol}); } | |||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||
| 118 | 5 | 1; | |||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||