Ignore:
Timestamp:
Feb 16, 2009, 4:26:24 PM (15 years ago)
Author:
イグトランス (egtra)
Message:

UTF8Encodingクラスをとりあえず使える状態に。ただし、BOM出力はまだ不可能。
(#231)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/Text/Encoding.ab

    r676 r682  
    7474    @date   2007/12/08
    7575    */
    76     Abstract Function GetBytesCountCore(src As *WCHAR, srcCount As Long) As Long
     76    Virtual Function GetBytesCountCore(src As *WCHAR, srcCount As Long) As Long
     77        Dim s = New IO.Detail.WriteCountingNullStream
     78        GetEncoder().Encode(src, srcCount, s, True)
     79        GetBytesCountCore = s.WriteCount
     80        If GetBytesCountCore < 0 Then
     81            Throw New OverflowException
     82        End If
     83    End Function
    7784Public
    7885    /*!
     
    110117    @date   2007/12/08
    111118    */
    112     Abstract Function GetBytesCore(src As *WCHAR, srcCount As Long, dst As *Byte, dstCount As Long) As Long
     119    Virtual Function GetBytesCore(src As *WCHAR, srcCount As Long, dst As *Byte, dstCount As Long) As Long
     120        Dim s = New IO.MemoryStream
     121        GetEncoder().Encode(src, srcCount, s, True)
     122        Dim size = s.Position()
     123        If size > (dstCount As QWord) Then
     124            Throw New ArgumentException("dstCount")
     125        End If
     126        GetBytesCore = size As Long
     127        memcpy(dst, s.ToPointer(), size As SIZE_T)
     128    End Function
    113129Public
    114130    /*!
     
    136152    @date   2007/12/08
    137153    */
    138     Abstract Function GetCharsCountCore(src As *Byte, srcCount As Long) As Long
     154    Virtual Function GetCharsCountCore(src As *Byte, srcCount As Long) As Long
     155        Dim s = New IO.MemoryStream(src, srcCount)
     156        Dim l = New Collections.Generic.List<WCHAR>
     157        GetDecoder().Decode(l, s)
     158        GetCharsCountCore = l.Count
     159    End Function
    139160Public
    140161    /*!
     
    172193    @date   2007/12/08
    173194    */
    174     Abstract Function GetCharsCore(src As *Byte, srcCount As Long, dst As *WCHAR, dstCount As Long) As Long
     195    Virtual Function GetCharsCore(src As *Byte, srcCount As Long, dst As *WCHAR, dstCount As Long) As Long
     196        Dim s = New IO.MemoryStream(src, srcCount)
     197        Dim l = New Collections.Generic.List<WCHAR>
     198        GetDecoder().Decode(l, s)
     199        If l.Count > dstCount Then
     200            Throw New ArgumentException("dstCount")
     201        End If
     202        Dim p As *WCHAR
     203        p = l
     204        memcpy(dst, p, (l.Count As SIZE_T) * 2)
     205    End Function
    175206Public
    176207#ifdef UNICODE
Note: See TracChangeset for help on using the changeset viewer.