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/Text/Encoding.ab

    r653 r655  
    353353        ByRef srcUsed As Long, ByRef dstUsed As Long, ByRef completed As Boolean)
    354354
    355         If src = 0 Then
     355        If src = 0 And srcCount > 0 Then
    356356            Throw New ArgumentNullException("src")
    357357        ElseIf srcCount < 0 Then
     
    452452        ByRef srcUsed As Long, ByRef dstUsed As Long, ByRef completed As Boolean)
    453453
    454         If src = 0 Then
     454        If src = 0 And srcCount > 0 Then
    455455            Throw New ArgumentNullException("src")
    456456        ElseIf srcCount < 0 Then
     
    641641
    642642    Override Function GetBytesCountCore(src As *WCHAR, srcCount As Long, flush As Boolean) As Long
     643        GetBytesCountCore = srcCount * 2 + 1 '暫定
    643644    End Function
    644645
     
    658659    Override Sub ConvertCore(src As *Byte, srcCount As Long, dst As *WCHAR, dstCount As Long, flush As Boolean,
    659660        ByRef srcUsed As Long, ByRef dstUsed As Long, ByRef completed As Boolean)
     661
     662        Dim srcPos = 0 As Long
     663        Dim dstPos = 0 As Long
     664        If dstCount > 0 And nextByte <> 0 Then
     665            Dim buf[1] As CHAR
     666            buf[0] = nextByte As CHAR
     667            buf[1] = src[1] As CHAR
     668            Dim len = MultiByteToWideChar(cp, 0, buf, Len(buf), VarPtr(dst[dstPos]), 10)
     669            If len = 0 Then
     670                ActiveBasic.Windows.ThrowWithLastError()
     671            End If
     672            srcPos++
     673            dstPos++
     674            nextByte = 0
     675        End If
     676        While srcPos < srcCount And dstPos < srcCount
     677            Dim srcCharSize = 1 As Long
     678            If IsDBCSLeadByteEx(cp, src[srcPos]) Then
     679                srcCharSize = 2
     680                If srcPos + 1 = srcCount Then
     681                    nextByte = src[srcPos]
     682                    Exit While
     683                End If
     684            End If
     685            '将来的には行毎に変換しMB_USEGLYPHCHARSを使うようにしたい。
     686            Dim len = MultiByteToWideChar(cp, 0, VarPtr(src[srcPos]) As *CHAR, srcCharSize, VarPtr(dst[dstPos]), 1)
     687            If len = 0 Then
     688                ActiveBasic.Windows.ThrowWithLastError()
     689            End If
     690            srcPos += srcCharSize
     691            dstPos++
     692        Wend
     693        srcUsed = srcPos
     694        dstUsed = dstPos
     695        completed = (srcPos = srcCount And dstPos = srcCount And nextByte = 0)
    660696    End Sub
    661697
    662698    Override Function GetCharsCountCore(src As *Byte, srcCount As Long, flush As Boolean) As Long
     699        GetCharsCountCore = srcCount + 1 '暫定
    663700    End Function
    664701
    665702Private
    666703    cp As DWord
     704    nextByte As Byte
    667705End Class
    668706
Note: See TracChangeset for help on using the changeset viewer.