source: trunk/ab5.0/ablib/src/Classes/System/IO/StreamReader.ab@ 665

Last change on this file since 665 was 665, checked in by イグトランス (egtra), 15 years ago

TextWriter同様TextReaderでバッファリングし、StreamReaderはMultiByteToWideChar固定で仮実装。これで、マルチバイトモードでもStringReaderが使えるようにした。
(#235)

File size: 1.8 KB
RevLine 
[432]1'Classes/System/IO/StreamReader.ab
2
[271]3Namespace System
4Namespace IO
5
[432]6/*
7@brief ストリームから読み取りを行うTextReaderの実装。
8@date 2008/02/25
9@auther Egtra
10*/
[426]11Class StreamReader
12 Inherits TextReader
13Public
[432]14 /*
15 @date 2008/02/25
16 @auther Egtra
17 */
[426]18 Sub StreamReader(path As String)
19 init(New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
20 End Sub
[271]21
[432]22 /*
23 @date 2008/02/25
24 @auther Egtra
25 */
[426]26 Sub StreamReader(stream As Stream)
27 init(stream)
28 End Sub
29
[627]30Public
[432]31 /*
[627]32 @brief 基になるストリームを取得する
33 @date 2008/09/02
34 @auther NoWest
35 */
36 Function BaseStream () As Stream
37 Return s
38 End Function
39
[426]40
[432]41Protected
42 /*
43 @date 2008/02/25
44 @auther Egtra
45 */
46 Override Sub Dispose(disposing As Boolean)
47 If disposing Then
48 If Not ActiveBasic.IsNothing(s) Then
49 s.Dispose(True)
50 End If
[426]51 End If
[432]52 s = Nothing
53 End Sub
[426]54
[432]55 /*
[665]56 @date 2008/12/27
[432]57 @auther Egtra
58 */
[665]59 Override Function Underflow() As Boolean
60 Dim wcBuf[4095] As WCHAR
61 Dim mbBuf[4095] As SByte
62 Dim mbLen = s.Read(mbBuf As *Byte, 0, Len(buf))
63 If mbLen = 0 Then
64 Underflow = False
[426]65 Exit Function
66 End If
[665]67 Dim pNext = mbBuf As PSTR
68 Do
69 Dim q = CharNextExA(cp, pNext, 0)
70 If q = pNext Then
71 Exit Do
72 End If
73 pNext = q As PSTR
74 Loop
75 If pNext <> mbBuf + mbLen Then
76 leadByte = mbBuf[mbLen - 1]
[426]77 End If
[665]78 Dim wcLen = MultiByteToWideChar(cp, 0, mbBuf, (pNext - mbBuf) As Long, wcBuf, 4095)
79 Dim s = New String(wcBuf, wcLen)
80 Dim buf = Buffer
81 buf.Append(s)
82 Underflow = True
[426]83 End Function
[665]84Private
[426]85
[432]86 /*
87 @date 2008/02/25
88 @auther Egtra
89 */
[426]90 Sub init(str As Stream)
91 s = str
[665]92 cp = CP_ACP '暫定。
93 leadByte = 0
[426]94 End Sub
95
96 s As Stream
[665]97 cp As Word
98 leadByte As Byte
[271]99End Class
100
101End Namespace
102End Namespace
Note: See TracBrowser for help on using the repository browser.