src/lwowlib.c
static int wow_strsplit(lua_State *L)
{
	const char *sep = luaL_checkstring(L, 1);
	const char *str = luaL_checkstring(L, 2);
	int limit = luaL_optint(L, 3, 0);
	int count = 0;
	/* Set the stack to a predictable size */
	lua_settop(L, 0);
	/* Initialize the result count */
	/* Tokenize the string */
	if(!limit || limit > 1) {
		const char *end = str;
		while(*end) {
			int issep = 0;
			const char *s = sep;
			for(; *s; ++s) {
				if(*s == *end) {
					issep = 1;
					break;
				}
			}
			if(issep) {
				luaL_checkstack(L, count+1, "too many results");
				lua_pushlstring(L, str, (end-str));
				++count;
				str = end+1;
				if(count == (limit-1)) {
					break;
				}
			}
			++end;
		}
	}
	/* Add the remainder */
	luaL_checkstack(L, count+1, "too many results");
	lua_pushstring(L, str);
	++count;
	/* Return with the number of values found */
	return count;
}
/* strsplit & strjoin adapted from code by Norganna */
strsplit & strjoin adapted from code by Norganna
strsplit & strjoin adapted from code by Norganna
static int wow_strsplit(lua_State *L)
{
	const char *sep = luaL_checkstring(L, 1);
	const char *str = luaL_checkstring(L, 2);
	int limit = luaL_optint(L, 3, 0);
	int count = 0;
	lua_settop(L, 0);
	if(!limit || limit > 1) {
		const char *end = str;
		while(*end) {
			int issep = 0;
			const char *s = sep;
			for(; *s; ++s) {
				if(*s == *end) {
					issep = 1;
					break;
				}
			}
			if(issep) {
				luaL_checkstack(L, count+1, "too many results");
				lua_pushlstring(L, str, (end-str));
				++count;
				str = end+1;
				if(count == (limit-1)) {
					break;
				}
			}
			++end;
		}
	}
	luaL_checkstack(L, count+1, "too many results");
	lua_pushstring(L, str);
	++count;
	return count;
}
static int wow_strsplit ( lua_State * L ) { const char * sep = luaL_checkstring ( L , 1 ) ; const char * str = luaL_checkstring ( L , 2 ) ; int limit = luaL_optint ( L , 3 , 0 ) ; int count = 0 ; lua_settop ( L , 0 ) ; if ( ! limit || limit > 1 ) { const char * end = str ; while ( * end ) { int issep = 0 ; const char * s = sep ; for ( ; * s ; ++ s ) { if ( * s == * end ) { issep = 1 ; break ; } } if ( issep ) { luaL_checkstack ( L , count + 1 , " " ) ; lua_pushlstring ( L , str , ( end - str ) ) ; ++ count ; str = end + 1 ; if ( count == ( limit - 1 ) ) { break ; } } ++ end ; } } luaL_checkstack ( L , count + 1 , " " ) ; lua_pushstring ( L , str ) ; ++ count ; return count ; }
strsplit & strjoin adapted from code by Norganna
strsplit & strjoin adapted from code by Norganna
/* Set the stack to a predictable size */ /* Initialize the result count */ /* Tokenize the string */ /* Add the remainder */ /* Return with the number of values found */