'NOTE: the following subs/functions ar used to gain misc information about byte strings.
'The information functions should be optimized for speed.
Public Function GETBYTESTRINGLENGTH(ByRef ByteString() As Byte) As Long
'on error Resume Next 'returns appearence of first Chr$(0) in ByteString() or UBound(ByteString()); a special algorithm is used that increases the checking speed compared to a simple loop
ByteStringLengthMax = UBound(ByteString())
For TempGlobal = 1& To ByteStringLengthMax Step 2&
If ByteString(TempGlobal) = 0& Then
If Not (TempGlobal = 1&) Then
If ByteString(TempGlobal - 1) = 0& Then
GETBYTESTRINGLENGTH = (TempGlobal - 2&)
Exit Function
Else
GETBYTESTRINGLENGTH = (TempGlobal - 1&)
Exit Function
End If
Else
GETBYTESTRINGLENGTH = (TempGlobal - 1&)
Exit Function
End If
End If
Next TempGlobal
If ByteString(ByteStringLengthMax) = 0& Then
GETBYTESTRINGLENGTH = ByteStringLengthMax - 1&
Else
GETBYTESTRINGLENGTH = ByteStringLengthMax
End If
Exit Function
End Function
Public Function GETBYTESTRINGLENGTHMAX(ByRef ByteString() As Byte) As Long
'on error resume next 'professional-looking UBound()
GETBYTESTRINGLENGTHMAX = UBound(ByteString()) 'ByteString() must have been Dim-ed already
End Function
Public Function BYTESTRINGISEQUAL(ByRef ByteString1() As Byte, ByRef ByteString2() As Byte, ByVal IgnoreCapitalizationFlag As Boolean) As Boolean
'on error Resume Next 'returns True if data (!) in the two passed byte strings is equal
Dim ByteString1LengthGlobal As Long
Dim ByteString2LengthGlobal As Long
Dim TempGlobal As Long
'
'NOTE: when using large loops to check byte strings for equalness,
'first check if (ByteString1(1) = ByteString2(1)) = True before calling
Public Function BYTESTRINGISEQUALFIXED(ByRef ByteString1() As Byte, ByRef ByteString2() As Byte, ByVal IgnoreCapitalizationFlag As Boolean) As Boolean
'on error Resume Next 'returns True if data (!) in the two passed byte strings is equal (both byte strings msut have a fixed length that was previously passed to BYTESTRINGISEQUALFIXED_SETLENGTH())
Dim TempGlobal As Long
'
'NOTE: when using large loops to check byte strings for equalness,
'first check if (ByteString1(1) = ByteString2(1)) = True before calling
'this function.
'
If IgnoreCapitalizationFlag = False Then
For TempGlobal = 1& To ByteStringLengthFixed
If Not (ByteString1(TempGlobal) = ByteString2(TempGlobal)) Then
BYTESTRINGISEQUALFIXED = False
Exit Function
End If
Next TempGlobal
Else
For TempGlobal = 1& To ByteStringLengthFixed
If Not (BYTEUCASE(ByteString1(TempGlobal)) = BYTEUCASE(ByteString2(TempGlobal))) Then
BYTESTRINGISEQUALFIXED = False
Exit Function
End If
Next TempGlobal
End If
BYTESTRINGISEQUALFIXED = True
Exit Function
End Function
'NOTE: the following function was not really faster than the original BYTESTRINGISEQUAL() function.
'Public Function BYTESTRINGISEQUAL2(ByRef ByteString1() As Byte, ByRef ByteString2() As Byte, ByVal IgnoreCapitalizationFlag As Boolean, ByVal ByteString1LengthMax As Long, ByVal ByteString2LengthMax As Long) As Boolean
' 'on error resume next
' Dim Temp As Long
' '
' 'NOTE: this function is faster than BYTESTRINGISEQUAL().
' 'Use this function if the maximal byte string length is known
' '(this function saves GETBYTESTRINGLENGTH() calls).
' '
' 'preset
' 'begin
' If IgnoreCapitalizationFlag = False Then
' For Temp = 1 To BS_MIN(ByteString1LengthMax, ByteString2LengthMax)
' If ByteString1(Temp) = ByteString2(Temp) Then
' 'ok
' Else
' BYTESTRINGISEQUAL2 = False
' Exit Function
' End If
' Next Temp
' If ByteString1LengthMax > ByteString2LengthMax Then
' For Temp = (ByteString2LengthMax + 1&) To ByteString1LengthMax
' If ByteString1(Temp) = 0& Then
' Exit For 'end of string
' Else
' BYTESTRINGISEQUAL2 = False
' Exit Function
' End If
' Next Temp
' Else
' For Temp = (ByteString1LengthMax + 1&) To ByteString2LengthMax
' If ByteString2(Temp) = 0& Then
' Exit For 'end of string
' Else
' BYTESTRINGISEQUAL2 = False
' Exit Function
' End If
' Next Temp
' End If
' Else
' For Temp = 1 To BS_MIN(ByteString1LengthMax, ByteString2LengthMax)
' If BYTEUCASE(ByteString1(Temp)) = BYTEUCASE(ByteString2(Temp)) Then
' 'ok
' Else
' BYTESTRINGISEQUAL2 = False
' Exit Function
' End If
' Next Temp
' If ByteString1LengthMax > ByteString2LengthMax Then
' For Temp = (ByteString2LengthMax + 1&) To ByteString1LengthMax
' If ByteString1(Temp) = 0& Then
' Exit For 'end of string
' Else
' BYTESTRINGISEQUAL2 = False
' Exit Function
' End If
' Next Temp
' Else
' For Temp = (ByteString1LengthMax + 1&) To ByteString2LengthMax
' If ByteString2(Temp) = 0& Then
' Exit For 'end of string
' Else
' BYTESTRINGISEQUAL2 = False
' Exit Function
' End If
' Next Temp
' End If
' End If
' BYTESTRINGISEQUAL2 = True 'if not quit before
' Exit Function
'End Function
Public Function InStrByte(ByVal StartPos As Long, ByRef ByteString1() As Byte, ByRef ByteString2() As Byte, ByVal CompareMethod As Integer) As Long
For Temp = StartPos To GETBYTESTRINGLENGTH(ByteString1())
If ByteString1(Temp) = ByteString2(ByteString2Pos) Then
ByteString2Pos = ByteString2Pos + 1&
If ByteString2Pos > ByteString2Length Then
InStrByte = Temp - ByteString2Pos + 2& 'ok
Exit Function
End If
Else
ByteString2Pos = 1& 'reset (important)
End If
Next Temp
Case Else 'i.e. vbTextCompare
For Temp = StartPos To GETBYTESTRINGLENGTH(ByteString1())
If BYTEUCASE(ByteString1(Temp)) = BYTEUCASE(ByteString2(ByteString2Pos)) Then
ByteString2Pos = ByteString2Pos + 1&
If ByteString2Pos > ByteString2Length Then
InStrByte = Temp - ByteString2Pos + 2& 'ok
Exit Function
End If
Else
ByteString2Pos = 1& 'reset (important)
End If
Next Temp
End Select
InStrByte = 0& 'error
Exit Function
End Function
'NOTE: the following function was not faster than the original InStrByte() function.
'Public Function InStrByte2(ByVal StartPos As Long, ByRef ByteString1() As Byte, ByRef ByteString2() As Byte, ByVal CompareMethod As Integer, ByVal ByteString1LengthMax As Long, ByVal ByteString2LengthMax As Long) As Long
' 'on error resume next
' Dim ByteString2Pos As Long
' Dim ByteString2LengthMaxMinusOne As Long
' Dim Temp As Long
' 'verify
' If StartPos < 1& Then
' InStrByte2 = 0&
' Exit Function
' End If
' If (ByteString2(1) = 0&) Or (ByteString2LengthMax = 0) Then
Public Sub BYTESTRINGCUT(ByRef ByteString() As Byte, ByVal CutStartPos As Long, ByVal CutLength As Long, Optional ByVal RightEndReplaceAsc As Byte = 0, Optional ByVal ByteStringLengthFixedFlag As Boolean = True)
'on error Resume Next 'removes data in byte string leftwards and deltes 'right end' of moved data through overw Case 50Eaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanaaaaaaa=eCharNumber As alue = ReturnValue SthGlobal 'or Byte^ (Number0u(Temeg(1) = 0 'r'ength As Longtype smp - 1&)igthMax Then
' For Temp = (ByteString2LengthMax + 1&) To ByteString1LengthMax