1 |
## ------------------------------------------------------------------------- |
2 |
## $Id: String.pm,v 1.3 2003/02/20 21:23:34 joko Exp $ |
3 |
## ------------------------------------------------------------------------- |
4 |
## $Log: String.pm,v $ |
5 |
## Revision 1.3 2003/02/20 21:23:34 joko |
6 |
## using 'trim_space' from Pitonyak::StringUtil as a replacement for our 'trim' |
7 |
## |
8 |
## Revision 1.2 2003/01/31 01:22:19 root |
9 |
## + sub getLastPart |
10 |
## |
11 |
## Revision 1.1 2003/01/19 03:27:36 joko |
12 |
## + initial check-in |
13 |
## ------------------------------------------------------------------------- |
14 |
|
15 |
|
16 |
package Data::Transform::String; |
17 |
|
18 |
use strict; |
19 |
use warnings; |
20 |
|
21 |
require Exporter; |
22 |
our @ISA = qw( Exporter ); |
23 |
our @EXPORT_OK = qw( |
24 |
stripHtml stripNewLines toReal getLastPart trim |
25 |
); |
26 |
|
27 |
|
28 |
use Pitonyak::StringUtil qw( trim_space ); |
29 |
|
30 |
sub stripHtml { |
31 |
my $html = shift; |
32 |
my $result = ''; |
33 |
#$html =~ s/<br>(.*)/ - ($1)/i; |
34 |
my $p = HTML::PullParser->new( |
35 |
doc => \$html, |
36 |
text => 'text', |
37 |
unbroken_text => 1, |
38 |
); |
39 |
while (my $token = $p->get_token()) { |
40 |
my $text = join('', @{$token}); |
41 |
$result .= $text; |
42 |
} |
43 |
#$result =~ s/ //g; |
44 |
return $result; |
45 |
} |
46 |
|
47 |
sub trim { |
48 |
trim_space(@_); |
49 |
} |
50 |
|
51 |
sub stripNewLines { |
52 |
my $text = shift; |
53 |
#print "text: $text", "\n"; |
54 |
#print "ord: ", ord(substr($text, 0, 1)), "\n"; |
55 |
$text =~ s/\n//g; |
56 |
#$text =~ s/\s*$//g; |
57 |
return $text; |
58 |
} |
59 |
|
60 |
sub toReal { |
61 |
my $string = shift; |
62 |
$string =~ m/(\d+\.*\d+)/; |
63 |
my $real = $1; |
64 |
return $real; |
65 |
} |
66 |
|
67 |
sub getLastPart { |
68 |
my $which = shift; |
69 |
my $seperator = shift; |
70 |
$seperator ||= '\/'; |
71 |
$which =~ m/^.*$seperator(.+?)$/; |
72 |
return $1; |
73 |
} |
74 |
|
75 |
1; |