Commit Graph

203 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto e0194bba67 mruby-string-ext/string.c: remove mrb_ prefix from static functions 2023-04-25 14:25:15 +09:00
Yukihiro "Matz" Matsumoto a21edf75ad Use mrb_get_arg1() instead of mrb_get_args() for single argument 2023-02-21 16:33:15 +09:00
Yukihiro "Matz" Matsumoto a2e2e83012 string.c: move String#bytesplice to the core 2023-01-28 16:43:40 +09:00
Yukihiro "Matz" Matsumoto 12e232c006 mruby-string-ext/string.rb: add test for String#bytesplice 2023-01-28 16:41:40 +09:00
Yukihiro "Matz" Matsumoto 52746479a3 mruby-string-ext/string.c: new method String#byteslice 2023-01-27 23:22:02 +09:00
John Bampton efd0e52cfd Remove # coding: utf-8 from Ruby file
The default script encoding is Encoding::UTF-8 after v2.0.

https://ruby-doc.org/core-2.1.2/Encoding.html#class-Encoding-label-Script+encoding
2022-12-29 10:15:48 +10:00
Yukihiro "Matz" Matsumoto 48e5ca4802 include/value.h (mrb_float_p): define always
even when `MRB_NO_FLOAT` is set. In that case, it is FALSE always.
2022-12-24 19:05:41 +09:00
Yukihiro "Matz" Matsumoto 14f8cf040e mruby-string-ext: add unary +/- for strings to freeze/unfreeze 2022-12-24 10:42:28 +09:00
Yukihiro "Matz" Matsumoto 9c5dc42e59 small cosmetic changes.
I prefer `i++` style unless absolutely necessary.
This commit is an addition to 41e4148.
2022-11-19 17:11:56 +09:00
John Bampton ea8964ef35 ruby: standardize whitespace 2022-10-31 16:25:56 +10:00
John Bampton 44db4f18d3 Remove # coding: utf-8 from Ruby files
The default script encoding is Encoding::UTF-8 after v2.0.

https://ruby-doc.org/core-2.1.2/Encoding.html#class-Encoding-label-Script+encoding
2022-10-27 04:43:13 +10:00
Yukihiro "Matz" Matsumoto 11504318b8 string-ext/string.rb: String#prepend to take multiple arguments. 2022-09-20 18:31:04 +09:00
Yukihiro "Matz" Matsumoto 4cba1b49c0 string-ext/string.c: String#concat to take multiple arguments. 2022-09-20 18:26:23 +09:00
John Bampton 2990aaa343 pre-commit autoupdate, fix spelling, update codespell.txt
https://pre-commit.com/#pre-commit-autoupdate
2022-09-18 00:22:55 +10:00
Yukihiro "Matz" Matsumoto d72d26afcb mruby-string-ext/string.c: use the reference from mrb structure. 2022-09-12 10:27:31 +09:00
Yukihiro "Matz" Matsumoto d55a152b3d mruby-string-ext/string.c (utf8code): max length of UTF-8 is 4 bytes.
It used to be 6 bytes in RFC2279 but overridden by new RFC3629.
2022-05-29 22:19:00 +09:00
Yukihiro "Matz" Matsumoto 82b87be4df string.c (mrb_utf8len): retry 7cdef2b0.
C++ requires `extern` declaration before variable definition.
2022-05-29 22:18:59 +09:00
Yukihiro "Matz" Matsumoto 82f0ba14a9 Revert "string.c: share UTF-8 length table with mruby-string-ext."
This reverts commit 7cdef2b03e.
This sharing does not with C++ compilers.
2022-05-25 16:07:52 +09:00
Yukihiro "Matz" Matsumoto 7cdef2b03e string.c: share UTF-8 length table with mruby-string-ext. 2022-05-25 11:25:43 +09:00
Yukihiro "Matz" Matsumoto be0b5f8cee mruby-string-ext/string.c: reduce UTF-8 table size. 2022-05-25 11:22:28 +09:00
Yukihiro "Matz" Matsumoto 2f4695b759 mruby-string-ext/string.c: check sequence length before decoding. 2022-05-25 11:20:29 +09:00
Yukihiro "Matz" Matsumoto f08e66e53e mruby-string-ext/string.c (mrb_str_ord): fail with invalid UTF-8. 2022-05-25 11:17:49 +09:00
Yukihiro "Matz" Matsumoto b99c389ec3 internal.h: aggregate internal functions.
Internal functions can only be called from within the library.
Functions listed in `mruby/internal.h` can be called from:

