Commit 883d2093
883d2093a2a0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
Add 13 String methods, string comparison, repetition, split
New String methods: strip, chomp, capitalize, reverse, count(chars), start_with?, end_with?, gsub(from,to), sub(from,to), split(delim) → sp_StrArray
String operators: == != < > <= >= → strcmp-based comparison "str" * n → sp_str_repeat (string repetition)
Also adds sp_StrArray type (SPINEL_TYPE_STR_ARRAY) for split results, with length/size method.
Test: examples/bm_strings2.rb — 14 assertions, all match Ruby. All regressions pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 883d2093a2a0
- Parent
- 5e927e868e36
examples/bm_strings2.rbaddedView file
1+
# Test additional String methods2+
3+
str = " Hello, World! "4+
puts str.strip # "Hello, World!"5+
puts str.chomp # " Hello, World! " (no trailing newline)6+
7+
s = "hello world"8+
puts s.capitalize # "Hello world"9+
puts s.reverse # "dlrow olleh"10+
puts s.count("lo") # 511+
puts s.start_with?("hel") # true12+
puts s.end_with?("rld") # true13+
puts s.gsub("l", "L") # heLLo worLd14+
puts s.sub("o", "0") # hell0 world15+
puts s.split(" ").length # 216+
17+
# String repeat18+
puts "ha" * 3 # hahaha19+
20+
# String comparison21+
puts "abc" == "abc" # true22+
puts "abc" == "def" # false23+
puts "abc" < "def" # truesrc/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…