line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/File-Extract/trunk/lib/File/Extract/RTF.pm 4210 2007-10-27T13:43:07.499967Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2005 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package File::Extract::RTF; |
7
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
80
|
|
8
|
2
|
|
|
2
|
|
12
|
use base qw(File::Extract::Base); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
164
|
|
9
|
2
|
|
|
2
|
|
2368
|
use RTF::Lexer qw(PTEXT ENBIN ENHEX CSYMB); |
|
2
|
|
|
|
|
15634
|
|
|
2
|
|
|
|
|
960
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
1
|
9
|
sub mime_type { 'application/rtf' } |
12
|
|
|
|
|
|
|
sub extract |
13
|
|
|
|
|
|
|
{ |
14
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
15
|
0
|
|
|
|
|
|
my $file = shift; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $p = RTF::Lexer->new(in => $file); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $text; |
20
|
0
|
|
|
|
|
|
my $token = ''; |
21
|
0
|
|
|
|
|
|
do { |
22
|
0
|
|
|
|
|
|
$token = $p->get_token; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
0
|
|
|
|
if ($token->[0] == ENHEX) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$text .= pack("H2", $token->[1]); |
26
|
|
|
|
|
|
|
} elsif ($token->[0] == CSYMB && $token->[1] =~ /^\s+$/) { |
27
|
0
|
|
|
|
|
|
$text .= $token->[1]; |
28
|
|
|
|
|
|
|
} elsif ($token->[0] == PTEXT || $token->[0] == ENBIN) { |
29
|
0
|
|
|
|
|
|
$text .= $token->[1]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} until $p->is_stop_token($token); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return File::Extract::Result->new( |
34
|
0
|
|
0
|
|
|
|
text => eval { $self->recode($text) } || $text, |
35
|
|
|
|
|
|
|
filename => $file, |
36
|
|
|
|
|
|
|
mime_type => $self->mime_type, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |