equal
deleted
inserted
replaced
1 # $Id: String.pm,v 1.5 2003/07/30 13:39:23 matt Exp $ |
|
2 |
|
3 package XML::SAX::PurePerl::Reader::String; |
|
4 |
|
5 use strict; |
|
6 use vars qw(@ISA); |
|
7 |
|
8 use XML::SAX::PurePerl::Reader qw( |
|
9 LINE |
|
10 COLUMN |
|
11 BUFFER |
|
12 ENCODING |
|
13 EOF |
|
14 ); |
|
15 |
|
16 @ISA = ('XML::SAX::PurePerl::Reader'); |
|
17 |
|
18 use constant DISCARDED => 7; |
|
19 |
|
20 sub new { |
|
21 my $class = shift; |
|
22 my $string = shift; |
|
23 my @parts; |
|
24 @parts[BUFFER, EOF, LINE, COLUMN, DISCARDED] = |
|
25 ($string, 0, 1, 0, ''); |
|
26 return bless \@parts, $class; |
|
27 } |
|
28 |
|
29 sub read_more () { } |
|
30 |
|
31 sub move_along { |
|
32 my $self = shift; |
|
33 my $discarded = substr($self->[BUFFER], 0, $_[0], ''); |
|
34 $self->[DISCARDED] .= $discarded; |
|
35 |
|
36 # Wish I could skip this lot - tells us where we are in the file |
|
37 my $lines = $discarded =~ tr/\n//; |
|
38 $self->[LINE] += $lines; |
|
39 if ($lines) { |
|
40 $discarded =~ /\n([^\n]*)$/; |
|
41 $self->[COLUMN] = length($1); |
|
42 } |
|
43 else { |
|
44 $self->[COLUMN] += $_[0]; |
|
45 } |
|
46 } |
|
47 |
|
48 sub set_encoding { |
|
49 my $self = shift; |
|
50 my ($encoding) = @_; |
|
51 |
|
52 XML::SAX::PurePerl::Reader::switch_encoding_string($self->[BUFFER], $encoding, "utf-8"); |
|
53 $self->[ENCODING] = $encoding; |
|
54 } |
|
55 |
|
56 sub bytepos { |
|
57 my $self = shift; |
|
58 length($self->[DISCARDED]); |
|
59 } |
|
60 |
|
61 1; |
|