fix stringarrayjoin

main
Alan Francis 1 year ago
parent b40e99b48f
commit 1688eabbfd
  1. 10
      containers/stringarray.c

@ -47,22 +47,22 @@ STRPTR StringArrayJoinedParts(StringArray array, BYTE linkCharacter, ULONG start
ULONG index = 0;
ULONG cursor = 0;
STRPTR result = NULL;
ULONG howManyParts = MIN(maxParts, SizeOfArray(array));
ULONG lastIndex = MIN(startIndex+maxParts, SizeOfArray(array)-1);
if( howManyParts <= 0 )
if( lastIndex-startIndex < 0 )
{
return (STRPTR)AllocVec(1, MEMF_CLEAR); //return an empty string
}
for( index = startIndex; index < howManyParts; index++ )
for( index = startIndex; index < lastIndex; index++ )
{
requiredSize += strlen(StringArrayValues(array)[index]);
}
requiredSize += (howManyParts - 1); // add the joins
requiredSize += (maxParts == 0 ? 0 : maxParts - 1); // add the join characters
requiredSize += 1; // trailing NULL
result = AllocVec(requiredSize, MEMF_CLEAR);
for( index = startIndex; index < howManyParts; index++ )
for( index = startIndex; index < lastIndex; index++ )
{
CONST_STRPTR entry = StringArrayValues(array)[index];
CopyMem((STRPTR)entry, result+cursor, strlen(entry));

Loading…
Cancel
Save