Ignore:
Timestamp:
Nov 9, 2008, 2:21:49 PM (15 years ago)
Author:
イグトランス (egtra)
Message:

#161完了。StreamReaderのUnicode対応。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/IO/TextReader.ab

    r497 r655  
    1 NameSpace System
    2 NameSpace IO
     1Namespace System
     2Namespace IO
    33
    44Class TextReader
    55    Implements System.IDisposable
    6 
    7 Public
    8 'Protected
    9     Sub TextReader()
    10     End Sub
    116Public
    127    Virtual Sub ~TextReader()
     
    3126    @auther Egtra
    3227    */
    33     Function Read(buffer As *Char, index As Long, count As Long) As Long
     28    Function Read(buffer As *WCHAR, index As Long, count As Long) As Long
    3429        If buffer = 0 Then
     30            Throw New ArgumentNullException("buffer")
    3531        ElseIf index < 0 Then
     32            Throw New ArgumentOutOfRangeException("index")
    3633        ElseIf count < 0 Then
     34            Throw New ArgumentOutOfRangeException("count")
    3735        End If
    38         Read = ReadImpl(buffer, index, count)
     36        Read = ReadImpl(VarPtr(buffer[index]), count)
     37    End Function
     38
     39    Static Function Synchronized(reader As TextReader) As TextReader
     40        Synchronized = New Detail.SynchronizedTextReader(reader)
    3941    End Function
    4042
     
    4547    @retval 有効なStringインスタンス 読み取った1行
    4648    */
    47     Virtual Function ReadLine() As String
     49    Function ReadLine() As String
    4850        If Peek() = -1 Then
    4951            Exit Function
    5052        End If
    51         Dim sb = New Text.StringBuilder(256)
     53        Dim sb = New Collections.Generic.List<WCHAR>
    5254        Do
    5355            Dim ch = Read()
     
    6971                Case &h0D 'CR
    7072                    Exit Do
    71 '               Case &h85 'NEL
    72 '                   Exit Do
    73 '               Case &h2028 'LS
    74 '                   Exit Do
    75 '               Case &h2029 'PS
    76 '                   Exit Do
     73                Case &h85 'NEL
     74                    Exit Do
     75                Case &h2028 'LS
     76                    Exit Do
     77                Case &h2029 'PS
     78                    Exit Do
    7779            End Select
    78             sb.Append(ch As Char) 'ToDo キャスト不要にすべきというチケットを書くこと
     80            sb.Add(ch As WCHAR)
    7981        Loop
    80         ReadLine = sb.ToString
     82        ReadLine = New String(sb As *WCHAR, sb.Count)
    8183    End Function
    8284    /*
     
    9799    End Function
    98100
    99     Static Function Synchronized(reader As TextReader) As TextReader
    100         Synchronized = New Detail.SynchronizedTextReader(reader)
    101     End Function
     101Protected
     102    Sub TextReader()
     103    End Sub
    102104
    103 Protected
    104105    Virtual Sub Dispose(disposing As Boolean)
    105106    End Sub
     
    109110    @auther Egtra
    110111    */
    111     Virtual Function ReadImpl(buffer As *Char, index As Long, count As Long) As Long
     112    Virtual Function ReadImpl(buffer As *WCHAR, count As Long) As Long
    112113        Dim i As Long
    113         Dim p = VarPtr(buffer[index])
    114114        For i = 0 To ELM(count)
    115115            Dim c = Read()
    116116            If c = -1 Then
    117                 ReadImpl = i - 1
     117                ReadImpl = i
    118118                Exit Function
    119119            Else
    120                 p[i] = c As Char
     120                buffer[i] = c As Char
    121121            End If
    122122        Next
    123         ReadImpl = i - 1
     123        ReadImpl = i
    124124    End Function
    125125End Class
     
    147147    End Function
    148148
    149     Override Function ReadLine() As String
    150 '       Using lock = cs.Lock
    151             ReadLine = base.ReadLine
    152 '       End Using
    153     End Function
    154 
    155     Override Function ReadToEnd() As String
    156 '       Using lock = cs.Lock
    157             ReadToEnd = base.ReadToEnd
    158 '       End Using
    159     End Function
    160 
    161149Protected
    162150    Override Sub Dispose(disposing As Boolean)
     
    171159    End Sub
    172160
    173     Override Function ReadImpl(buffer As *Char, index As Long, count As Long) As Long
     161    Override Function ReadImpl(buffer As *WCHAR, count As Long) As Long
    174162'       Using lock = cs.Lock
    175             ReadImpl = base.ReadImpl(buffer, index, count)
     163            ReadImpl = base.ReadImpl(buffer, count)
    176164'       End Using
    177165    End Function
     
    183171End Namespace
    184172
    185 End NameSpace
    186 End NameSpace
     173End Namespace
     174End Namespace
Note: See TracChangeset for help on using the changeset viewer.