Image/ExifTool/VCard.pm

filter: Statementstmt 97.9% 142 / 145 Branchbran 87.5% 84 / 96 Conditioncond 66.6% 24 / 36 MC/DCmcdc 47.6% 10 / 21 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 86.6% 266 / 307 CC 63 SCAR 38.3
CC
63
Cov
90%
ProcessVCard
57.7
DecodeVCardText
8.0
GetVCardTag
4.0
CRAP 46.2
« Image/ExifTool/HTML.pm ↑ Summary Image/ExifTool/Torrent.pm »
1 #------------------------------------------------------------------------------
2 # File: VCard.pm
3 #
4 # Description: Read vCard and iCalendar meta information
5 #
6 # Revisions: 2015/04/05 - P. Harvey Created
7 # 2015/05/02 - PH Added iCalendar support
8 #
9 # References: 1) http://en.m.wikipedia.org/wiki/VCard
10 # 2) http://tools.ietf.org/html/rfc6350
11 # 3) http://tools.ietf.org/html/rfc5545
12 #------------------------------------------------------------------------------
13  
14 package Image::ExifTool::VCard;
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 $VERSION = '1.07';
21  
22 1 my %unescapeVCard = ( '\\'=>'\\', ','=>',', 'n'=>"\n", 'N'=>"\n" );
23  
24 # lookup for iCalendar components (used to generate family 1 group names if top level)
25 1 my %isComponent = ( Event=>1, Todo=>1, Journal=>1, Freebusy=>1, Timezone=>1, Alarm=>1 );
26  
27 1 my %timeInfo = (
28 # convert common date/time formats to EXIF style
29 ValueConv => q{
30 $val =~ s/(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z?)/$1:$2:$3 $4:$5:$6$7/g;
31 $val =~ s/(\d{4})(\d{2})(\d{2})/$1:$2:$3/g;
32 $val =~ s/(\d{4})-(\d{2})-(\d{2})/$1:$2:$3/g;
33 return $val;
34 },
35 PrintConv => '$self->ConvertDateTime($val)',
36 );
37  
38 # vCard tags (ref 1/2/PH)
39 # Note: The case of all tag ID's is normalized to lowercase with uppercase first letter
40 1 %Image::ExifTool::VCard::Main = (
41 GROUPS => { 2 => 'Document' },
42 VARS => { NO_LOOKUP => 1 }, # omit tags from lookup
43 NOTES => q{
44 This table lists common vCard tags, but ExifTool will also extract any other
45 vCard tags found. Tag names may have "Pref" added to indicate the preferred
46 instance of a vCard property, and other "TYPE" parameters may also added to
47 the tag name. VCF files may contain multiple vCard entries which are
48 distinguished by the ExifTool family 3 group name (document number). See
49 L<http://tools.ietf.org/html/rfc6350> for the vCard 4.0 specification.
50 },
51 Version => { Name => 'VCardVersion', Description => 'VCard Version' },
52 Fn => { Name => 'FormattedName', Groups => { 2 => 'Author' } },
53 N => { Name => 'Name', Groups => { 2 => 'Author' } },
54 Bday => { Name => 'Birthday', Groups => { 2 => 'Time' }, %timeInfo },
55 Tz => { Name => 'TimeZone', Groups => { 2 => 'Time' } },
56 Adr => { Name => 'Address', Groups => { 2 => 'Location' } },
57 Geo => {
58 Name => 'Geolocation',
59 Groups => { 2 => 'Location' },
60 # when used as a parameter, VCard 4.0 adds a "geo:" prefix that we need to remove
61 ValueConv => '$val =~ s/^geo://; $val',
62 },
63 Anniversary => { },
64 Email => { },
65 Gender => { },
66 Impp => 'IMPP',
67 Lang => 'Language',
68 Logo => { },
69 Nickname => { },
70 Note => { },
71 Org => 'Organization',
72 Photo => { Groups => { 2 => 'Preview' } },
73 Prodid => 'Software',
74 Rev => 'Revision',
75 Sound => { },
76 Tel => 'Telephone',
77 Title => 'JobTitle',
78 Uid => 'UID',
79 Url => 'URL',
80 'X-ablabel' => { Name => 'ABLabel', PrintConv => '$val =~ s/^_\$!<(.*)>!\$_$/$1/; $val' },
81 'X-abdate' => { Name => 'ABDate', Groups => { 2 => 'Time' }, %timeInfo },
82 'X-aim' => 'AIM',
83 'X-icq' => 'ICQ',
84 'X-abuid' => 'AB_UID',
85 'X-abrelatednames' => 'ABRelatedNames',
86 'X-socialprofile' => 'SocialProfile',
87 );
88  
89 1 %Image::ExifTool::VCard::VCalendar = (
90 GROUPS => { 1 => 'VCalendar', 2 => 'Document' },
91 VARS => {
92 NO_LOOKUP => 1, # omit tags from lookup
93 LONG_TAGS => 6, # some X-microsoft tags have unavoidably long ID's
94 },
95 NOTES => q{
96 The VCard module is also used to process iCalendar ICS files since they use
97 a format similar to vCard. The following table lists standard iCalendar
98 tags, but any existing tags will be extracted. Top-level iCalendar
99 components (eg. Event, Todo, Timezone, etc.) are used for the family 1 group
100 names, and embedded components (eg. Alarm) are added as a prefix to the tag
101 name. See L<http://tools.ietf.org/html/rfc5545> for the official iCalendar
102 2.0 specification.
103 },
104 Version => { Name => 'VCalendarVersion', Description => 'VCalendar Version' },
105 Calscale => 'CalendarScale',
106 Method => { },
107 Prodid => 'Software',
108 Attach => 'Attachment',
109 Categories => { },
110 Class => 'Classification',
111 Comment => { },
112 Description => { },
113 Geo => {
114 Name => 'Geolocation',
115 Groups => { 2 => 'Location' },
116 ValueConv => '$val =~ s/^geo://; $val',
117 },
118 Location => { Name => 'Location', Groups => { 2 => 'Location' } },
119 'Percent-complete' => 'PercentComplete',
120 Priority => { },
121 Resources => { },
122 Status => { },
123 Summary => { },
124 Completed => { Name => 'DateTimeCompleted', Groups => { 2 => 'Time' }, %timeInfo },
125 Dtend => { Name => 'DateTimeEnd', Groups => { 2 => 'Time' }, %timeInfo },
126 Due => { Name => 'DateTimeDue', Groups => { 2 => 'Time' }, %timeInfo },
127 Dtstart => { Name => 'DateTimeStart', Groups => { 2 => 'Time' }, %timeInfo },
128 Duration => { },
129 Freebusy => 'FreeBusyTime',
130 Transp => 'TimeTransparency',
131 Tzid => { Name => 'TimezoneID', Groups => { 2 => 'Time' } },
132 Tzname => { Name => 'TimezoneName', Groups => { 2 => 'Time' } },
133 Tzoffsetfrom=> { Name => 'TimezoneOffsetFrom', Groups => { 2 => 'Time' } },
134 Tzoffsetto => { Name => 'TimezoneOffsetTo', Groups => { 2 => 'Time' } },
135 Tzurl => { Name => 'TimeZoneURL', Groups => { 2 => 'Time' } },
136 Attendee => { },
137 Contact => { },
138 Organizer => { },
139 'Recurrence-id' => 'RecurrenceID',
140 'Related-to' => 'RelatedTo',
141 Url => 'URL',
142 Uid => 'UID',
143 Exdate => { Name => 'ExceptionDateTimes', Groups => { 2 => 'Time' }, %timeInfo },
144 Rdate => { Name => 'RecurrenceDateTimes', Groups => { 2 => 'Time' }, %timeInfo },
145 Rrule => { Name => 'RecurrenceRule', Groups => { 2 => 'Time' } },
146 Action => { },
147 Repeat => { },
148 Trigger => { },
149 Created => { Name => 'DateCreated', Groups => { 2 => 'Time' }, %timeInfo },
150 Dtstamp => { Name => 'DateTimeStamp', Groups => { 2 => 'Time' }, %timeInfo },
151 'Last-modified' => { Name => 'ModifyDate', Groups => { 2 => 'Time' }, %timeInfo },
152 Sequence => 'SequenceNumber',
153 'Request-status' => 'RequestStatus',
154 Acknowledged=> { Name => 'Acknowledged', Groups => { 2 => 'Time' }, %timeInfo },
155 #
156 # Observed X-tags (not a comprehensive list):
157 #
158 'X-apple-calendar-color'=> 'CalendarColor',
159 'X-apple-default-alarm' => 'DefaultAlarm',
160 'X-apple-local-default-alarm' => 'LocalDefaultAlarm',
161 'X-microsoft-cdo-appt-sequence' => 'AppointmentSequence',
162 'X-microsoft-cdo-ownerapptid' => 'OwnerAppointmentID',
163 'X-microsoft-cdo-busystatus' => 'BusyStatus',
164 'X-microsoft-cdo-intendedstatus' => 'IntendedBusyStatus',
165 'X-microsoft-cdo-alldayevent' => 'AllDayEvent',
166 'X-microsoft-cdo-importance' => {
167 Name => 'Importance',
168 PrintConv => {
169 0 => 'Low',
170 1 => 'Normal',
171 2 => 'High',
172 },
173 },
174 'X-microsoft-cdo-insttype' => {
175 Name => 'InstanceType',
176 PrintConv => {
177 0 => 'Non-recurring Appointment',
178 1 => 'Recurring Appointment',
179 2 => 'Single Instance of Recurring Appointment',
180 3 => 'Exception to Recurring Appointment',
181 },
182 },
183 'X-microsoft-donotforwardmeeting' => 'DoNotForwardMeeting',
184 'X-microsoft-disallow-counter' => 'DisallowCounterProposal',
185 'X-microsoft-locations' => { Name => 'MeetingLocations', Groups => { 2 => 'Location' } },
186 'X-wr-caldesc' => 'CalendarDescription',
187 'X-wr-calname' => 'CalendarName',
188 'X-wr-relcalid' => 'CalendarID',
189 'X-wr-timezone' => { Name => 'TimeZone2', Groups => { 2 => 'Time' } },
190 'X-wr-alarmuid' => 'AlarmUID',
191 );
192  
193 1 %Image::ExifTool::VCard::VNote = (
194 GROUPS => { 1 => 'VNote', 2 => 'Document' },
195 NOTES => 'Tags extracted from V-Note VNT files.',
196 Version => { },
197 Body => { },
198 Dcreated => { Name => 'CreateDate', Groups => { 2 => 'Time' }, %timeInfo },
199 'Last-modified' => { Name => 'ModifyDate', Groups => { 2 => 'Time' }, %timeInfo },
200 );
201  
202 #------------------------------------------------------------------------------
203 # Get vCard tag, creating if necessary
204 # Inputs: 0) ExifTool ref, 1) tag table ref, 2) tag ID, 3) tag Name,
205 # 4) source tagInfo ref, 5) lang code
206 # Returns: tagInfo ref
207 sub GetVCardTag($$$$;$$)
208 120 ▶{
Subroutine GetVCardTag: called CC=4 SCAR=13.9
Pod undocumented
209 120 my ($et, $tagTablePtr, $tag, $name, $srcInfo, $langCode) = @_;
210 120 my $tagInfo = $$tagTablePtr{$tag};
211 120 ▶ unless ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo) 52 68 120
212 52 ▶ if ($srcInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srcInfo) { } 50 2 52
213 50 $tagInfo = { %$srcInfo };
214 } else {
215 2 $tagInfo = { };
216 2 $et->VPrint(0, $$et{INDENT}, "[adding $tag]\n");
217 }
218 52 $$tagInfo{Name} = $name;
219 52 delete $$tagInfo{Description}; # create new description
220 52 AddTagToTable($tagTablePtr, $tag, $tagInfo);
221 }
222 # handle alternate languages (the "language" parameter)
223 120 ▶ $tagInfo = Image::ExifTool::GetLangInfo($tagInfo, $langCode) if $langCode;
Branch: 1 branch
BranchTrueFalseTotal
if $langCode 1 119 120
224 120 return $tagInfo;
225 }
226  
227 #------------------------------------------------------------------------------
228 # Decode vCard text
229 # Inputs: 0) ExifTool ref, 1) vCard text, 2) encoding
230 # Returns: decoded text (or array ref for a list of values)
231 sub DecodeVCardText($$;$)
232 120 ▶{
Subroutine DecodeVCardText: called CC=8 SCAR=20.8
Pod undocumented
233 120 my ($et, $val, $enc) = @_;
234 120 ▶ $enc = defined($enc) ? lc $enc : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $enc ? : 3 117 120
235 120 ▶ if ($enc eq 'b' or $enc eq 'base64') {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc eq 'b' or $enc eq 'base64') { } 2 118 120
Condition100%3/3
$enc eq "b" or $enc eq "base64"
l!l&&r!l&&!r
11118
MC/DC100%2/2
$enc eq "b" or $enc eq "base64"
$enc eq "b" $enc eq "base64"
Truth table100%3/3
A or B
A= $enc eq "b"B= $enc eq "base64"
ABresult
1X1
011
000
236 2 require Image::ExifTool::XMP;
237 2 $val = Image::ExifTool::XMP::DecodeBase64($val);
238 } else {
239 118 ▶ if ($enc eq 'quoted-printable') {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc eq "quoted-printable") 1 117 118
240 # convert "=HH" hex codes to characters
241 1 $val =~ s/=([0-9a-f]{2})/chr(hex($1))/ige;
242 }
243 118 $val = $et->Decode($val, 'UTF8'); # convert from UTF-8
244 # convert unescaped commas to nulls to separate list items
245 118 ▶ $val =~ s/(\\.)|(,)/$1 || "\0"/sge;
Condition100%2/2
$1 || "\000"
l!l
51
MC/DC100%1/1
$1 || "\000"
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
246 # unescape necessary characters in value
247 118 ▶ $val =~ s/\\(.)/$unescapeVCard{$1}||$1/sge;
Condition33%1/3
$unescapeVCard{$1} || $1
l!l&&r!l&&!r
500
MC/DC0%0/2
$unescapeVCard{$1} || $1
$unescapeVCard{$1} $1
Truth table33%1/3
A || B
A= $unescapeVCard{$1}B= $1
ABresult
1X1
011
000
248 # split into list if necessary
249 118 my @vals = split /\0/, $val;
250 118 ▶ $val = \@vals if @vals > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @vals > 1 1 117 118
251 }
252 120 return $val;
253 }
254  
255 #------------------------------------------------------------------------------
256 # Read information in a vCard file
257 # Inputs: 0) ExifTool ref, 1) dirInfo ref
258 # Returns: 1 on success, 0 if this wasn't a valid vCard file
259 sub ProcessVCard($$)
260 2 ▶{
Subroutine ProcessVCard: called CC=53 SCAR=40.6
Pod undocumented
261 2 local $_;
262 2 my ($et, $dirInfo) = @_;
263 2 my $raf = $$dirInfo{RAF};
264 2 my ($buff, $val, $ok, $component, %compNum, @count);
265  
266 2 ▶ return 0 unless $raf->Read($buff, 24) and $raf->Seek(0,0) and $buff=~/^BEGIN:(VCARD|VCALENDAR|VNOTE)\r\n/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 24) and $raf->Seek(0, 0) and $buff =~ /^BEGIN:(VCARD|VCALENDAR|VNOTE)\r\n/i 0 2 2
Condition33%2/6
$raf->Read($buff, 24) and $raf->Seek(0, 0) and $buff =~ /^BEGIN:(VCARD|VCALENDAR|VNOTE)\r\n/i
!ll&&!rl&&r
002
$raf->Read($buff, 24) and $raf->Seek(0, 0)
!ll&&!rl&&r
002
MC/DC0%0/3
$raf->Read($buff, 24) and $raf->Seek(0, 0) and $buff =~ /^BEGIN:(VCARD|VCALENDAR|VNOTE)\r\n/i
$raf->Read($buff, 24) $raf->Seek(0, 0) $buff =~ /^BEGIN:(VCARD|VCALENDAR|VNOTE)\r\n/i
Truth table25%1/4
A and B and C
A= $raf->Read($buff, 24)B= $raf->Seek(0, 0)C= $buff =~ /^BEGIN:(VCARD|VCALENDAR|VNOTE)\r\n/i
ABCresult
0XX0
10X0
1100
1111
267 2 my %info = (
268 VCARD => [ qw(VCard vCard Main VCF) ],
269 VCALENDAR => [ qw(ICS iCalendar VCalendar ICS) ],
270 VNOTE => [ qw(VNote vNote VNote VNT text/v-note) ],
271 );
272 2 my ($type, $lbl, $tbl, $ext, $mime) = @{$info{uc($1)}};
273 2 $et->SetFileType($type, $mime, $ext);
274 2 ▶ return 1 if $$et{OPTIONS}{FastScan} and $$et{OPTIONS}{FastScan} == 3;
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"OPTIONS"}{"FastScan"} and $et->{"OPTIONS"}{"FastScan"} == 3 0 2 2
Condition33%1/3
$et->{"OPTIONS"}{"FastScan"} and $et->{"OPTIONS"}{"FastScan"} == 3
!ll&&!rl&&r
200
MC/DC0%0/2
$et->{"OPTIONS"}{"FastScan"} and $et->{"OPTIONS"}{"FastScan"} == 3
$et->{"OPTIONS"}{"FastScan"} $et->{"OPTIONS"}{"FastScan"} == 3
Truth table33%1/3
A and B
A= $et->{"OPTIONS"}{"FastScan"}B= $et->{"OPTIONS"}{"FastScan"} == 3
ABresult
0X0
100
111
275 2 local $/ = "\r\n";
276 2 my $tagTablePtr = GetTagTable("Image::ExifTool::VCard::$tbl");
277 2 my $more = $raf->ReadLine($buff); # read first line
278 2 ▶ chomp $buff if $more;
Branch: 1 branch
BranchTrueFalseTotal
if $more 2 0 2
279 2 ▶ while ($more) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more) 139 2 141
280 # retrieve previous line from $buff
281 139 ▶ $val = $buff if defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
if defined $buff 139 0 139
282 # read ahead to next line to see if is a continuation
283 139 $more = $raf->ReadLine($buff);
284 139 ▶ if ($more) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more) 137 2 139
285 137 chomp $buff;
286 # add continuation line if necessary
287 137 ▶ $buff =~ s/^[ \t]// and $val .= $buff, undef($buff), next;
Branch: 1 branch
BranchTrueFalseTotal
$buff =~ s/^[ \t]// and $val .= $buff, undef $buff, next 0 137 137
288 }
289 139 ▶ if ($val =~ /^(BEGIN|END):(V?)(\w+)$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(BEGIN|END):(V?)(\w+)$/i) { } 28 111 139
elsif ($ok) { } 1 110 111
290 28 ▶ my ($begin, $v, $what) = ((lc($1) eq 'begin' ? 1 : 0), $2, ucfirst lc $3);
Branch: 1 branch
BranchTrueFalseTotal
lc $1 eq 'begin' ? : 14 14 28
291 28 ▶ if ($what eq 'Card' or $what eq 'Calendar' or $what eq 'Note') {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "Card" or $what eq "Calendar" or $what eq "Note") 6 22 28
Condition83%5/6
$what eq "Card" or $what eq "Calendar" or $what eq "Note"
l!l&&r!l&&!r
6022
$what eq "Card" or $what eq "Calendar"
l!l&&r!l&&!r
4222
MC/DC66%2/3
$what eq "Card" or $what eq "Calendar" or $what eq "Note"
$what eq "Card" $what eq "Calendar" $what eq "Note"
Truth table75%3/4
A or B or C
A= $what eq "Card"B= $what eq "Calendar"C= $what eq "Note"
ABCresult
1XX1
01X1
0011
0000
292 6 ▶ if ($begin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin) { } 3 3 6
293 3 @count = ( { } ); # reset group counters
294 } else {
295 3 $ok = 1; # ok if we read at least on full VCARD or VCALENDAR
296 }
297 6 next;
298 }
299 # absorb top-level component into family 1 group name
300 22 ▶ if ($isComponent{$what}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isComponent{$what}) 14 8 22
301 14 ▶ if ($begin) {
Branch: 2 branches
BranchTrueFalseTotal
if ($begin) { } 7 7 14
elsif ($component and $component eq $what) { } 4 3 7
302 7 ▶ unless ($component) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($component) 4 3 7
303 # begin a new top-level component
304 4 @count = ( { } );
305 4 $component = $what;
306 4 ▶ $compNum{$component} = ($compNum{$component} || 0) + 1;
Condition100%2/2
$compNum{$component} || 0
l!l
22
MC/DC100%1/1
$compNum{$component} || 0
$compNum{$component}
Truth table100%2/2
A
A= $compNum{$component}
Aresult
11
00
307 4 next;
308 }
309 ▶ } elsif ($component and $component eq $what) {
Condition66%2/3
$component and $component eq $what
!ll&&!rl&&r
034
MC/DC50%1/2
$component and $component eq $what
$component $component eq $what
Truth table66%2/3
A and B
A= $componentB= $component eq $what
ABresult
0X0
100
111
310 # this top-level component has ended
311 4 undef $component;
312 4 next;
313 }
314 }
315 # keep count of each component at this level
316 14 ▶ if ($begin) {
Branch: 2 branches
BranchTrueFalseTotal
if ($begin) { } 7 7 14
elsif (@count > 1) { } 7 0 7
317 7 ▶ $count[-1]{$what} = ($count[-1]{$what} || 0) + 1 if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 3 4 7
Condition100%2/2
$count[-1]{$what} || 0
l!l
12
MC/DC100%1/1
$count[-1]{$what} || 0
$count[-1]{$what}
Truth table100%2/2
A
A= $count[-1]{$what}
Aresult
11
00
318 7 push @count, { obj => $what };
319 } elsif (@count > 1) {
320 7 pop @count;
321 }
322 14 next;
323 } elsif ($ok) {
324 1 $ok = 0;
325 1 $$et{DOC_NUM} = ++$$et{DOC_COUNT}; # read next card as a new document
326 }
327 111 ▶ unless ($val =~ s/^([-A-Za-z0-9.]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ s/^([-A-Za-z0-9.]+)//) 0 111 111
328 0 $et->Warn("Unrecognized line in $lbl file");
329 0 next;
330 }
331 111 my $tag = $1;
332 # set group if it exists
333 111 ▶ if ($tag =~ s/^([-A-Za-z0-9]+)\.//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag =~ s/^([-A-Za-z0-9]+)\.//) { } 8 103 111
elsif ($component) { } 64 39 103
334 8 $$et{SET_GROUP1} = ucfirst lc $1;
335 } elsif ($component) {
336 64 $$et{SET_GROUP1} = $component . $compNum{$component};
337 } else {
338 39 delete $$et{SET_GROUP1};
339 }
340 111 my ($name, %param, $p);
341 # vCard tag ID's are case-insensitive, so normalize to lowercase with
342 # an uppercase first letter for use as a tag name
343 111 ▶ $name = ucfirst $tag if $tag =~ /[a-z]/; # preserve mixed case in name if it exists
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /[a-z]/ 6 105 111
344 111 $tag = ucfirst lc $tag;
345 # get source tagInfo reference
346 111 my $srcInfo = $et->GetTagInfo($tagTablePtr, $tag);
347 111 ▶ if ($srcInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srcInfo) { } 110 1 111
348 110 $name = $$srcInfo{Name}; # use our name
349 } else {
350 1 ▶ $name or $name = $tag;
Branch: 1 branch
BranchTrueFalseTotal
$name or $name = $tag 0 1 1
351 # remove leading "X-" from name if it exists
352 1 ▶ $name =~ s/^X-// and $name = ucfirst $name;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ s/^X-// and $name = ucfirst $name 0 1 1
353 }
354 # add object name(s) to tag if necessary
355 111 ▶ if (@count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@count > 1) 40 71 111
356 40 my $i;
357 40 ▶ for ($i=$#count-1; $i>=0; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 40 40 80
358 40 my $pre = $count[$i-1]{obj}; # use containing object name as tag prefix
359 40 my $c = $count[$i]{$pre}; # add index for object number
360 40 ▶ $c = '' unless defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 20 20 40
361 40 $tag = $pre . $c . $tag;
362 40 $name = $pre . $c . $name;
363 }
364 }
365 # parse parameters
366 111 ▶ while ($val =~ s/^;([-A-Za-z0-9]*)(=?)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s/^;([-A-Za-z0-9]*)(=?)//) 56 111 167
367 56 $p = ucfirst lc $1;
368 # convert old vCard 2.x parameters to the new "TYPE=" format
369 56 ▶ $2 or $val = $1 . $val, $p = 'Type';
Branch: 1 branch
BranchTrueFalseTotal
$2 or $val = $1 . $val, $p = "Type" 54 2 56
370 # read parameter value
371 56 for (;;) {
372 112 ▶ last unless $val =~ s/^"([^"]*)",?// or $val =~ s/^([^";:,]+,?)//;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ s/^"([^"]*)",?// or $val =~ s/^([^";:,]+,?)// 56 56 112
Condition100%3/3
$val =~ s/^"([^"]*)",?// or $val =~ s/^([^";:,]+,?)//
l!l&&r!l&&!r
15556
MC/DC100%2/2
$val =~ s/^"([^"]*)",?// or $val =~ s/^([^";:,]+,?)//
$val =~ s/^"([^"]*)",?// $val =~ s/^([^";:,]+,?)//
Truth table100%3/3
A or B
A= $val =~ s/^"([^"]*)",?//B= $val =~ s/^([^";:,]+,?)//
ABresult
1X1
011
000
373 56 ▶ my $v = $p eq 'Type' ? ucfirst lc $1 : $1;
Branch: 1 branch
BranchTrueFalseTotal
$p eq 'Type' ? : 38 18 56
374 56 ▶ $param{$p} = defined($param{$p}) ? $param{$p} . $v : $v;
Branch: 1 branch
BranchTrueFalseTotal
defined $param{$p} ? : 15 41 56
375 }
376 56 ▶ if (defined $param{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{$p}) { } 56 0 56
377 56 ▶ $param{$p} =~ s/\\(.)/$unescapeVCard{$1}||$1/sge;
Condition33%1/3
$unescapeVCard{$1} || $1
l!l&&r!l&&!r
100
MC/DC0%0/2
$unescapeVCard{$1} || $1
$unescapeVCard{$1} $1
Truth table33%1/3
A || B
A= $unescapeVCard{$1}B= $1
ABresult
1X1
011
000
378 } else {
379 0 $param{$p} = '';
380 }
381 }
382 111 ▶ $val =~ s/^:// or $et->Warn("Invalid line in $lbl file"), next;
Branch: 1 branch
BranchTrueFalseTotal
$val =~ s/^:// or $et->Warn("Invalid line in $lbl file"), next 111 0 111
383 # add 'Type' parameter to id and name if it exists
384 111 ▶ $param{Type} and $tag .= $param{Type}, $name .= $param{Type};
Branch: 1 branch
BranchTrueFalseTotal
$param{"Type"} and $tag .= $param{"Type"}, $name .= $param{"Type"} 23 88 111
385 # convert base64-encoded data
386 111 ▶ if ($val =~ s{^data:(\w+)/(\w+);base64,}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s[^data:(\w+)/(\w+);base64,][]) 1 110 111
387 1 my $xtra = ucfirst(lc $1) . ucfirst(lc $2);
388 1 $tag .= $xtra;
389 1 $name .= $xtra;
390 1 $param{Encoding} = 'base64';
391 }
392 111 $val = DecodeVCardText($et, $val, $param{Encoding});
393 111 my $tagInfo = GetVCardTag($et, $tagTablePtr, $tag, $name, $srcInfo, $param{Language});
394 111 $et->HandleTag($tagTablePtr, $tag, $val, TagInfo => $tagInfo);
395 # handle some other parameters that we care about (ignore the rest for now)
396 111 foreach $p (qw(Geo Label Tzid)) {
397 333 ▶ next unless defined $param{$p};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param{$p} 324 9 333
398 # use tag attributes from our table if it exists
399 9 my $srcTag2 = $et->GetTagInfo($tagTablePtr, $p);
400 9 ▶ my $pn = $srcTag2 ? $$srcTag2{Name} : $p;
Branch: 1 branch
BranchTrueFalseTotal
$srcTag2 ? : 8 1 9
401 9 $val = DecodeVCardText($et, $param{$p});
402 # add parameter to tag ID and name
403 9 my ($tg, $nm) = ($tag . $p, $name . $pn);
404 9 $tagInfo = GetVCardTag($et, $tagTablePtr, $tg, $nm, $srcTag2, $param{Language});
405 9 $et->HandleTag($tagTablePtr, $tg, $val, TagInfo => $tagInfo);
406 }
407 }
408 2 delete $$et{SET_GROUP1};
409 2 delete $$et{DOC_NUM};
410 2 ▶ $ok or $et->Warn("Missing $lbl end");
Branch: 1 branch
BranchTrueFalseTotal
$ok or $et->Warn("Missing $lbl end") 2 0 2
411 2 return 1;
412 }
413  
414 1 1; # end
415  
416 __END__
« Image/ExifTool/HTML.pm ↑ Summary Image/ExifTool/Torrent.pm »