Fix corner cases with ExplodeString (bug 4629, r=dvander).
--HG-- extra : rebase_source : ebb338bc93d32544e66c16fcba4494d5eae7ee8e
This commit is contained in:
parent
f3b84b8670
commit
f7364111f2
@ -490,35 +490,34 @@ stock StrCat(String:buffer[], maxlength, const String:source[])
|
|||||||
* @param buffers An array of string buffers (2D array).
|
* @param buffers An array of string buffers (2D array).
|
||||||
* @param maxStrings Number of string buffers (first dimension size).
|
* @param maxStrings Number of string buffers (first dimension size).
|
||||||
* @param maxStringLength Maximum length of each string buffer.
|
* @param maxStringLength Maximum length of each string buffer.
|
||||||
|
* @param copyRemainder False (default) discard excess pieces, true to ignore
|
||||||
|
* delimiters after last piece.
|
||||||
* @return Number of strings retrieved.
|
* @return Number of strings retrieved.
|
||||||
*/
|
*/
|
||||||
stock ExplodeString(const String:text[], const String:split[], String:buffers[][], maxStrings, maxStringLength)
|
stock ExplodeStringLumiStance(const String:text[], const String:split[], String:buffers[][], maxStrings, maxStringLength, bool:copyRemainder = false)
|
||||||
{
|
{
|
||||||
new reloc_idx, idx, total;
|
new reloc_idx, idx, total;
|
||||||
|
|
||||||
if (maxStrings < 1 || split[0] == '\0')
|
if (maxStrings < 1 || !split[0])
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((idx = SplitString(text[reloc_idx], split, buffers[total], maxStringLength)) != -1)
|
while ((idx = SplitString(text[reloc_idx], split, buffers[total], maxStringLength)) != -1)
|
||||||
{
|
{
|
||||||
reloc_idx += idx;
|
reloc_idx += idx;
|
||||||
if (text[reloc_idx] == '\0')
|
if (++total == maxStrings)
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (++total >= maxStrings)
|
|
||||||
{
|
{
|
||||||
|
if (copyRemainder)
|
||||||
|
{
|
||||||
|
strcopy(buffers[total-1], maxStringLength, text[reloc_idx-idx]);
|
||||||
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text[reloc_idx] != '\0' && total <= maxStrings - 1)
|
strcopy(buffers[total++], maxStringLength, text[reloc_idx]);
|
||||||
{
|
|
||||||
strcopy(buffers[total++], maxStringLength, text[reloc_idx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user