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

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

#231に関連して、エンコーディング周りを見直し、Encoder/Decoderをストリーム用に特化。
UTF8Encodingをコンパイル可能にし、ビルドに含めるようにした。ただし、実装が不完全なためテストは不可。
(#231)

File size: 1.6 KB
RevLine 
[432]1'Classes/System/IO/StreamReader.ab
2
[676]3'ToDo: コンソールで入力待ちになる問題への対処
4
[271]5Namespace System
6Namespace IO
7
[432]8/*
9@brief ストリームから読み取りを行うTextReaderの実装。
10@date 2008/02/25
11@auther Egtra
12*/
[426]13Class StreamReader
14 Inherits TextReader
15Public
[432]16 /*
17 @date 2008/02/25
18 @auther Egtra
19 */
[426]20 Sub StreamReader(path As String)
21 init(New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
22 End Sub
[271]23
[432]24 /*
25 @date 2008/02/25
26 @auther Egtra
27 */
[426]28 Sub StreamReader(stream As Stream)
29 init(stream)
30 End Sub
31
[627]32Public
[432]33 /*
[627]34 @brief 基になるストリームを取得する
35 @date 2008/09/02
36 @auther NoWest
37 */
38 Function BaseStream () As Stream
39 Return s
40 End Function
41
[432]42Protected
43 /*
44 @date 2008/02/25
45 @auther Egtra
46 */
47 Override Sub Dispose(disposing As Boolean)
48 If disposing Then
49 If Not ActiveBasic.IsNothing(s) Then
50 s.Dispose(True)
51 End If
[426]52 End If
[432]53 s = Nothing
54 End Sub
[426]55
[432]56 /*
[665]57 @date 2008/12/27
[432]58 @auther Egtra
59 */
[665]60 Override Function Underflow() As Boolean
61 Dim buf = Buffer
[676]62 Dim tmp = New Collections.Generic.List<WCHAR>
63 Underflow = decoder.Decode(tmp, s)
64 'ToDo: 非UNICODEのとき、
65 ' サロゲートペアや結合文字列 (Combining Character Sequence)の途中でバッファが途切れている場合に対応する
66 Dim s = New String(tmp.Data, tmp.Count)
[665]67 buf.Append(s)
[426]68 End Function
[665]69Private
[426]70
[432]71 /*
72 @date 2008/02/25
73 @auther Egtra
74 */
[426]75 Sub init(str As Stream)
76 s = str
[676]77 decoder = New Text.Detail.WindowsCodePageDecoder(CP_ACP)
[426]78 End Sub
79
80 s As Stream
[676]81 decoder As Text.Decoder
[271]82End Class
83
84End Namespace
85End Namespace
Note: See TracBrowser for help on using the repository browser.