'Classes/System/IO/StreamReader.ab Namespace System Namespace IO /* @brief ストリームから読み取りを行うTextReaderの実装。 @date 2008/02/25 @auther Egtra */ Class StreamReader Inherits TextReader Public /* @date 2008/02/25 @auther Egtra */ Sub StreamReader(path As String) init(New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) End Sub /* @date 2008/02/25 @auther Egtra */ Sub StreamReader(stream As Stream) init(stream) End Sub Public /* @brief 基になるストリームを取得する @date 2008/09/02 @auther NoWest */ Function BaseStream () As Stream Return s End Function Protected /* @date 2008/02/25 @auther Egtra */ Override Sub Dispose(disposing As Boolean) If disposing Then If Not ActiveBasic.IsNothing(s) Then s.Dispose(True) End If End If s = Nothing End Sub /* @date 2008/12/27 @auther Egtra */ Override Function Underflow() As Boolean Dim wcBuf[4095] As WCHAR Dim mbBuf[4095] As SByte Dim pNext = mbBuf As PSTR Dim mbBufSize = Len(buf) If leadByte <> 0 Then pNext[0] = leadByte leadByte = 0 pNext++ mbBufSize-- End If Dim mbLen = s.Read(pNext As *Byte, 0, mbBufSize) If mbLen = 0 Then Underflow = False Exit Function End If Do Dim q = CharNextExA(cp, pNext, 0) If q = pNext Then Exit Do End If pNext = q As PSTR Loop If pNext <> mbBuf + mbLen Then leadByte = mbBuf[mbLen - 1] End If Dim wcLen = MultiByteToWideChar(cp, 0, mbBuf, (pNext - mbBuf) As Long, wcBuf, 4095) Dim s = New String(wcBuf, wcLen) Dim buf = Buffer buf.Append(s) Underflow = True End Function Private /* @date 2008/02/25 @auther Egtra */ Sub init(str As Stream) s = str cp = CP_ACP '暫定。 leadByte = 0 End Sub s As Stream cp As Word leadByte As Byte End Class End Namespace End Namespace