Changeset 676 for trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab
- Timestamp:
- Jan 13, 2009, 2:01:38 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab
r653 r676 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 Flush(False) 44 End Sub 45 46 Sub Flush(last As Boolean) 47 #ifdef UNICODE 48 encoder.Encode(StrPtr(buf), buf.Length As SIZE_T, s, last) 49 buf.Remove(0, buf.Length As SIZE_T) 50 #else 51 Dim p = StrPtr(buf) 52 Dim i = 0 As SIZE_T 53 Dim mbLen = 0 As SIZE_T 54 While i <= buf.Length 55 mbLen = i 56 'ヌル文字で終わっていないので、CharNextは使えない 57 If IsDBCSLeadByte(p[i]) Then 58 i += 2 59 Else 60 i += 1 61 End If 62 Wend 63 Dim wcBuf As PCWSTR 64 Dim wcLen = GetStr(p, mbLen, wcBuf) 65 encoder.Encode(wcBuf, wcLen, s, last) 66 buf.Remove(0, mbLen) 67 If last Then 68 If buf.Length <> 0 Then 69 s.WriteByte(Asc("?")) 70 buf.Length = 0 71 End If 72 End If 73 #endif 59 74 End Sub 60 75 … … 62 77 Override Sub Dispose(disposing As Boolean) 63 78 If disposing Then 64 Flush() 65 flushLast() 79 Flush(True) 66 80 s.Dispose() 67 81 End If … … 73 87 buf = New Text.StringBuilder(4096) 74 88 '暫定。正式版ではUTF-8を標準とする。 75 encoding = New Text.Detail.WindowsCodePageEncoding(CP_ACP) 76 encoder = encoding.GetEncoder() 89 encoder = New Text.Detail.WindowsCodePageEncoder(CP_ACP) 77 90 End Sub 78 91 79 Sub flushLast()80 Dim charConverted As Long81 Dim byteBuf[63] As Byte82 Dim byteSize As Long83 Dim completed As Boolean84 Do85 encoder.Convert(0, 0, byteBuf, Len(byteBuf), False, charConverted, byteSize, completed)86 s.Write(byteBuf, 0, byteSize)87 Loop Until completed88 End Sub89 90 encoding As Text.Encoding91 92 encoder As Text.Encoder 92 93 s As System.IO.Stream
Note:
See TracChangeset
for help on using the changeset viewer.