Commit 5fca17b5
5fca17b526f2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Expand sp_String (mutable string) method support
Add 25+ methods to sp_String: downcase, strip, chomp, capitalize, start_with?, end_with?, empty?, sub, ljust, rjust, center, lstrip, rstrip, tr, delete, squeeze, to_i, to_f, count, each_line, freeze, frozen?, chars, bytes, ord, match?
All delegate to existing const char* helpers via sp_String_cstr(), keeping the implementation DRY.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 5fca17b526f2
- Parent
- 5d57abfbfd1d
examples/bm_mutable_str3.rbaddedView file
1+
# Test sp_String (mutable string) additional methods2+
3+
s = ""4+
s << "Hello"5+
s << " "6+
s << "World"7+
puts s.length # 118+
puts s.downcase # hello world9+
puts s.strip # Hello World10+
puts s.capitalize # Hello world11+
12+
puts s.start_with?("Hello") # true13+
puts s.end_with?("World") # true14+
puts s.empty? # false15+
16+
# sub / gsub17+
puts s.gsub("l", "r") # Herro Worrd18+
puts s.sub("World", "Ruby") # Hello Ruby19+
20+
# to_i / to_f21+
n = ""22+
n << "42"23+
puts n.to_i # 4224+
25+
# ljust / rjust26+
t = ""27+
t << "hi"28+
puts t.ljust(10) # "hi "29+
puts t.rjust(10) # " hi"30+
31+
# include?32+
puts s.include?("World") # true33+
puts s.include?("xyz") # false34+
35+
puts "done"src/codegen.cmodifiedView file
Loading diff…