I believe you are right. My problem is with this procedure:
Code:
ProcedureDLL.l ParseString(stringToParse.s, arrayToFill.s(1), delimiter.s) ; Parse a string into an array using a delimiter. Returns count.
; Source: Uses code posted by pdwyer
; http://www.purebasic.fr/english/viewtopic.php?t=31044&highlight=split+string
Structure MemoryArray
Byte.c[0]
word.w[0]
EndStructure
FindLen.l = Len(delimiter)
MainLen.l = Len(stringToParse)
arrayToFill.s(0)
StringCount.l = 0
*MainByteArray.MemoryArray = @stringToParse ;*MainMem
*FindByteArray.MemoryArray = @delimiter ;*FindMem
PrevPos.l = 1
; Build BadChr Array
Dim BadChar.l(255)
; set all alphabet to max shift pos (length of find string plus 1)
For i = 0 To 255
BadChar(i) = FindLen + 1
Next
;Update chars that are in the find string to their position from the end.
For i = 0 To FindLen -1
BadChar(*FindByteArray\Byte[i]) = FindLen - i
Next
MainArrayLoop.l = 1
EndSearchPos.l = MainLen - (FindLen -1)
While MainArrayLoop <= EndSearchPos
If CompareMemory(@stringToParse + MainArrayLoop, @delimiter, FindLen) = 1
FoundPos = MainArrayLoop + 1
Redim arrayToFill.s(StringCount )
;emulate fast mid() function inline,
If FoundPos - PrevPos > 0
*RetMem = AllocateMemory(FoundPos - PrevPos)
CopyMemory(@stringToParse + PrevPos -1, *RetMem, FoundPos - PrevPos)
MidStr.s = PeekS(*RetMem,FoundPos - PrevPos)
FreeMemory(*RetMem)
Else
MidStr.s = ""
EndIf
arrayToFill(StringCount) = MidStr
StringCount = StringCount + 1
PrevPos = FoundPos + FindLen
EndIf
;Didn't find the string so shift as per the table.
MainArrayLoop + BadChar(*MainByteArray.MemoryArray\Byte[MainArrayLoop + FindLen])
Wend
;catch end
Redim arrayToFill.s(StringCount)
arrayToFill(StringCount) = Mid(stringToParse, PrevPos, MainLen - PrevPos +1)
StringCount = StringCount + 1
Redim arrayToFill.s(StringCount)
ProcedureReturn StringCount
EndProcedure