| 324 | }; |
| 325 | |
| 326 | static Uint32 scanTextFile( TextFileStats& stats, IOStream& ins, const TextEncoding* encoding, |
| 327 | Uint32 maxBytes ) { |
| 328 | if ( encoding == nullptr ) |
| 329 | return 0; |
| 330 | bool prevWasCR = false; |
| 331 | Uint32 numBytes = 0; |
| 332 | ins.seek( 0 ); |
| 333 | char buf[4]; |
| 334 | while ( numBytes < maxBytes ) { |
| 335 | size_t read = ins.read( buf, 4 ); |
| 336 | if ( 0 == read ) |
| 337 | break; |
| 338 | |
| 339 | TextDecodeResult decoded = encoding->decodePoint( std::string_view{ buf, read } ); |
| 340 | if ( decoded.status == TextDecodeResult::Status::Truncated && decoded.numBytes == 0 ) |
| 341 | break; // EOF/error |
| 342 | |
| 343 | numBytes += decoded.numBytes; |
| 344 | ins.seek( numBytes ); |
| 345 | |
| 346 | stats.numPoints++; |
| 347 | if ( decoded.status == TextDecodeResult::Status::Valid ) { |
| 348 | eeASSERT( decoded.point >= 0 && decoded.numBytes > 0 ); |
| 349 | stats.numValidPoints++; |
| 350 | stats.totalPointValue += decoded.point; |
| 351 | if ( decoded.point < 32 ) { |
| 352 | if ( decoded.point == '\n' ) { |
| 353 | stats.numPlainAscii++; |
| 354 | stats.numLines++; |
| 355 | stats.numWhitespace++; |
| 356 | if ( prevWasCR ) { |
| 357 | stats.numCRLF++; |
| 358 | } |
| 359 | } else if ( decoded.point == '\t' ) { |
| 360 | stats.numPlainAscii++; |
| 361 | stats.numWhitespace++; |
| 362 | } else if ( decoded.point == '\r' ) { |
| 363 | stats.numPlainAscii++; |
| 364 | } else { |
| 365 | stats.numControl++; |
| 366 | if ( decoded.point == 0 ) { |
| 367 | stats.numNull++; |
| 368 | } |
| 369 | } |
| 370 | } else if ( decoded.point < 127 ) { |
| 371 | stats.numPlainAscii++; |
| 372 | if ( decoded.point == ' ' ) { |
| 373 | stats.numWhitespace++; |
| 374 | } |
| 375 | } else if ( decoded.point >= 65536 ) { |
| 376 | stats.numExtended++; |
| 377 | } else if ( stats.count16b && decoded.point >= 0x8140 ) { |
| 378 | stats.num16bytes++; |
| 379 | } |
| 380 | } |
| 381 | prevWasCR = ( decoded.point == '\r' ); |
| 382 | } |
| 383 | if ( stats.numPoints > 0 ) { |
no test coverage detected