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 methods
2+
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") # 5
11+puts s.start_with?("hel") # true
12+puts s.end_with?("rld") # true
13+puts s.gsub("l", "L") # heLLo worLd
14+puts s.sub("o", "0") # hell0 world
15+puts s.split(" ").length # 2
16+
17+# String repeat
18+puts "ha" * 3 # hahaha
19+
20+# String comparison
21+puts "abc" == "abc" # true
22+puts "abc" == "def" # false
23+puts "abc" < "def" # true