Changeset 1224
- Timestamp:
- 2000-06-21T10:26:01+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/multiread.pm
r627 r1224 29 29 # unicode - just unicode (doesn't currently do endian detection) 30 30 # gb - GB 31 # extended - extended ascii32 31 # latin1 - extended ascii (iso-8859-1) 32 # arabic - 8 bit arabic (iso-8859-6) 33 33 34 34 package multiread; … … 169 169 } 170 170 171 if ($self->{'encoding'} eq " extended") {172 # extended ascii171 if ($self->{'encoding'} eq "latin1") { 172 # Latin 1 extended ascii (ISO-8859-1) 173 173 return undef if (eof ($handle)); 174 174 return &unicode::ascii2utf8 (getc ($handle)); 175 } 176 177 if ($self->{'encoding'} eq "arabic") { 178 # 8 bit Arabic (IOS-8859-6) 179 return undef if (eof ($handle)); 180 return &unicode::unicode2utf8(&unicode::arabic2unicode (getc ($handle))); 175 181 } 176 182 … … 236 242 } 237 243 238 if ($self->{'encoding'} eq " extended") {239 # extended ascii 244 if ($self->{'encoding'} eq "latin1") { 245 # extended ascii (ISO-8859-1) 240 246 my $line = ""; 241 247 if (defined ($line = <$handle>)) { … … 244 250 return undef; 245 251 } 252 253 if ($self->{'encoding'} eq "arabic") { 254 # 8 bit arabic (ISO-8859-6) 255 my $line = ""; 256 if (defined ($line = <$handle>)) { 257 return &unicode::unicode2utf8(&unicode::arabic2unicode ($line)); 258 } 259 return undef; 260 } 246 261 247 262 # unknown encoding … … 250 265 251 266 267 # will convert entire contents of file to utf8 and append result to $outputref 268 sub read_file { 269 my $self = shift (@_); 270 my ($outputref) = @_; 271 272 # make sure we have a file handle 273 return if ($self->{'handle'} eq ""); 274 275 my $handle = $self->{'handle'}; 276 277 if ($self->{'first'} && $self->{'encoding'} eq "utf8") { 278 # special case for the first line of utf8 text to detect whether 279 # the file is in utf8 or unicode 280 $$text .= $self->read_line (); 281 } 282 283 if ($self->{'encoding'} eq "utf8") { 284 undef $/; 285 $$outputref .= <$handle>; 286 $/ = "\n"; 287 return; 288 } 289 290 if ($self->{'encoding'} eq "unicode") { 291 my $line = ""; 292 while (defined ($line = $self->read_line())) { 293 $$outputref .= $line; 294 } 295 return; 296 } 297 298 if ($self->{'encoding'} eq "gb") { 299 undef $/; 300 $$outputref .= &unicode::unicode2utf8 (&gb::gb2unicode (<$handle>)); 301 $/ = "\n"; 302 return; 303 } 304 305 if ($self->{'encoding'} eq "latin1") { 306 undef $/; 307 $$outputref .= &unicode::ascii2utf8 (<$handle>); 308 $/ = "\n"; 309 return; 310 } 311 312 if ($self->{'encoding'} eq "arabic") { 313 undef $/; 314 $$outputref .= &unicode::unicode2utf8(&unicode::arabic2unicode (<$handle>)); 315 $/ = "\n"; 316 return; 317 } 318 } 319 320 252 321 1;
Note:
See TracChangeset
for help on using the changeset viewer.