Changeset 673 for branch/egtra-stream-without-en_dec/Classes/System/IO
- Timestamp:
- Jan 5, 2009, 1:40:11 AM (16 years ago)
- Location:
- branch/egtra-stream-without-en_dec/Classes/System/IO
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/egtra-stream-without-en_dec/Classes/System/IO/StreamReader.ab
r666 r673 58 58 */ 59 59 Override Function Underflow() As Boolean 60 Dim wcBuf[4095] As WCHAR 61 Dim mbBuf[4095] As SByte 62 Dim pNext = mbBuf As PSTR 63 Dim mbBufSize = Len(buf) 64 If leadByte <> 0 Then 65 pNext[0] = leadByte 66 leadByte = 0 67 pNext++ 68 mbBufSize-- 69 End If 70 Dim mbLen = s.Read(pNext As *Byte, 0, mbBufSize) 71 If mbLen = 0 Then 60 Dim nextRead As *Byte 61 Dim readSize = s.Read(mbBuf + bufSize, 0, bufCapacity - bufSize) 62 If readSize = 0 Then 63 If bufSize <> 0 Then 64 #ifdef UNCODE 65 Buffer.Append(&hfffd As WCHAR) 66 #else 67 Buffer.Append("?") 68 #endif 69 End If 72 70 Underflow = False 73 71 Exit Function 74 72 End If 73 Dim mbLen = bufSize + readSize 74 '文字全体が揃っている部分を抽出する。 75 Dim pNext = mbBuf 75 76 Do 76 Dim q = CharNextExA(cp, pNext, 0)77 Dim q = e.NextChar(pNext, ((mbBuf + mbLen) - pNext) As Long) 77 78 If q = pNext Then 78 79 Exit Do 79 80 End If 80 pNext = q As PSTR81 pNext = q 81 82 Loop 82 If pNext <> mbBuf + mbLen Then 83 leadByte = mbBuf[mbLen - 1] 83 '文字全体が揃っている部分を変換しTextReaderのバッファに送る。 84 Dim wcBufCapacity = e.GetMaxCharCount(mbLen) 85 Dim wcBuf = GC_malloc_atomic(wcBufCapacity * SizeOf (WCHAR)) As *WCHAR 86 Dim wcLen = e.GetChars(mbBuf, (pNext - mbBuf) As Long, wcBuf, wcBufCapacity) 87 Dim appendStr As PCTSTR 88 Dim appendLen = GetStr(wcBuf, wcLen As SIZE_T, appendStr) 89 Dim readerBuffer = Buffer 90 readerBuffer.Append(appendStr, 0, appendLen) 91 'マルチバイトの揃っていない部分を手前に連れてくる。 92 bufSize = ((mbBuf + mbLen) - pNext) As Long 93 If bufSize <> 0 Then 94 memmove(mbBuf, mbBuf + mbLen, bufSize) 84 95 End If 85 Dim wcLen = MultiByteToWideChar(cp, 0, mbBuf, (pNext - mbBuf) As Long, wcBuf, 4095)86 Dim s = New String(wcBuf, wcLen)87 Dim buf = Buffer88 buf.Append(s)89 96 Underflow = True 90 97 End Function … … 97 104 Sub init(str As Stream) 98 105 s = str 99 cp = CP_ACP '暫定。 100 leadByte = 0 106 e = New Text.Detail.WindowsCodePageEncoding(CP_ACP) '暫定。 107 bufCapacity = 8192 108 mbBuf = GC_malloc_atomic(bufCapacity) As *Byte 109 bufSize = 0 101 110 End Sub 102 111 103 112 s As Stream 104 cp As Word 105 leadByte As Byte 113 e As Text.Encoding 114 mbBuf As *Byte 115 bufSize As Long 116 bufCapacity As Long 106 117 End Class 107 118 -
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 -
branch/egtra-stream-without-en_dec/Classes/System/IO/TextWriter.ab
r665 r673 86 86 End Sub 87 87 88 Sub WriteLine()88 Virtual Sub WriteLine() 89 89 Write(Environment.NewLine) 90 90 End Sub
Note:
See TracChangeset
for help on using the changeset viewer.