1 # $Id: String.pm,v 1.6 2008-08-04 03:35:44 grant Exp $
3 package XML::SAX::PurePerl::Reader::String;
8 use XML::SAX::PurePerl::Reader qw(
16 @ISA = ('XML::SAX::PurePerl::Reader');
18 use constant DISCARDED => 8;
19 use constant STRING => 9;
20 use constant USED => 10;
21 use constant CHUNK_SIZE => 2048;
27 @parts[BUFFER, EOF, LINE, COLUMN, DISCARDED, STRING, USED] =
28 ('', 0, 1, 0, 0, $string, 0);
29 return bless \@parts, $class;
34 if ($self->[USED] >= length($self->[STRING])) {
38 my $bytes = CHUNK_SIZE;
39 if ($bytes > (length($self->[STRING]) - $self->[USED])) {
40 $bytes = (length($self->[STRING]) - $self->[USED]);
42 $self->[BUFFER] .= substr($self->[STRING], $self->[USED], $bytes);
43 $self->[USED] += $bytes;
49 my($self, $bytes) = @_;
50 my $discarded = substr($self->[BUFFER], 0, $bytes, '');
51 $self->[DISCARDED] += length($discarded);
53 # Wish I could skip this lot - tells us where we are in the file
54 my $lines = $discarded =~ tr/\n//;
55 $self->[LINE] += $lines;
57 $discarded =~ /\n([^\n]*)$/;
58 $self->[COLUMN] = length($1);
61 $self->[COLUMN] += $_[0];
69 XML::SAX::PurePerl::Reader::switch_encoding_string($self->[BUFFER], $encoding, "utf-8");
70 $self->[ENCODING] = $encoding;