在lua中從一個字符串中移除空間源碼
阿新 • • 發佈:2017-12-07
gis iss 字符 ase sea 移除 lists 字符串 std
/* trim.c - based on http://lua-users.org/lists/lua-l/2009-12/msg00951.html from Sean Conner */ #include <stddef.h> #include <ctype.h> #include <lua.h> #include <lauxlib.h> int trim(lua_State *L) { const char *front; const char *end; size_t size; front = luaL_checklstring(L,1,&size); end = &front[size - 1]; for ( ; size && isspace(*front) ; size-- , front++) ; for ( ; size && isspace(*end) ; size-- , end--) ; lua_pushlstring(L,front,(size_t)(end - front) + 1); return 1; } int luaopen_trim(lua_State *L) { lua_register(L,"trim",trim); return 0; }
在lua中從一個字符串中移除空間源碼