Changeset 363:5f6d9bb33a53
- Timestamp:
- 04/04/09 15:38:37
(3 years ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- Parents:
362:5b585873fec2 361:4bffbf81e2d6
- branch:
- default
- Message:
merge
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r361 |
r363 |
|
| 12 | 12 | } |
|---|
| 13 | 13 | } |
|---|
| 14 | | version(TANGOSVN){ |
|---|
| 15 | | import tango.io.device.Conduit; |
|---|
| 16 | | } else { |
|---|
| 17 | | import tango.io.Conduit; |
|---|
| 18 | | } |
|---|
| | 14 | import tango.io.device.Conduit; |
|---|
| 19 | 15 | |
|---|
| 20 | 16 | class InputStreamWrapper : tango.io.model.IConduit.InputStream { |
|---|
| r362 |
r363 |
|
| 6 | 6 | public import dwt.dwthelper.InputStream; |
|---|
| 7 | 7 | import dwt.dwthelper.utils; |
|---|
| 8 | | import tango.io.Stdout; |
|---|
| 9 | 8 | import tango.io.compress.ZlibStream; |
|---|
| 10 | 9 | version(Windows){ |
|---|
| … | … | |
| 27 | 26 | return res; |
|---|
| 28 | 27 | } |
|---|
| 29 | | void[] load (void[] dst = null) { |
|---|
| 30 | | return Conduit.load (this, dst); |
|---|
| | 28 | |
|---|
| | 29 | IOStream flush () { |
|---|
| | 30 | return this; |
|---|
| | 31 | } |
|---|
| | 32 | |
|---|
| | 33 | void[] load ( size_t max = -1 ) { |
|---|
| | 34 | return Conduit.load (this, max); |
|---|
| 31 | 35 | } |
|---|
| 32 | 36 | |
|---|
| … | … | |
| 35 | 39 | } |
|---|
| 36 | 40 | |
|---|
| 37 | | long seek ( long offset, IOStream.Anchor anchor = IOStream.Anchor.Begin ) |
|---|
| 38 | | { |
|---|
| 39 | | throw new IOException(__FILE__ ~ "seek method not implemented"); |
|---|
| 40 | | } |
|---|
| 41 | | |
|---|
| 42 | 41 | tango.io.model.IConduit.IConduit conduit (){ |
|---|
| 43 | 42 | return null; |
|---|
| … | … | |
| 47 | 46 | istr.close(); |
|---|
| 48 | 47 | } |
|---|
| 49 | | |
|---|
| 50 | | tango.io.model.IConduit.InputStream input() { |
|---|
| 51 | | return this; //?? |
|---|
| | 48 | tango.io.model.IConduit.InputStream input (){ |
|---|
| | 49 | return null; |
|---|
| | 50 | } |
|---|
| | 51 | long seek (long offset, Anchor anchor = Anchor.Begin){ |
|---|
| | 52 | return 0; |
|---|
| 52 | 53 | } |
|---|
| 53 | 54 | } |
|---|
| r361 |
r363 |
|
| 486 | 486 | } |
|---|
| 487 | 487 | |
|---|
| 488 | | alias tango.text.convert.Utf.toString16 toString16; |
|---|
| 489 | | alias tango.text.convert.Utf.toString toString; |
|---|
| | 488 | //alias tango.text.convert.Utf.toString16 toString16; |
|---|
| | 489 | //alias tango.text.convert.Utf.toString toString; |
|---|
| 490 | 490 | |
|---|
| 491 | 491 | int toAbsoluteCodePointStartOffset( String str, int index ){ |
|---|
| r362 |
r363 |
|
| 11 | 11 | |
|---|
| 12 | 12 | import tango.io.Stdout; |
|---|
| 13 | | version(TANGOSVN) { |
|---|
| 14 | | import tango.io.stream.Format; |
|---|
| 15 | | alias FormatOutput Print; |
|---|
| 16 | | } |
|---|
| 17 | | else |
|---|
| 18 | | import tango.io.Print; |
|---|
| 19 | | |
|---|
| | 13 | import tango.io.stream.Format; |
|---|
| 20 | 14 | static import tango.stdc.stringz; |
|---|
| 21 | 15 | static import tango.text.Util; |
|---|
| … | … | |
| 27 | 21 | import tango.stdc.stdlib : exit; |
|---|
| 28 | 22 | |
|---|
| 29 | | import tango.util.log.Trace; |
|---|
| | 23 | import tango.util.log.Log; |
|---|
| 30 | 24 | import tango.text.UnicodeData; |
|---|
| | 25 | |
|---|
| | 26 | Logger getDwtLogger(){ |
|---|
| | 27 | return Log.lookup( "dwt" ); |
|---|
| | 28 | } |
|---|
| 31 | 29 | |
|---|
| 32 | 30 | alias char[] String; |
|---|
| … | … | |
| 36 | 34 | |
|---|
| 37 | 35 | void implMissing( String file, uint line ){ |
|---|
| 38 | | Stderr.formatln( "implementation missing in file {} line {}", file, line ); |
|---|
| 39 | | Stderr.formatln( "exiting ..." ); |
|---|
| | 36 | getDwtLogger().fatal( "implementation missing in file {} line {}", file, line ); |
|---|
| | 37 | getDwtLogger().fatal( "exiting ..." ); |
|---|
| 40 | 38 | exit(1); |
|---|
| 41 | 39 | } |
|---|
| … | … | |
| 60 | 58 | return (typeid(T[])).getHash(&array); |
|---|
| 61 | 59 | } |
|---|
| 62 | | static if( is( T == char[] )){ |
|---|
| | 60 | static if( is( T == char )){ |
|---|
| 63 | 61 | public override char[] toString(){ |
|---|
| 64 | 62 | return array; |
|---|
| … | … | |
| 455 | 453 | consumed = ate; |
|---|
| 456 | 454 | if( ate is 0 || res.length is 0 ){ |
|---|
| 457 | | Trace.formatln( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); |
|---|
| | 455 | getDwtLogger().trace( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); |
|---|
| 458 | 456 | } |
|---|
| 459 | 457 | assert( ate > 0 ); |
|---|
| … | … | |
| 467 | 465 | consumed = ate; |
|---|
| 468 | 466 | if( ate is 0 || res.length is 0 ){ |
|---|
| 469 | | Trace.formatln( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); |
|---|
| | 467 | getDwtLogger().trace( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); |
|---|
| 470 | 468 | } |
|---|
| 471 | 469 | assert( ate > 0 ); |
|---|
| … | … | |
| 491 | 489 | //alias tango.text.convert.Utf.toString toString; |
|---|
| 492 | 490 | |
|---|
| | 491 | int toAbsoluteCodePointStartOffset( String str, int index ){ |
|---|
| | 492 | //getDwtLogger().trace( "str={}, str.length={}, index={}", str, str.length, index ); |
|---|
| | 493 | //Trace.memory( str ); |
|---|
| | 494 | if( str.length is index ){ |
|---|
| | 495 | return index; |
|---|
| | 496 | } |
|---|
| | 497 | if( ( str[index] & 0x80 ) is 0x00 ) { |
|---|
| | 498 | return index; |
|---|
| | 499 | } |
|---|
| | 500 | else{ |
|---|
| | 501 | int steps = 0; |
|---|
| | 502 | while(( str[index] & 0xC0 ) is 0x80 ){ |
|---|
| | 503 | index--; |
|---|
| | 504 | steps++; |
|---|
| | 505 | if( steps > 3 || index < 0 ){ |
|---|
| | 506 | break; |
|---|
| | 507 | } |
|---|
| | 508 | } |
|---|
| | 509 | if((( str[index] & 0xE0 ) is 0xC0) && ( steps <= 1 )){ |
|---|
| | 510 | // ok |
|---|
| | 511 | } |
|---|
| | 512 | else if((( str[index] & 0xF0 ) is 0xE0) && ( steps <= 2 )){ |
|---|
| | 513 | // ok |
|---|
| | 514 | } |
|---|
| | 515 | else if((( str[index] & 0xF8 ) is 0xF0) && ( steps <= 3 )){ |
|---|
| | 516 | // ok |
|---|
| | 517 | } |
|---|
| | 518 | else{ |
|---|
| | 519 | tango.text.convert.Utf.onUnicodeError( "invalid utf8 input to toAbsoluteCodePointStartOffset" ); |
|---|
| | 520 | } |
|---|
| | 521 | return index; |
|---|
| | 522 | } |
|---|
| | 523 | } |
|---|
| 493 | 524 | int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ |
|---|
| 494 | 525 | return getAbsoluteCodePointOffset( str, startIndex, searchRelCp ) - startIndex; |
|---|
| 495 | 526 | } |
|---|
| 496 | 527 | int getAbsoluteCodePointOffset( String str, int startIndex, int searchRelCp ){ |
|---|
| | 528 | |
|---|
| | 529 | //getDwtLogger().trace( "str={}, str.length={}, startIndex={}, searchRelCp={}", str, str.length, startIndex, searchRelCp ); |
|---|
| | 530 | //Trace.memory( str ); |
|---|
| | 531 | |
|---|
| 497 | 532 | int ignore; |
|---|
| 498 | 533 | int i = startIndex; |
|---|
| … | … | |
| 501 | 536 | |
|---|
| 502 | 537 | if( ( i < str.length ) |
|---|
| 503 | | && ( str[i] & 0x80 ) is 0x00 ) |
|---|
| | 538 | && (( str[i] & 0x80 ) is 0x00 )) |
|---|
| 504 | 539 | { |
|---|
| 505 | 540 | i+=1; |
|---|
| … | … | |
| 527 | 562 | } |
|---|
| 528 | 563 | else{ |
|---|
| 529 | | Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str ); |
|---|
| | 564 | getDwtLogger().trace( "getAbsoluteCodePointOffset invalid utf8 characters: {:X2}", cast(ubyte[]) str ); |
|---|
| 530 | 565 | tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); |
|---|
| 531 | 566 | } |
|---|
| … | … | |
| 539 | 574 | if( i < 0 ){ |
|---|
| 540 | 575 | return startIndex-1; |
|---|
| 541 | | //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); |
|---|
| 542 | | //tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); |
|---|
| 543 | 576 | } |
|---|
| 544 | 577 | } while(( str[i] & 0xC0 ) is 0x80 ); |
|---|
| … | … | |
| 566 | 599 | } |
|---|
| 567 | 600 | else{ |
|---|
| 568 | | Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str ); |
|---|
| 569 | | tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); |
|---|
| | 601 | getDwtLogger().trace( "invalid utf16 characters: {:X2}", cast(ubyte[]) str ); |
|---|
| | 602 | tango.text.convert.Utf.onUnicodeError( "invalid utf16 input", i ); |
|---|
| 570 | 603 | } |
|---|
| 571 | 604 | searchRelCp--; |
|---|
| … | … | |
| 578 | 611 | if( i < 0 ){ |
|---|
| 579 | 612 | return startIndex-1; |
|---|
| 580 | | //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); |
|---|
| 581 | | //tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); |
|---|
| | 613 | //getDwtLogger().trace( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); |
|---|
| | 614 | //tango.text.convert.Utf.onUnicodeError( "invalid utf16 input", i ); |
|---|
| 582 | 615 | } |
|---|
| 583 | 616 | } while(( str[i] & 0xDC00 ) is 0xDC00 ); |
|---|
| … | … | |
| 628 | 661 | assert( tries-- > 0 ); |
|---|
| 629 | 662 | } |
|---|
| 630 | | Trace.formatln( "utf8OffsetDecr {}->{}", offset, res ); |
|---|
| 631 | | Trace.memory( str ); |
|---|
| | 663 | getDwtLogger().trace( "utf8OffsetDecr {}->{}", offset, res ); |
|---|
| | 664 | //Trace.memory( str ); |
|---|
| 632 | 665 | return res; |
|---|
| 633 | 666 | } |
|---|
| … | … | |
| 1046 | 1079 | ExceptionPrintStackTrace( e, Stderr ); |
|---|
| 1047 | 1080 | } |
|---|
| 1048 | | void ExceptionPrintStackTrace( Exception e, Print!(char) print ){ |
|---|
| | 1081 | void ExceptionPrintStackTrace( Exception e, FormatOutput!(char) print ){ |
|---|
| 1049 | 1082 | Exception exception = e; |
|---|
| 1050 | 1083 | while( exception !is null ){ |
|---|
| … | … | |
| 1266 | 1299 | foreach( msg; e.info ){ |
|---|
| 1267 | 1300 | if( idx >= start && idx < start+deepth ) { |
|---|
| 1268 | | Trace.formatln( "{}: {}", prefix, msg ); |
|---|
| | 1301 | getDwtLogger().trace( "{}: {}", prefix, msg ); |
|---|
| 1269 | 1302 | } |
|---|
| 1270 | 1303 | idx++; |
|---|