Commit 7f3ee54d
7f3ee54de9c0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · ~2 modified
Description
feat: add Kernel#readlines
Reads all lines from stdin into a str_array using fgets. Added sp_readlines to runtime.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 7f3ee54de9c0
- Parent
- b199b1def745
lib/sp_runtime.hmodifiedView file
@@ -172,6 +172,7 @@
172172
static const char*sp_str_delete_prefix(const char*s,const char*p){size_t sl=strlen(s),pl=strlen(p);if(pl<=sl&&memcmp(s,p,pl)==0){char*r=(char*)malloc(sl-pl+1);memcpy(r,s+pl,sl-pl+1);return r;}char*r=(char*)malloc(sl+1);memcpy(r,s,sl+1);return r;}173173
static const char*sp_str_delete_suffix(const char*s,const char*p){size_t sl=strlen(s),pl=strlen(p);if(pl<=sl&&memcmp(s+sl-pl,p,pl)==0){char*r=(char*)malloc(sl-pl+1);memcpy(r,s,sl-pl);r[sl-pl]=0;return r;}char*r=(char*)malloc(sl+1);memcpy(r,s,sl+1);return r;}174174
static const char*sp_gets(void){char buf[4096];if(!fgets(buf,sizeof(buf),stdin))return NULL;size_t l=strlen(buf);char*r=(char*)malloc(l+1);memcpy(r,buf,l+1);return r;}175+
static sp_StrArray*sp_readlines(void){sp_StrArray*a=sp_StrArray_new();char buf[4096];while(fgets(buf,sizeof(buf),stdin)){size_t l=strlen(buf);char*r=(char*)malloc(l+1);memcpy(r,buf,l+1);sp_StrArray_push(a,r);}return a;}175176
static const char*sp_str_strip(const char*s){while(*s&&isspace((unsigned char)*s))s++;size_t l=strlen(s);while(l>0&&isspace((unsigned char)s[l-1]))l--;char*r=(char*)malloc(l+1);memcpy(r,s,l);r[l]=0;return r;}176177
static const char*sp_str_chomp(const char*s){size_t l=strlen(s);while(l>0&&(s[l-1]=='\n'||s[l-1]=='\r'))l--;char*r=(char*)malloc(l+1);memcpy(r,s,l);r[l]=0;return r;}177178
static mrb_bool sp_str_include(const char*s,const char*sub){return strstr(s,sub)!=NULL;}spinel_codegen.rbmodifiedView file
Loading diff…