- Timestamp:
- Jan 5, 2009, 1:40:11 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/egtra-stream-without-en_dec/Classes/System/IO/StreamWriter.ab
r653 r673 41 41 42 42 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() 59 50 End Sub 60 51 … … 63 54 If disposing Then 64 55 Flush() 65 flushLast()66 56 s.Dispose() 67 57 End If … … 73 63 buf = New Text.StringBuilder(4096) 74 64 '暫定。正式版ではUTF-8を標準とする。 75 encoding = New Text.Detail.WindowsCodePageEncoding(CP_ACP) 76 encoder = encoding.GetEncoder() 65 e = New Text.Detail.WindowsCodePageEncoding(CP_ACP) 77 66 End Sub 78 67 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) 88 76 End Sub 89 77 90 encoding As Text.Encoding 91 encoder As Text.Encoder 78 e As Text.Encoding 92 79 s As System.IO.Stream 93 80 End Class
Note:
See TracChangeset
for help on using the changeset viewer.