Commit 2067c0f3
2067c0f3fe61Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Merge pull request #1110 from neidiom/fix/str-lines-chomp-keyword
Fix String#lines(chomp: true) ignoring the chomp keyword
Details
- Commit
- 2067c0f3fe61
- Parent
- 150932579d02
- Merge parent
- e1cf50f1cc90
lib/sp_runtime.hmodifiedView file
@@ -1302,6 +1302,7 @@
13021302
`end` is computed once at entry so a string with no newlines avoids13031303
a redundant strlen call on the trailing piece. */13041304
static sp_StrArray*sp_str_lines(const char*s){sp_StrArray*a=sp_StrArray_new();if(*s==0)return a;const char*end=s+strlen(s);const char*p=s;while(p<end){const char*nl=strchr(p,'\n');size_t n=nl?(size_t)(nl-p+1):(size_t)(end-p);char*r=sp_str_alloc_raw(n+1);memcpy(r,p,n);r[n]=0;sp_StrArray_push(a,r);if(!nl)break;p=nl+1;}return a;}1305+
static sp_StrArray*sp_str_lines_chomp(const char*s){sp_StrArray*a=sp_StrArray_new();if(*s==0)return a;const char*end=s+strlen(s);const char*p=s;while(p<end){const char*nl=strchr(p,'\n');size_t n=nl?(size_t)(nl-p):(size_t)(end-p);if(nl&&nl>s&&nl[-1]=='\r')n--;char*r=sp_str_alloc_raw(n+1);memcpy(r,p,n);r[n]=0;sp_StrArray_push(a,r);if(!nl)break;p=nl+1;}return a;}13051306
/* Issue #827: gsub previously returned a raw malloc buffer. The GC's13061307
sp_mark_string writes byte[-1] = 0xfc, which on a raw malloc buffer13071308
clobbers malloc metadata. Build into a scratch buffer, then copyspinel_codegen.rbmodifiedView file
Loading diff…
test/str_lines_chomp.rbaddedView file
Loading diff…
test/str_lines_chomp.rb.expectedaddedView file
Loading diff…