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