/[cvs]/nfo/perl/libs/Data/Mungle/Transform/String.pm
ViewVC logotype

Contents of /nfo/perl/libs/Data/Mungle/Transform/String.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Fri Jan 31 01:22:19 2003 UTC (21 years, 5 months ago) by root
Branch: MAIN
Changes since 1.1: +14 -3 lines
+ sub getLastPart

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed