Hello Phil,
I work with Exiftool v11.10 on a Windows 7 system.
In order to test structures and also string-tags with multiline values I read all tags of an image
exiftool.exe -t -G0:1 -all:all -sep ?? -api struct=2 -api Filter=RepNL($_) image.jpg
My application starts Exiftool using the -stay_open mechanism.
It also sends some additional options, but they are out of interest for the described problem/finding.
The procedure RepNL has been introduced by StarGeek in thread https://exiftool.org/forum/index.php/topic,9348.0.html (https://exiftool.org/forum/index.php/topic,9348.0.html) where we discussed multiline string and #[CSTR] feature.
It is to get newline as printable characters"\n" for h'0A0D.
Currently it is
sub RepNL {
($_)=@_;
my %replace = (
"\\" => "\\\\", # escape backslash
"\r\n" => "\\n", # CRLF
"\n\r" => "\\n", # LFCR
"\n" => "\\n", # line feed 0x0A
"\r" => "\\r", # carriage return 0x0D
# "\t" => "\\t", # tab 0x09
);
s/(@{[join '|', map { quotemeta($_) } keys %replace]})/$replace{$1}/g;
}
For listtype tags (in my case -by-linetitle and headline) I have the following strange behaviour:
- by-linetitle has 2 list elements: title1line1\r\ntitle1line2 and title2line1
element 1 is multiline element 2 is singleline
- headline has 1 multiline value, also with \r\n as newline.
Sometimes Exiftool sends: IPTC \t by-linetitle \t [title1line1\r\ntitle1line2,title2line1] and
sometimes it sends: IPTC \t by-linetitle \t [title1line1\ntitle1line2,title2line1]
without \r
Because my Perl knowledge is not the very best I ask: Could there be a side-effect with RepNL?
Does anyone have an idea where it might come from?
Thanks for your help in advance
Best regards
Herb
Hi Herb,
The problem occurs because "keys %replace" returns the keys in random order. If it happens to replace "\n" before "\n\r", then you get the problem. Try this instead:
sub RepNL {
($_)=@_;
my @order = ("\r\n","\n\r","\n","\r","\\");
my %replace = (
"\\" => "\\\\", # escape backslash
"\r\n" => "\\n", # CRLF
"\n\r" => "\\n", # LFCR
"\n" => "\\n", # line feed 0x0A
"\r" => "\\r", # carriage return 0x0D
);
s/(@{[join '|', map { quotemeta($_) } @order]})/$replace{$1}/g;
}
- Phil
Hello Phil,
thanks for your help.
In a (very) short test I could not reproduce the problem.
Best regards
Herb