Commit e6625e27
e6625e276955Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · ~2 modified
Description
feat: add String#swapcase
Swaps upper- and lowercase letters in a string. Added sp_str_swapcase to runtime.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- e6625e276955
- Parent
- 66496dfba04c
lib/sp_runtime.hmodifiedView file
@@ -156,6 +156,7 @@
156156
static const char*sp_float_to_s(mrb_float f){char*b=(char*)malloc(64);snprintf(b,64,"%g",f);return b;}157157
static const char*sp_str_upcase(const char*s){size_t l=strlen(s);char*r=(char*)malloc(l+1);for(size_t i=0;i<=l;i++)r[i]=toupper((unsigned char)s[i]);return r;}158158
static const char*sp_str_downcase(const char*s){size_t l=strlen(s);char*r=(char*)malloc(l+1);for(size_t i=0;i<=l;i++)r[i]=tolower((unsigned char)s[i]);return r;}159+
static const char*sp_str_swapcase(const char*s){size_t l=strlen(s);char*r=(char*)malloc(l+1);for(size_t i=0;i<=l;i++){unsigned char c=(unsigned char)s[i];if(isupper(c))r[i]=tolower(c);else if(islower(c))r[i]=toupper(c);else r[i]=s[i];}return r;}159160
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;}160161
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;}161162
static mrb_bool sp_str_include(const char*s,const char*sub){return strstr(s,sub)!=NULL;}spinel_codegen.rbmodifiedView file
Loading diff…