Ignore:
Timestamp:
Jan 5, 2009, 1:40:11 AM (15 years ago)
Author:
イグトランス (egtra)
Message:

Encoder/Decoderを排除した実装(UTF8Encodingは修正していません)。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branch/egtra-stream-without-en_dec/Classes/System/IO/StreamWriter.ab

    r653 r673  
    4141
    4242    Override Sub Flush()
    43         Dim buf = Buffer()
    44         Dim pws As PCWSTR
    45         Dim size = GetWCStr(buf.ToString(), pws)
    46         Dim pwsEnd = VarPtr(pws[size])
    47         Dim charConverted As Long
    48         Dim byteBuf[4095] As Byte
    49         Dim byteSize As Long
    50         Dim completed As Boolean
    51         Do
    52             Dim converted As Long
    53             encoder.Convert(pws, size, byteBuf, Len(byteBuf), False, charConverted, byteSize, completed)
    54             s.Write(byteBuf, 0, byteSize)
    55             pws = VarPtr(pws[charConverted])
    56             size -= charConverted
    57         Loop Until pws = pwsEnd
    58         buf.Length = 0
     43        softFlush()
     44        s.Flush()
     45    End Sub
     46
     47    Override Sub WriteLine()
     48        Super.WriteLine()
     49        softFlush()
    5950    End Sub
    6051
     
    6354        If disposing Then
    6455            Flush()
    65             flushLast()
    6656            s.Dispose()
    6757        End If
     
    7363        buf = New Text.StringBuilder(4096)
    7464        '暫定。正式版ではUTF-8を標準とする。
    75         encoding = New Text.Detail.WindowsCodePageEncoding(CP_ACP)
    76         encoder = encoding.GetEncoder()
     65        e = New Text.Detail.WindowsCodePageEncoding(CP_ACP)
    7766    End Sub
    7867
    79     Sub flushLast()
    80         Dim charConverted As Long
    81         Dim byteBuf[63] As Byte
    82         Dim byteSize As Long
    83         Dim completed As Boolean
    84         Do
    85             encoder.Convert(0, 0, byteBuf, Len(byteBuf), False, charConverted, byteSize, completed)
    86             s.Write(byteBuf, 0, byteSize)
    87         Loop Until completed
     68    Sub softFlush()
     69        Dim buf = Buffer()
     70        Dim pws As PCWSTR
     71        Dim wcSize = GetWCStr(buf.ToString(), pws)
     72        Dim mbMaxSize = e.GetMaxByteCount(wcSize)
     73        Dim mbBuf = GC_malloc_atomic(mbMaxSize) As *Byte
     74        Dim mbBufSize = e.GetBytes(pws, wcSize, mbBuf, mbMaxSize)
     75        s.Write(mbBuf, 0, mbBufSize)
    8876    End Sub
    8977
    90     encoding As Text.Encoding
    91     encoder As Text.Encoder
     78    e As Text.Encoding
    9279    s As System.IO.Stream
    9380End Class
Note: See TracChangeset for help on using the changeset viewer.