📄 asciiencoding.cls
字号:
End Function
''
' Returns the maximum number of characters than can be decoded from the number of bytes specified.
'
' @param ByteCount The number of bytes to be decoded.
' @return The maximum number of characters that can be decoded from the specified number of bytes.
' @see Encoding
'
Public Function GetMaxCharCount(ByVal ByteCount As Long) As Long
If ByteCount < 0 Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_NeedNonNegNum), "ByteCount", ByteCount)
GetMaxCharCount = ByteCount
End Function
''
' Returns the maximum number of bytes that can be created from a specific number of characters.
'
' @param CharCount The number of characters to be encoded.
' @return The maximum number of bytes that can be generated from the specified number of characters.
' @see Encoding
'
Public Function GetMaxByteCount(ByVal CharCount As Long) As Long
If CharCount < 0 Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_NeedNonNegNum), "CharCount", CharCount)
GetMaxByteCount = CharCount
End Function
''
' Returns an encoder that maintains state.
'
' @return The stateful encoder.
' @remarks Since encoding Unicode characters equates to exactly 2 bytes per
' character, there is no state that is maintained between calls. This method
' functions identically to GetBytes.
' @see Encoding
'
Public Function GetEncoder() As Encoder
Dim Ret As New DefaultEncoder
Call Ret.Init(Me)
Set GetEncoder = Ret
End Function
''
' Returns a decoder that maintains state.
'
' @return The stateful decoder.
' @remarks Unlike UnicodeEncoding, the decoder maintains state between decoding calls.
' Since a single unicode character required exactly 2 bytes to be decoded, it is possible
' that an odd number of bytes may be attempted to be decoding, creating an orphaned byte
' which represents only half of a unicode character. The remaining byte is held until
' the next decoding call, and the byte is then inserted at the beginning of the next set
' of bytes to be decoded, picking up byte decoding where the orphaned byte left off.
' @see Encoding
'
Public Function GetDecoder() As Decoder
Dim Ret As New DefaultDecoder
Call Ret.Init(Me)
Set GetDecoder = Ret
End Function
''
' Returns an array of bytes that represents this encoding.
'
' @return A byte array containg the bytes to be used to identify this encoding type.
' @remarks <p>If the encoding was created setting the <i>BigEndian</i> paramter
' to true, then this will return the Unicode byte array identifer &HFEFF otherwise
' &hFFFE for a non-bigEndian encoding. If no identifier is to be emitted, then an
' empty byte array is returned (not a null array).
' @see Encoding
'
Public Function GetPreamble() As Byte()
GetPreamble = Cor.NewBytes()
End Function
''
' Decodes a set of bytes into a String.
'
' @param Bytes The set of bytes to be decoded into a string.
' @param Index The index of the first byte to be decoded.
' @param Count The number of bytes to be used in the decoding.
' @return A string containing the decoded set of bytes.
' @see Encoding
'
Public Function GetString(ByRef Bytes() As Byte, Optional ByRef Index As Variant, Optional ByRef Count As Variant) As String
Dim ElemIndex As Long
Dim ElemCount As Long
Dim Result As Long
Result = GetOptionalArrayRange(SAPtr(Bytes), Index, ElemIndex, Count, ElemCount)
If Result <> NO_ERROR Then Call ThrowArrayRangeException(Result, "Bytes", ElemIndex, "Index", ElemCount, "Count", IsMissing(Index))
GetString = SysAllocStringLen(0, ElemCount)
Call AttachChars(GetString, mChars, mCharsSA)
' With mCharsSA
' .pvData = StrPtr(GetString)
' .lLbound = 0
' .cElements = ElemCount
' End With
' SAPtr(mChars) = VarPtr(mCharsSA)
Call InternalGetChars(Bytes, ElemIndex, ElemCount, mChars, 0)
End Function
''
' Returns a string representation of this object instance.
'
' @return String representing this instance.
' @see IObject
'
Public Function ToString() As String
ToString = Object.ToString(Me, App)
End Function
''
' Returns a boolean indicating if the value and this object
' instance are the same instance.
'
' @param value The value to compare equality to.
' @return Boolean indicating equality.
' @see IObject
'
Public Function Equals(ByRef Value As Variant) As Boolean
Equals = Object.Equals(Me, Value)
End Function
''
' Returns a pseudo-unique number identifying this instance.
'
' @return Pseudo-unique number identifying this instance.
' @see IObject
'
Public Function GetHashCode() As Long
GetHashCode = CODE_PAGE
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Private Helpers
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function InternalGetBytes(ByRef Chars() As Integer, ByVal Index As Long, ByVal Count As Long, ByRef Bytes() As Byte, ByVal ByteIndex As Long) As Long
If cArray.IsNull(Bytes) Then _
Throw Cor.NewArgumentNullException(Environment.GetResourceString(ArgumentNull_Array), "Bytes")
If ByteIndex < LBound(Bytes) Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_LBound), "ByteIndex", ByteIndex)
If ByteIndex + Count - 1 > UBound(Bytes) Then Call SmallBufferError("Bytes")
Dim i As Long
Dim Ch As Long
For i = 0 To Count - 1
Ch = Chars(Index + i)
Select Case Ch
' we need to have a range because by using Integers to
' represent unicode characters, we could end up with
' negative numbers.
Case 0 To 127: Bytes(ByteIndex + i) = Ch
Case Else: Bytes(ByteIndex + i) = BYTE_QUESTION_MARK
End Select
Next i
InternalGetBytes = Count
End Function
Private Sub SmallBufferError(ByVal ParamName As String)
Throw Cor.NewArgumentException(Environment.GetResourceString(Argument_SmallConversionBuffer), ParamName)
End Sub
Private Function InternalGetChars(ByRef Bytes() As Byte, ByVal ByteIndex As Long, ByVal ByteCount As Long, ByRef Chars() As Integer, ByVal CharIndex As Long) As Long
If cArray.IsNull(Chars) Then _
Throw Cor.NewArgumentNullException(Environment.GetResourceString(ArgumentNull_Array), "Chars")
If CharIndex < LBound(Chars) Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_LBound), "ByteIndex", ByteIndex)
If CharIndex + ByteCount - 1 > UBound(Chars) Then Call SmallBufferError("Chars")
Dim i As Long
Dim b As Byte
For i = 0 To ByteCount - 1
b = Bytes(ByteIndex + i)
If b < 128 Then
Chars(CharIndex + i) = b
Else
Chars(CharIndex + i) = BYTE_QUESTION_MARK
End If
Next i
InternalGetChars = ByteCount
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Terminate()
SAPtr(mChars) = 0
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Equals(Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = GetHashCode
End Function
Private Function IObject_ToString() As String
IObject_ToString = ToString
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Encoding Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get Encoding_BodyName() As String
Encoding_BodyName = BodyName
End Property
Private Property Get Encoding_CodePage() As Long
Encoding_CodePage = CodePage
End Property
Private Property Get Encoding_EncodingName() As String
Encoding_EncodingName = EncodingName
End Property
Private Function Encoding_Equals(Value As Variant) As Boolean
Encoding_Equals = Equals(Value)
End Function
Private Function Encoding_GetByteCount(Chars As Variant, Optional Index As Variant, Optional Count As Variant) As Long
Encoding_GetByteCount = GetByteCount(Chars, Index, Count)
End Function
Private Function Encoding_GetBytes(Chars As Variant, Optional Index As Variant, Optional Count As Variant) As Byte()
Encoding_GetBytes = GetBytes(Chars, Index, Count)
End Function
Private Function Encoding_GetBytesEx(Chars As Variant, ByVal CharIndex As Long, ByVal CharCount As Long, Bytes() As Byte, ByVal ByteIndex As Long) As Long
Encoding_GetBytesEx = GetBytesEx(Chars, CharIndex, CharCount, Bytes, ByteIndex)
End Function
Private Function Encoding_GetCharCount(Bytes() As Byte, Optional Index As Variant, Optional Count As Variant) As Long
Encoding_GetCharCount = GetCharCount(Bytes, Index, Count)
End Function
Private Function Encoding_GetChars(Bytes() As Byte, Optional Index As Variant, Optional Count As Variant) As Integer()
Encoding_GetChars = GetChars(Bytes, Index, Count)
End Function
Private Function Encoding_GetCharsEx(Bytes() As Byte, ByVal ByteIndex As Long, ByVal ByteCount As Long, Chars() As Integer, ByVal CharIndex As Long) As Long
Encoding_GetCharsEx = GetCharsEx(Bytes, ByteIndex, ByteCount, Chars, CharIndex)
End Function
Private Function Encoding_GetDecoder() As Decoder
Set Encoding_GetDecoder = GetDecoder
End Function
Private Function Encoding_GetEncoder() As Encoder
Set Encoding_GetEncoder = GetEncoder
End Function
Private Function Encoding_GetHashCode() As Long
Encoding_GetHashCode = GetHashCode
End Function
Private Function Encoding_GetMaxByteCount(ByVal CharCount As Long) As Long
Encoding_GetMaxByteCount = GetMaxByteCount(CharCount)
End Function
Private Function Encoding_GetMaxCharCount(ByVal ByteCount As Long) As Long
Encoding_GetMaxCharCount = GetMaxCharCount(ByteCount)
End Function
Private Function Encoding_GetPreamble() As Byte()
Encoding_GetPreamble = GetPreamble
End Function
Private Function Encoding_GetString(Bytes() As Byte, Optional Index As Variant, Optional Count As Variant) As String
Encoding_GetString = GetString(Bytes, Index, Count)
End Function
Private Property Get Encoding_HeaderName() As String
Encoding_HeaderName = HeaderName
End Property
Private Property Get Encoding_IsBrowserDisplay() As Boolean
Encoding_IsBrowserDisplay = IsBrowserDisplay
End Property
Private Property Get Encoding_IsBrowserSave() As Boolean
Encoding_IsBrowserSave = IsBrowserSave
End Property
Private Property Get Encoding_IsMailNewsDisplay() As Boolean
Encoding_IsMailNewsDisplay = IsMailNewsDisplay
End Property
Private Property Get Encoding_IsMailNewsSave() As Boolean
Encoding_IsMailNewsSave = IsMailNewsSave
End Property
Private Function Encoding_ToString() As String
Encoding_ToString = ToString
End Function
Private Property Get Encoding_WebName() As String
Encoding_WebName = WebName
End Property
Private Property Get Encoding_WindowsCodePage() As Long
Encoding_WindowsCodePage = WindowsCodePage
End Property
Private Property Get Encoding_IsSingleByte() As Boolean
Encoding_IsSingleByte = IsSingleByte
End Property
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -