summaryrefslogtreecommitdiff
path: root/string.c
AgeCommit message (Collapse)Author
2020-11-20Remove obsoleted str_new_emptyTakashi Kokubun
since 58325daae3beefda13ed100782cd19a89cc68771. ../string.c:1339:1: warning: ‘str_new_empty’ defined but not used [-Wunused-function] 1339 | str_new_empty(VALUE str) | ^~~~~~~~~~~~~
2020-11-20Make String methods return String instances when called on a subclass instanceJeremy Evans
This modifies the following String methods to return String instances instead of subclass instances: * String#* * String#capitalize * String#center * String#chomp * String#chop * String#delete * String#delete_prefix * String#delete_suffix * String#downcase * String#dump * String#each/#each_line * String#gsub * String#ljust * String#lstrip * String#partition * String#reverse * String#rjust * String#rpartition * String#rstrip * String#scrub * String#slice! * String#slice/#[] * String#split * String#squeeze * String#strip * String#sub * String#succ/#next * String#swapcase * String#tr * String#tr_s * String#upcase This also fixes a bug in String#swapcase where it would return the receiver instead of a copy of the receiver if the receiver was the empty string. Some string methods were left to return subclass instances: * String#+@ * String#-@ Both of these methods will return the receiver (subclass instance) in some cases, so it is best to keep the returned class consistent. Fixes [#10845] Notes: Merged: https://github.com/ruby/ruby/pull/3701
2020-11-17Expose the rb_interned_str_* family of functionsJean Boussier
Fixes [Feature #13381] Notes: Merged: https://github.com/ruby/ruby/pull/3586
2020-10-30Move variable closer to usageAlan Wu
2020-10-21Don't redefine #rb_intern over and over againStefan Stüben
Notes: Merged: https://github.com/ruby/ruby/pull/3589
2020-10-08Enhanced RDoc for String#insert (#3643)Burdette Lamar
* Enhanced RDoc for String#insert Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-30Enhanced RDoc for String#[] (#3607)Burdette Lamar
* Enhanced RDoc for String#[] Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-29Enhanced RDoc for String#upto (#3603)Burdette Lamar
* Enhanced RDoc for String#upto Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-28Enhanced RDoc for String#succ! (#3596)Burdette Lamar
* Enhanced RDoc for String#succ! Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-25Enhanced RDoc for String#succ (#3590)Burdette Lamar
* Enhanced RDoc for String#succ Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-24Enhanced RDoc for String#match? (#3576)Burdette Lamar
* Enhanced RDoc for String#match? Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-24Enhanced RDoc for String (#3574)Burdette Lamar
Methods: =~ match Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-24Enhanced RDoc for String (#3569)Burdette Lamar
Makes some methods doc compliant with https://github.com/ruby/ruby/blob/master/doc/method_documentation.rdoc. Also, other minor revisions to make more consistent. Methods: == === eql? <=> casecmp casecmp? index rindex Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-23Fix call-seq [ci skip]Kazuhiro NISHIYAMA
`encoding` can be not only an encoding name, but also an Encoding object. ``` s = String.new('foo', encoding: Encoding::US_ASCII) s.encoding # => #<Encoding:US-ASCII> ```
2020-09-22Enhanced RDoc for String (#3565)Burdette Lamar
Makes some methods doc compliant with https://github.com/ruby/ruby/blob/master/doc/method_documentation.rdoc. Also, other minor revisions to make more consistent. Methods: try_convert +string -string concat << prepend hash Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-21Comply with guide for method doc: string.c (#3528)Burdette Lamar
Methods: ::new #length #bytesize #empty? #+ #* #% Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-09-18sync fstring_table for deletionKoichi Sasada
Ractors can access this table simultaneously so we need to sync accesses. Notes: Merged: https://github.com/ruby/ruby/pull/3548
2020-09-15sync fstring poolKoichi Sasada
fstring pool should be sync with other Ractors. Notes: Merged: https://github.com/ruby/ruby/pull/3534
2020-09-11Let String#slice! return nil (#3533)Soutaro Matsumoto
Returns `nil` instead of an empty string when non-integer number is given (to make it 2.7 compatible). Notes: Merged-By: soutaro <matsumoto@soutaro.com>
2020-09-04Added Symbol#nameNobuyoshi Nakada
https://bugs.ruby-lang.org/issues/16150#change-87446 Notes: Merged: https://github.com/ruby/ruby/pull/3514 Merged-By: nobu <nobu@ruby-lang.org>
2020-08-20Partial compliance with doc/method_documentation.rdoc in string.c (#3436)Burdette Lamar
Removes references to *-convertible thingies. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-08-19register_fstring: avoid duping the passed string when possibleJean Boussier
If the passed string is frozen, bare and not shared, then there is no need to duplicate it. Ref: 4ab69ebbd7cef8539f687e1f948845d076461dc6 Ref: https://bugs.ruby-lang.org/issues/11386 Notes: Merged: https://github.com/ruby/ruby/pull/3430
2020-08-15[DOC] fixed a missing markupNobuyoshi Nakada
2020-08-13rb_str_{index,rindex}_m: Handle /\K/ in patternKasumi Hanazuki
When the pattern Regexp given to String#index and String#rindex contain a /\K/ (lookbehind) operator, these methods return the position where the beginning of the lookbehind pattern matches, while they are expected to return the position where the \K matches. ``` # without patch "abcdbce".index(/b\Kc/) # => 1 "abcdbce".rindex(/b\Kc/) # => 4 ``` This patch fixes this problem by using BEG(0) instead of the return value of rb_reg_search. ``` # with patch "abcdbce".index(/b\Kc/) # => 2 "abcdbce".rindex(/b\Kc/) # => 5 ``` Fixes [Bug #17118] Notes: Merged: https://github.com/ruby/ruby/pull/3414
2020-08-13rb_str_{partition,rpartition}_m: Handle /\K/ in patternKasumi Hanazuki
When the pattern given to String#partition and String#rpartition contain a /\K/ (lookbehind) operator, the methods return strings sliced at incorrect positions. ``` # without patch "abcdbce".partition(/b\Kc/) # => ["a", "c", "cdbce"] "abcdbce".rpartition(/b\Kc/) # => ["abcd", "c", "ce"] ``` This patch fixes the problem by using BEG(0) instead of the return value of rb_reg_search. ``` # with patch "abcdbce".partition(/b\Kc/) # => ["ab", "c", "dbce"] "abcdbce".rpartition(/b\Kc/) # => ["abcdb", "c", "e"] ``` As a side-effect this patch makes String#partition 2x faster when the pattern is a costly Regexp by performing Regexp search only once, which was unexpectedly done twice in the original implementation. Fixes [Bug #17119] Notes: Merged: https://github.com/ruby/ruby/pull/3413
2020-08-12string.c(rb_str_split_m): Handle /\K/ correctlyKasumi Hanazuki
Use BEG(0) instead of the result of rb_reg_search to handle the cases when the separator Regexp contains /\K/ (lookbehind) operator. Fixes [Bug #17113] Notes: Merged: https://github.com/ruby/ruby/pull/3407
2020-08-10Removed non-ASCII code to suppress warnings by localized compilersNobuyoshi Nakada
2020-08-10Adjust indentNobuyoshi Nakada
2020-07-28Use https instead of httpKazuhiro NISHIYAMA
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_partition: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_crypt: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29trnext: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29chompped_length: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29get_pat_quoted: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29get_pat: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_slice_bang: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_aset: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_subpat_set: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_update: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_match: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_rindex_m: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_str_index_m: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_enc_cr_str_buf_cat: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-05-27add static modifier for rb_str_ord funcS-H-GAMELINKS
2020-05-17Fix typos [ci skip]Kazuhiro NISHIYAMA
2020-05-15[ci skip] Enhanced rdoc for String.new (#3067)Burdette Lamar
* Per @nobu review * Enhanced rdoc for String.new * Respond to review Notes: Merged-By: drbrain <drbrain@segment7.net>
2020-05-12Optimize String#splitNobuyoshi Nakada
Optimized `String#split` with `/ /` (single space regexp) as simple string splitting. [ruby-core:98272] | |compare-ruby|built-ruby| |:--------------|-----------:|---------:| |re_space-1 | 432.786k| 1.539M| | | -| 3.56x| |re_space-10 | 76.231k| 191.547k| | | -| 2.51x| |re_space-100 | 8.152k| 19.557k| | | -| 2.40x| |re_space-1000 | 837.405| 2.022k| | | -| 2.41x| ruby-core:98272: https://bugs.ruby-lang.org/issues/15771#change-85511 Notes: Merged: https://github.com/ruby/ruby/pull/3103
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079