summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext
AgeCommit message (Collapse)Author
2021-12-16string-ext.c: fix memory leak in `tr_parse_pattern`.Yukihiro "Matz" Matsumoto
2021-12-13string-ext/string.c: fixed memory leak from `tr` on exception.Yukihiro "Matz" Matsumoto
With some refactoring. * `ret` argument is always non-nil, so no check needed. * move allocation check right after malloc(). * simplify conditions.
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-11-15string-ext/string.c: fixed a memory leak.Yukihiro "Matz" Matsumoto
2021-09-07string.h: rename `mrb_str_to_inum` to `mrb_str_to_integer`.Yukihiro "Matz" Matsumoto
Consistent naming: `integer` to represent integer packed in `mrb_value` instead of `inum`.
2021-09-01string-ext/string.c: implement `casecmp` in C.Yukihiro "Matz" Matsumoto
* should not raise error for non-string arguments * avoid allocating case converted string internally
2021-09-01Do no use return values from `mrb_ensure_` functions.Yukihiro "Matz" Matsumoto
They return the checking argument without modification, so the values are already there. Maybe we should change the return type to `void` but keep them unchanged for compatibility.
2021-07-10Update internal methods not to be listed in backtraces.Yukihiro "Matz" Matsumoto
- String#__lines - Array#__ary_eq - Array#__ary_cmp - Hash#__delete - Kernel#__case_eqq - Integer#__coerce_step_counter
2021-06-29string.rb: `upto` to break when the string length is longer than `end`.Yukihiro "Matz" Matsumoto
2021-06-28Avoid warnings with `ruby -cw`dearblue
```console % for rb in `git ls-files '*/mrblib/*.rb' 'mrblib'`; do ruby30 -cw $rb > /dev/null; done mrbgems/mruby-array-ext/mrblib/array.rb:389: warning: assigned but unused variable - ary mrbgems/mruby-array-ext/mrblib/array.rb:663: warning: assigned but unused variable - len mrbgems/mruby-hash-ext/mrblib/hash.rb:119: warning: possibly useless use of a variable in void context mrbgems/mruby-hash-ext/mrblib/hash.rb:259: warning: assigned but unused variable - keys mrbgems/mruby-io/mrblib/io.rb:229: warning: literal in condition mrbgems/mruby-io/mrblib/io.rb:280: warning: literal in condition mrbgems/mruby-string-ext/mrblib/string.rb:347: warning: assigned but unused variable - len mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb:2: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument ```
2021-05-17Global renaming regarding `integer` and `float`.Yukihiro "Matz" Matsumoto
Consistent number conversion function names: * `mrb_value` to immediate (C) value * `mrb_int()` -> `mrb_as_int()` * `mrb_to_flo()` -> `mrb_as_float()` * `mrb_value` to `mrb_value` (converted) * `mrb_to_int()' * `mrb_Integer()` - removed * `mrb_Float()` -> `mrb_to_float` Consistent function name (avoid `_flo` suffix): * `mrb_div_flo()` -> `mrb_div_float`
2021-05-13string.c: remove unnecessary branch in the internal method.Yukihiro "Matz" Matsumoto
2021-05-05Extend the tab with 8 whitespacedearblue
This work was done as follows: - check: `git grep $'\011' -- :^oss-fuzz` - convert: `ruby -pi -e 'nil while $_.sub!(/^(.*?)\t/) { $1 + " " * (8 - $1.size % 8) }'` The `doc/guide/{compile,mrbgems}.md` file adds and removes whitespace to make the directory tree look the same. In `mrbgems/mruby-socket/src/socket.c`, there is a part where the indent is changed from 4 to 2 at the same time as the tab is changed.
2021-04-28string.c: add a new method `String#center`.Yukihiro "Matz" Matsumoto
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`
2020-10-22Prohibit array changes by "a"/"*" specifier of `mrb_get_args()`dearblue
The "a"/"*" specifier of the `mrb_get_args()` function will now return `const mrb_value *`. This is because it is difficult for the caller to check if it is an array object and write-barrier if necessary. And it requires calling `mrb_ary_modify()` on the unmodified array object, which is also difficult (this is similar to #5087).
2020-10-15Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into ↵Yukihiro "Matz" Matsumoto
zubycz-work_for_merge
2020-10-15Merge pull request #5084 from mruby/mruby3Yukihiro "Matz" Matsumoto
Mruby3
2020-10-13Introduce endless range (a part of #5085)taiyoslime
Co-Authored-By: n4o847 <[email protected]> Co-Authored-By: smallkirby <[email protected]>
2020-10-12Reorganize `Integer` system.Yukihiro "Matz" Matsumoto
- Integrate `Fixnum` and `Integer` - Remove `Integral` - `int / int -> int` - Replace `mrb_fixnum()` to `mrb_int()` - Replace `mrb_fixnum_value()` to `mrb_int_value()`. - Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12Remove unnecessary assignment in String#upton4o847
Co-authored-by: taiyoslime <[email protected]> Co-authored-by: smallkirby <[email protected]>
2020-10-12Rename float configuration option names.Yukihiro "Matz" Matsumoto
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT` - `MRB_USE_FLOAT` => `MRB_USE_FLOAT32` The former is to use `USE_XXX` naming convention. The latter is to make sure `float` is 32bit float and not floating point number in general.
2020-09-25Prohibit string changes by "s"/"z" specifier of `mrb_get_args()`dearblue
- The `s` specifier is a string pointer obtained without performing `mrb_str_modify()`, so it cannot be changed. - The `z` specifier cannot be changed because it is a string pointer obtained by `RSTRING_CSTR()` which returns `const char *`.
2020-06-20Add `mrb_get_arg1()` that retrieves single (and only) argument.Yukihiro "Matz" Matsumoto
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one argument. And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-06-05Add proper casts to silence VC warnings.Yukihiro "Matz" Matsumoto
2019-10-20Use `mrb_str_cat_str` instead of `mrb_str_concat` if possibleKOBAYASHI Shuji
2019-10-10Integrate `mrb_str_inspect` and `mrb_str_dump`KOBAYASHI Shuji
2019-09-21Use `mrb_define_method` instead of `mrb_define_alias`KOBAYASHI Shuji
2019-09-18Remove `mrb_get_args(mrb, "")`; ref 30f37872KOBAYASHI Shuji
2019-09-14Add a macro `mrb_frozen_p` that points to `MRB_FROZEN_P`.Yukihiro "Matz" Matsumoto
2019-09-11Move tests related to `getbyte`, `setbyte`, byteslice` to core.Yukihiro "Matz" Matsumoto
2019-09-11Move `String#{getbyte,setbyte,byteslice}` to the core; #4696Yukihiro "Matz" Matsumoto
Unlike CRuby, there's no way to process strings byte-wise by core methods because there's no per string encoding in mruby, so that we moved 3 byte-wise operation methods from `mruby-string-ext` gem.
2019-09-11Drop test dependency from `mruby-string-ext` to `mruby-enumerator`KOBAYASHI Shuji
2019-08-18Simplify get argumentsdearblue
- `mrb_str_index_m()` and `mrb_str_rindex()` Make `mrb_get_args()` called only once from called twice. - `mrb_str_byteslice()` Replace `goto` with `if ~ else`.
2019-08-05Use new specifiers/modifiers of `mrb_vfromat()`KOBAYASHI Shuji
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in my environment than before the introduction of new specifiers/modifiers (5116789a) with this change. ------------+-------------------+-------------------+-------- BINARY | BEFORE (5116789a) | AFTER (This PR) | RATIO ------------+-------------------+-------------------+-------- mruby | 593416 bytes | 593208 bytes | -0.04% libmruby.a | 769048 bytes | 767264 bytes | -0.23% ------------+-------------------+-------------------+-------- BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613, so I put it back.
2019-07-24Add `return` to silence a warning; ref #4593Yukihiro "Matz" Matsumoto
2019-07-23Add encoding argument to `Integral#chr`KOBAYASHI Shuji
Currently, `Integral#chr` in mruby changes behavior by `MRB_UTF8_STRING` setting. before this patch: $ bin/mruby -e 'p 171.chr' #=> "\xab" (`MRB_UTF8_STRING` is disabled) $ bin/mruby -e 'p 171.chr' #=> "«" (`MRB_UTF8_STRING` is enabled) This behavior is incompatible with Ruby, and a little inconvenient because it can't be interpreted as ASCII-8BIT with `MRB_UTF8_STRING`, I think. So add encoding argument according to Ruby. after this patch: $ bin/mruby -e 'p 171.chr' #=> "\xab" $ bin/mruby -e 'p 171.chr("ASCII-8BIT")' #=> "\xab" $ bin/mruby -e 'p 171.chr("UTF-8")' #=> "«" Allow only `String` for encoding because mruby doesn't have `Encoding` class, and `"ASCII-8BIT"` (`"BINARY"`) and `"UTF-8"` (only with `MRB_UTF8_STRING`) are valid value (default is `"ASCII-8BIT"`).
2019-07-21Integrate `Integral#chr` (`Fixnum#chr`) to `mruby-string-ext`KOBAYASHI Shuji
Because they're defined in both `mruby-string-ext` and `mruby-numeric-ext` (they seem more natural to define in N, but `mruby-string-ext` depends on `Integral#chr`).
2019-07-19Refine `String#chr` test and separate `Fixnum#chr` testKOBAYASHI Shuji
2019-07-09Add Range#max and Range#min tests from Ruby SpecRyan Lopopolo
2019-07-08Add tests for String RangesRyan Lopopolo
Range#each depends on String#upto which is implemented in mruby-string-ext which is why these tests live there.
2019-06-28Use `__ENCODING__` in testsKOBAYASHI Shuji
It cannot be used for `String#size` test if judging whether or not `MRB_UTF8_STRING` is defined by result of `String#size`.
2019-06-25Fix `String#byteslice` with `MRB_UTF8_STRING` and some edge casesKOBAYASHI Shuji
Example: $ bin/mruby -e ' p "あa".byteslice(1) p "bar".byteslice(3) p "bar".byteslice(4..0) ' Before this patch: "a" "" RangeError (4..0 out of range) After this patch (same as Ruby): "\x81" nil nil
2019-06-12Fix typo in `String#setbyte` error messageKOBAYASHI Shuji
2019-05-25Name the return value of `mrb_range_beg_len()`dearblue
2019-04-27Remove duplicated `String#each_char`KOBAYASHI Shuji
2019-03-15Use `FrozenError` instead of `RuntimeError` in `String#rstrip!`KOBAYASHI Shuji
2019-03-12Fix missing assertions in `mruby-string-ext` testKOBAYASHI Shuji
2018-11-19Removed `String#try_convert` method from `mruby-string-ext` gem.Yukihiro "Matz" Matsumoto
Because `try_convert` method rarely used in production. For mruby users, we have `__to_str` utility method to check string type.
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.