码迷,mamicode.com
首页 > 其他好文 > 详细

在lua中从一个字符串中移除空间源码

时间:2017-12-07 11:56:06      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:tdd   sea   lua   org   stat   check   ase   users   string   

/* 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中从一个字符串中移除空间源码

标签:tdd   sea   lua   org   stat   check   ase   users   string   

原文地址:http://www.cnblogs.com/xiyushimei/p/7998259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!