MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / str_split

Function str_split

src/lstrlib.cpp:2015–2060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2013
2014
2015static int str_split (lua_State *L) {
2016 /*
2017 This str_split function is based on the one found in LuaU, licensed under their terms.
2018 https://github.com/Roblox/luau/blob/master/VM/src/lstrlib.cpp
2019 */
2020 size_t haystackLen;
2021 const char* haystack = luaL_checklstring(L, 1, &haystackLen);
2022 size_t needleLen;
2023 const char* needle = luaL_checklstring(L, 2, &needleLen);
2024 lua_Integer limit = luaL_optinteger(L, 3, LUA_MAXINTEGER) - 1;
2025
2026 const char* begin = haystack;
2027 const char* end = haystack + haystackLen;
2028 const char* spanStart = begin;
2029 lua_Integer numMatches = 0;
2030
2031 lua_createtable(L, 0, 0);
2032
2033 if (needleLen == 0)
2034 begin++;
2035
2036 if (l_likely(limit > 0)) {
2037 for (const char* iter = begin; iter <= end - needleLen; iter++) {
2038 if (memcmp(iter, needle, needleLen) == 0) {
2039 lua_pushinteger(L, ++numMatches);
2040 lua_pushlstring(L, spanStart, iter - spanStart);
2041 lua_settable(L, -3);
2042
2043 spanStart = iter + needleLen;
2044 if (needleLen > 0)
2045 iter += needleLen - 1;
2046
2047 if (numMatches == limit)
2048 break;
2049 }
2050 }
2051 }
2052
2053 if (needleLen > 0) {
2054 lua_pushinteger(L, ++numMatches);
2055 lua_pushlstring(L, spanStart, end - spanStart);
2056 lua_settable(L, -3);
2057 }
2058
2059 return 1;
2060}
2061
2062
2063static int str_islower (lua_State* L) {

Callers

nothing calls this directly

Calls 5

luaL_checklstringFunction · 0.85
lua_pushintegerFunction · 0.85
lua_pushlstringFunction · 0.85
lua_settableFunction · 0.85
lua_createtableFunction · 0.70

Tested by

no test coverage detected