Last change
on this file since 695 was 676, checked in by イグトランス (egtra), 16 years ago |
#231に関連して、エンコーディング周りを見直し、Encoder/Decoderをストリーム用に特化。
UTF8Encodingをコンパイル可能にし、ビルドに含めるようにした。ただし、実装が不完全なためテストは不可。
(#231)
|
File size:
1.6 KB
|
Line | |
---|
1 | 'Classes/System/IO/StreamReader.ab
|
---|
2 |
|
---|
3 | 'ToDo: コンソールで入力待ちになる問題への対処
|
---|
4 |
|
---|
5 | Namespace System
|
---|
6 | Namespace IO
|
---|
7 |
|
---|
8 | /*
|
---|
9 | @brief ストリームから読み取りを行うTextReaderの実装。
|
---|
10 | @date 2008/02/25
|
---|
11 | @auther Egtra
|
---|
12 | */
|
---|
13 | Class StreamReader
|
---|
14 | Inherits TextReader
|
---|
15 | Public
|
---|
16 | /*
|
---|
17 | @date 2008/02/25
|
---|
18 | @auther Egtra
|
---|
19 | */
|
---|
20 | Sub StreamReader(path As String)
|
---|
21 | init(New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
---|
22 | End Sub
|
---|
23 |
|
---|
24 | /*
|
---|
25 | @date 2008/02/25
|
---|
26 | @auther Egtra
|
---|
27 | */
|
---|
28 | Sub StreamReader(stream As Stream)
|
---|
29 | init(stream)
|
---|
30 | End Sub
|
---|
31 |
|
---|
32 | Public
|
---|
33 | /*
|
---|
34 | @brief 基になるストリームを取得する
|
---|
35 | @date 2008/09/02
|
---|
36 | @auther NoWest
|
---|
37 | */
|
---|
38 | Function BaseStream () As Stream
|
---|
39 | Return s
|
---|
40 | End Function
|
---|
41 |
|
---|
42 | Protected
|
---|
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
|
---|
52 | End If
|
---|
53 | s = Nothing
|
---|
54 | End Sub
|
---|
55 |
|
---|
56 | /*
|
---|
57 | @date 2008/12/27
|
---|
58 | @auther Egtra
|
---|
59 | */
|
---|
60 | Override Function Underflow() As Boolean
|
---|
61 | Dim buf = Buffer
|
---|
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)
|
---|
67 | buf.Append(s)
|
---|
68 | End Function
|
---|
69 | Private
|
---|
70 |
|
---|
71 | /*
|
---|
72 | @date 2008/02/25
|
---|
73 | @auther Egtra
|
---|
74 | */
|
---|
75 | Sub init(str As Stream)
|
---|
76 | s = str
|
---|
77 | decoder = New Text.Detail.WindowsCodePageDecoder(CP_ACP)
|
---|
78 | End Sub
|
---|
79 |
|
---|
80 | s As Stream
|
---|
81 | decoder As Text.Decoder
|
---|
82 | End Class
|
---|
83 |
|
---|
84 | End Namespace
|
---|
85 | End Namespace
|
---|
Note:
See
TracBrowser
for help on using the repository browser.