/*
* big_explode.c
*
* Opposite of implode()
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
/* big_explode(str, separator)
This function works like explode(), except that it also counts
separators at the start and end of the string. Basically that means
that the array returned is more practical to parse. Explode is found
3-4 times faster than using sscanf, which is over 10 times faster
using the needed functions coded in pure LPC.
*/
static string *big_explode(string str, string sep) {
int stlen, seplen;
string *expl;
expl = ::explode(str, sep);
/*return expl;*/
if ((stlen=strlen(str)) > (seplen=strlen(sep)) && seplen > 0) {
if (str[..seplen-1] == sep)
/* matching separator found at beginning */
expl = ({ "" }) + expl;
if (str[stlen-seplen..] == sep && ::sizeof(expl - ({ "" })))
/* matching separator found at end */
expl += ({ "" });
}
/* got correct array now, return */
return expl;
}
/* big_implode(str, separator)
fully implodes an array of strings, regaining the string from
big_explode(), unlike the relation between explode() and implode()
*/
static string big_implode(string *arr, string sep) {
if (!::sizeof(arr - ({ "" }))) {
/* special array consisting only of separators, add one extra */
arr += ({ "" });
}
return ::implode(arr, sep);
}