summaryrefslogtreecommitdiffhomepage
path: root/mrblib/string.rb
AgeCommit message (Collapse)Author
2021-11-28Align "wrong number of arguments" messagesdearblue
Make "N for M" into the form "given N, expected M". As I worked, I noticed that the `argnum_error()` function had a part to include the method name in the message. I think this part is no longer needed by https://github.com/mruby/mruby/pull/5394. - Before this patch ```console % bin/mruby -e '[1, 2, 3].each 0' trace (most recent call last): [1] -e:1 -e:1:in each: 'each': wrong number of arguments (1 for 0) (ArgumentError) ``` - After this patch ```console % bin/mruby -e '[1, 2, 3].each 0' trace (most recent call last): [1] -e:1 -e:1:in each: wrong number of arguments (given 1, expected 0) (ArgumentError) ```
2021-09-01string.c: implement `__sub_replace()` in C.Yukihiro "Matz" Matsumoto
To reduce number of string allocation.
2021-09-01string.rb: avoid internal `__to_str` calls.Yukihiro "Matz" Matsumoto
`__to_str` was a mere type check method despite its name.
2021-04-28string.{c,rb}: fix type of return values from some methods as Ruby3.0Yukihiro "Matz" Matsumoto
When the receiver is the instance of subclass of `String`. - `String#each_char` - `String#each_line` - `String#partition`
2019-09-12Merge pull request #4527 from lopopolo/string-each-line-paragraph-modeYukihiro "Matz" Matsumoto
Add paragraph mode to String#each_line in mrblib
2019-06-29Replace `String#[]=` method by C implementsdearblue
The purpose is to eliminate string objects that are temporarily created during processing.
2019-06-25Unify loops to minimize bytecode sizeRyan Lopopolo
2019-06-23Use explicit block parameterRyan Lopopolo
2019-06-23Optimize String#each_lineRyan Lopopolo
2019-06-22Speed up base case by 2xRyan Lopopolo
Make non-paragraph mode twice as fast. Performance is within a factor of 2 of the original implementation.
2019-06-22Add paragraph mode to String#each_line in mrblibRyan Lopopolo
mruby/mruby#4511 demonstrated an infinite loop in `String#each_line` when given an empty string separator. In MRI, an empty separator places String#each_line in paragraph mode, where the String is separated on successive runs of newlines. In paragraph mode, the String `"abc\n\n\ndef\nxyz"` is split into `["abc\n\n\n", "def\nxyz"]`. This commit makes the String#each_line implementation as close to ruby/spec compliant as possible given the limitations of mruby core. With this patch, the following specs fail for `String#each_line`: - uses `$/` as the separator when none is given (can be fixed by aliasing and redefining the method to use $/ as the default value of separator in mruby-io) - when no block is given returned Enumerator size should return nil (`Enumerator#size` is not supported on mruby) - tries to convert the separator to a string using to_str (`String#to_str` is not implemented on mruby) This patch has similar memory consumption compared to the prior implementation and is takes 4x the time the prior implementation takes to execute: ```console /usr/bin/time -l ./bin/mruby -e '("aaa\n\nbbbbb\n\n\n\n\ncccc" * 100000).each_line("\n") { }'; ```
2019-05-15Add Enumerator support to `String#each_byte`.Yukihiro "Matz" Matsumoto
`String#each_byte` is not defined in ISO Ruby but it is implemented in the core mruby because it's useful.
2019-05-15Remove `String#=~` and `String#match` that requires `Regexp`.Yukihiro "Matz" Matsumoto
2019-04-27Remove duplicated `String#each_char`KOBAYASHI Shuji
2019-04-21Commented out `String#scan` because it is not implemented yetKOBAYASHI Shuji
2019-04-19Add type check (conversion) in `String#[]=`KOBAYASHI Shuji
Before this patch: 'a'[0] = 1 #=> 1 'a'[:a] = '1' #=> ArgumentError 'a'[:a, 0] = '1' #=> ArgumentError 'a'[0, :a] = '1' #=> ArgumentError 'a'[0, 1] = 1 #=> 1 After this patch / Ruby: 'a'[0] = 1 #=> TypeError 'a'[:a] = '1' #=> TypeError 'a'[:a, 0] = '1' #=> TypeError 'a'[0, :a] = '1' #=> TypeError 'a'[0, 1] = 1 #=> TypeError
2019-04-18Remove duplicated `include Comparable` in `mrblib/string.rb`KOBAYASHI Shuji
2019-04-08Avoid infinite loop when no `Regexp` class is available; fix #4363Yukihiro "Matz" Matsumoto
2018-11-19Avoid assignments from type checking `String#__to_str`.Yukihiro "Matz" Matsumoto
2018-11-19Remove implicit conversion using `to_str` method; fix #3854Yukihiro "Matz" Matsumoto
We have added internal convenience method `__to_str` which does string type check. The issue #3854 was fixed but fundamental flaw of lack of stack depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA` for workaround.
2018-08-07Fixed the corner case bug in `String#{gsub!,sub!}`.Yukihiro "Matz" Matsumoto
`"a".sub!("a", "a")` should not return `nil`.
2017-12-12Modifying frozen objects will raise `FrozenError`.Yukihiro "Matz" Matsumoto
`FrozenError` is a subclass of `RuntimeError` which used to be raised. [Ruby2.5]
2017-06-21use `unless` instead of `if not`.Yukihiro "Matz" Matsumoto
2017-03-22Fix result if pattern is emptyksss
2017-03-19Callback should yield with pattern every timeksss
2017-03-19Support to return Enumerator for String#gsub,gsub!ksss
2017-03-15Support to return enumerator when no block givenksss
2017-03-15Suuport custom separatorksss
2017-03-15Use duplicated object for block argsksss
2017-03-11Merge branch 'master' into string-gsubYukihiro "Matz" Matsumoto
2017-03-10\1 sequences as empty stringsksss
2017-03-10Avoid infinity loop when empty string patternksss
2017-03-05Check modifiable for String `bang' methodsksss
2016-11-16Fixed off-by-one error in String#[]= with RangesYukihiro "Matz" Matsumoto
2016-11-16make String#[]= to take Ranges as position argumentYukihiro "Matz" Matsumoto
2015-09-23remove a comment that no longer be true; 2cb6c27Yukihiro "Matz" Matsumoto
2015-09-22String#index should no longer take integer argumentYukihiro "Matz" Matsumoto
2015-09-16support String#[]= with 3 argstakahashim
2015-08-21string.rb: refactor code (remove redundant code)go.kikuta
2015-07-16Don't crash if pattern not found for subJared Breeden
2015-06-08gsub/sub supports back references in substitutes. fixes #2816.Tomoyuki Sahara
This implementation is compatible with CRuby's String#gsub/sub except \1 ... \9 and \+. They are useless without Regexp library.
2015-05-29update mrblib/*.rb files to conform (some of) Rubocop checksYukihiro "Matz" Matsumoto
2015-01-19String#[]= should support negative position; close #2707Yukihiro "Matz" Matsumoto
2015-01-14fix infinite loop in String#match(arg) when arg is Stringtakahashim
2014-02-08made mrb_define_class to return existing class, with heavy refactoringYukihiro "Matz" Matsumoto
2014-01-10fix ISO reference number of String#=~.Tomoyuki Sahara
2013-12-24string type check based on #to_str to encourage duck typing; #1616Yukihiro "Matz" Matsumoto
2013-12-24verify the argument of String#=~h2so5
2013-07-23String `=~` and `match` to work with pluggable Regexp; close #1398Yukihiro "Matz" Matsumoto
2013-02-18adopt String#gsub to fixed split behaviorYukihiro Matz Matsumoto