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 methods
2+
3+s = ""
4+s << "Hello"
5+s << " "
6+s << "World"
7+puts s.length # 11
8+puts s.downcase # hello world
9+puts s.strip # Hello World
10+puts s.capitalize # Hello world
11+
12+puts s.start_with?("Hello") # true
13+puts s.end_with?("World") # true
14+puts s.empty? # false
15+
16+# sub / gsub
17+puts s.gsub("l", "r") # Herro Worrd
18+puts s.sub("World", "Ruby") # Hello Ruby
19+
20+# to_i / to_f
21+n = ""
22+n << "42"
23+puts n.to_i # 42
24+
25+# ljust / rjust
26+t = ""
27+t << "hi"
28+puts t.ljust(10) # "hi "
29+puts t.rjust(10) # " hi"
30+
31+# include?
32+puts s.include?("World") # true
33+puts s.include?("xyz") # false
34+
35+puts "done"