* core (src/*.c)
* gems (mrbgems/**/*.c)

But not from the application linked with `libmruby`.
2022-04-02 18:25:13 +09:00
Yukihiro "Matz" Matsumoto 57d93c4d76 string-ext.c: fix memory leak in tr_parse_pattern. 2021-12-16 11:39:35 +09:00
Yukihiro "Matz" Matsumoto 8a74b2a25d string-ext/string.c: fixed memory leak from tr on exception.
With some refactoring.

* `ret` argument is always non-nil, so no check needed.
* move allocation check right after malloc().
* simplify conditions.
2021-12-13 10:29:16 +09:00
dearblue c4bca7cbb3 Align "wrong number of arguments" messages
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-28 18:21:29 +09:00
Yukihiro "Matz" Matsumoto e0a3800e5d string-ext/string.c: fixed a memory leak. 2021-11-15 09:49:05 +09:00
Yukihiro "Matz" Matsumoto 79bc8e2539 string.h: rename mrb_str_to_inum to mrb_str_to_integer.
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `inum`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto 37a7ff228b string-ext/string.c: implement casecmp in C.
* should not raise error for non-string arguments
* avoid allocating case converted string internally
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto e86c9cb57c Do no use return values from mrb_ensure_ functions.
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-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto be6d559853 Update internal methods not to be listed in backtraces.
- String#__lines
- Array#__ary_eq
- Array#__ary_cmp
- Hash#__delete
- Kernel#__case_eqq
- Integer#__coerce_step_counter
2021-07-10 14:15:43 +09:00
Yukihiro "Matz" Matsumoto b2b0329d29 string.rb: upto to break when the string length is longer than end. 2021-06-29 16:49:16 +09:00
dearblue 2d0b50f6f3 Avoid warnings with ruby -cw
```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-06-28 23:21:47 +09:00
Yukihiro "Matz" Matsumoto 5eebbd7df2 Global renaming regarding integer and float.
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-17 15:07:05 +09:00
Yukihiro "Matz" Matsumoto 3a3761ec69 string.c: remove unnecessary branch in the internal method. 2021-05-13 16:08:25 +09:00
dearblue 6fc5dc986a Extend the tab with 8 whitespace
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-05-05 22:16:03 +09:00
Yukihiro "Matz" Matsumoto 2ad5d4f53d string.c: add a new method String#center. 2021-04-28 21:44:19 +09:00
Yukihiro "Matz" Matsumoto e5e5acefaf string.{c,rb}: fix type of return values from some methods as Ruby3.0
When the receiver is the instance of subclass of `String`.

- `String#each_char`
- `String#each_line`
- `String#partition`
2021-04-28 21:41:01 +09:00
dearblue f0a64329b1 Prohibit array changes by "a"/"*" specifier of mrb_get_args()
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-22 22:55:35 +09:00
Yukihiro "Matz" Matsumoto 6b457d2c00 Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into zubycz-work_for_merge 2020-10-15 18:35:13 +09:00
Yukihiro "Matz" Matsumoto 9cebddf9fe Merge pull request #5084 from mruby/mruby3
Mruby3
2020-10-15 18:31:06 +09:00
taiyoslime bec4d05340 Introduce endless range (a part of #5085)
Co-Authored-By: n4o847 <22975590+n4o847@users.noreply.github.com>
Co-Authored-By: smallkirby <ssmallkirby@gmail.com>
2020-10-13 14:09:36 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- 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-12 18:19:54 +09:00
n4o847 59af217779 Remove unnecessary assignment in String#upto
Co-authored-by: taiyoslime <t@iyosli.me>
Co-authored-by: smallkirby <ssmallkirby@gmail.com>
2020-10-12 16:50:22 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `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-10-12 16:21:40 +09:00
dearblue 57611240a9 Prohibit string changes by "s"/"z" specifier of mrb_get_args()
- 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-09-25 21:02:58 +09:00
Yukihiro "Matz" Matsumoto 49ae2a69f2 Add mrb_get_arg1() that retrieves single (and only) argument.
`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-20 12:49:46 +09:00
Yukihiro "Matz" Matsumoto 106f4c4e9d Add proper casts to silence VC warnings. 2020-06-05 16:04:30 +09:00
KOBAYASHI Shuji 7047c52d7b Use mrb_str_cat_str instead of mrb_str_concat if possible 2019-10-20 16:26:10 +09:00
KOBAYASHI Shuji 7ce5d33947 Integrate mrb_str_inspect and mrb_str_dump 2019-10-10 19:50:48 +09:00