summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
AgeCommit message (Collapse)Author
2020-11-22Remove `mrb_str_buf_new()` and `MRB_STR_BUF_MIN_SIZE`; close #5171Yukihiro "Matz" Matsumoto
2020-11-18Use `mrb_int_value()` instead of `mrb_fixnum_value()`; fix #5142Yukihiro "Matz" Matsumoto
2020-11-17Revert half of 9fbf0ef8.Yukihiro "Matz" Matsumoto
I misunderstand the meaning of #4483. Sorry.
2020-11-17Refactoring integer ranges.Yukihiro "Matz" Matsumoto
- Remove `mrb_ssize` - Fix `MRB_FIXNUM_{MIN,MAX}` to 32 bits on `MRB_NAN_BOXING`
2020-10-12Unify `mrb_str_to_str` to `mrb_obj_as_string`.Yukihiro "Matz" Matsumoto
Redirect `mrb_str_to_str` to `mrb_obj_as_string` via C macro. Inspired by #5082
2020-10-12Restore old function names for compatibility; fix #5070Yukihiro "Matz" Matsumoto
Rename new functions: - `mrb_convert_type(mrb,val,type,tname,method)` => `mrb_type_convert(mrb,val,type,tname,method)` - `mrb_check_convert_type(mrb,val,type,tname,method)` => `mrb_type_convert_check(mrb,val,type,tname,method)` Old names are defined by macros (support `tname` drop and `char*` => `mrb_sym` conversion).
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-12Rename `MRB_TT_FIXNUM` to `MRB_TT_INTEGER`.Yukihiro "Matz" Matsumoto
We still have `#define MRB_TT_FIXNUM MRB_TT_INTEGER` for compatibility.
2020-10-12Integrate `Fixnum` class into `Integer` classdearblue
* The `Fixnum` constant is now an alias for the `Integer` class. * Remove `struct mrb_state::fixnum_class` member. If necessary, use `struct mrb_state::integer_class` instead.
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-10-12Replace entire `irep->pool`.Yukihiro "Matz" Matsumoto
Changes: - `pool format is completely replaced - supported types: `STR`, `INT32`, `INT64`, `FLOAT` - `FLOAT` may be replaced by binary representation in the future - insert `NUL` after string literals in `mrb` files - `irep->pool` no longer store values in `mrb_value` - instead it stores in `mrb_pool_value` - less allocation - `mrb_irep` can be stored in ROM
2020-10-12Change the arguments of following implicit conversion functions:Yukihiro "Matz" Matsumoto
- `mrb_convert_type` - `mrb_check_convert_type` Those function no longer take `tname` string representation of desired type, and take method symbols instead of `const char*` names. This is incompatible change. I hope no third-party gems use those functions.
2020-09-18Remove redundant type-checkWataru Ashihara
since mrb_str_to_str() also does it.
2020-08-11Fix `mrb_int` and `size_t` combination warnings.Yukihiro "Matz" Matsumoto
2020-08-08Reintroduce `mrb_static_assert`; #5051Yukihiro "Matz" Matsumoto
Note that the home brew version of `mrb_static_assert` only works within the function body. This reverts commit 8f99689.
2020-08-06Remove `mrb_static_assert` from the core; #5051Yukihiro "Matz" Matsumoto
2020-07-06Avoid infinite loop when converting objects to strings.Yukihiro "Matz" Matsumoto
2020-06-25Use `mrb_get_argc()` to improve performance.Yukihiro "Matz" Matsumoto
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-04-29Makes `mrb_any_to_s()` accept an object whose class is `NULL`dearblue
When using `mrb_any_to_s()` for debugging purposes, giving an object whose class is `NULL` no longer causes a SIGSEGV and no crash. This is achieved by making `mrb_class_name()` and `mrb_str_cat_cstr()` null safe.
2020-04-28Rename (and expose) UTF-8 related functions; ref #4712Yukihiro "Matz" Matsumoto
- mrb_utf8len() - returns the size of a UTF-8 char (in bytes) - mrb_utf8_strlen() - returns the length of a UTF-8 string (in char)
2020-04-28Fix UTF-8 boundary check; ref #4982Yukihiro "Matz" Matsumoto
2020-02-03Add explicit type cast to return value from `mrmchr`; ref #4940Yukihiro "Matz" Matsumoto
C++ is stricter in implicit type casting.
2020-02-03Use simple search for short strings in `mrb_memsearch_qs`; close #4940Yukihiro "Matz" Matsumoto
Differences from the PR #4940: * Use simple search for short strings only. * "short" means `m+n` is shorter than `MRB_QS_SHORT_STRING_LENGTH`. * The current default value for `MRB_QS_SHORT_STRING_LENGTH` is 2048.
2020-01-08Fix buffer overflow in `mrb_str_len_to_dbl`.Yukihiro "Matz" Matsumoto
Issue 19902: mruby:mruby_fuzzer: Stack-buffer-overflow in mrb_str_len_to_dbl
2020-01-07Check memory boundary in `mrb_str_len_to_dbl`.Yukihiro "Matz" Matsumoto
2020-01-06`"0x10".to_f` should be `0`, not `16.0`; fix #4924Yukihiro "Matz" Matsumoto
2020-01-06Check remaining string length before access to avoid OOB access.Yukihiro "Matz" Matsumoto
2020-01-06Need to preserve the original input string in `mrb_str_len_to_dbl`.Yukihiro "Matz" Matsumoto
2020-01-06Fix `mrb_str_len_to_dbl` to support Hexadecimal like `0x10`.Yukihiro "Matz" Matsumoto
2020-01-06Refactor `mrb_cstr_to_dbl`; ref #4920Yukihiro "Matz" Matsumoto
2020-01-06Avoid creating temporary objects in `read_irep_record_1`; close #4920Yukihiro "Matz" Matsumoto
The basic idea of this change is from @dearblue. Note: the arguments of `mrb_str_pool()` have changed, but the function is provided for internal use (No `MRB_API`). So basically you don't have to worry about the change.
2020-01-01Revert "SHARED string is not required when sharing POOL string" (75949836)KOBAYASHI Shuji
Because literal pool may be released by GC. #### Example: ```ruby s1 = eval('"abcdefghijklmnopqrstuvwxyz01"') GC.start p s1 #=> "\x00\x00\x00\x00\x00\x00\x00\x90\x00\x00\x00\x00\x00\x00\x00\x90\x03\x00stuvwxyz01" ```
2019-12-14Remove location info from `Exception#inspect`KOBAYASHI Shuji
Because location info (file name and line number) is kept in the backtrace, it should not be kept in the result of `inspect` (and the exception object itself), I think. ### Example ```ruby # example.rb begin raise "err" rescue => e p e end ``` #### Before this patch: ``` $ bin/mruby example.rb example.rb:2: err (RuntimeError) ``` #### After this patch: ``` $ bin/mruby example.rb err (RuntimeError) ```
2019-12-11Fix behavior of `Kernel#Integer` to numbers ending with `_` and spacesKOBAYASHI Shuji
#### Before this patch: ```ruby Integer("1_ ") #=> 1 ``` #### After this patch (same as Ruby): ```ruby Integer("1_ ") #=> ArgumentError ```
2019-12-10Fix behavior of `String#to_i`/`Kernel#Integer` to numbers starting with `_`KOBAYASHI Shuji
#### Before this patch: ```ruby Integer("_1") #=> 1 "_1".to_i #=> 1 ``` #### After this patch (same as Ruby): ```ruby Integer("_1") #=> ArgumentError "_1".to_i #=> 0 ```
2019-12-09Fix that `String#to_f` accepts consecutive `_` as a numeric expressionKOBAYASHI Shuji
Consecutive `_` is not allowed as a numeric expression: 1_2__3 #=> SyntaxError Float("1_2__3") #=> ArgumentError Integer("1_2__3") #=> ArgumentError "1_2__3".to_i #=> 12 But `String#to_f` accept it, so I fixed the issue. Before this patch: "1_2__3".to_f #=> 123 After this patch: "1_2__3".to_f #=> 12
2019-12-08Fix the error message of `Kernel#Float`KOBAYASHI Shuji
#### Before this patch: ``` $ bin/mruby -e 'Float("1_a")' -e:1: invalid string for float(a) (ArgumentError) ``` #### After this patch: ``` $ bin/mruby -e 'Float("1_a")' -e:1: invalid string for float("1_a") (ArgumentError) ```
2019-11-23Rename `BITSIZE` to `BIT` and `BIT` to `BIT_POS` for consistencyKOBAYASHI Shuji
The bit width terminology is unified to `BIT` according to `MRB_INT_BIT` and `CHAR_BIT`. Also the bit position terminology is unified to `BIT_POS`.
2019-11-21Introduce `mrb_ssize` type for buffer size on memory; ref #4483KOBAYASHI Shuji
Previously, `mrb_int` was used as the type that represents the buffer size on memory, but the sizes of `RString` and `RArray` exceed 6 words when `MRB_INT64` is enabled on 32-bit CPU. I don't think it is necessary to be able to represent the buffer size on memory that exceeds the virtual address space. Therefore, for this purpose, introduce `mrb_ssize` which doesn't exceed the sizes of `mrb_int` and pointer. I think all `mrb_int` used for this purpose should be changed to `mrb_ssize`, but currently only the members of the structures (`RString`, `mrb_shared_string`, `RArray` and `mrb_shared_array`) are changed.
2019-11-19Refactor `mrb_string_value_cstr`KOBAYASHI Shuji
- Keep `MRB_STR_ASCII` flag. - Avoid a string object creation.
2019-11-08Avoid unnecessary `Symbol#to_s` call; fix #4812Yukihiro "Matz" Matsumoto
2019-11-07Clear `MRB_STR_SHARED` flag in `mrb_str_modify_keep_ascii`; close #4807KOBAYASHI Shuji
2019-11-03Remove unused enum in `mrb_cstr_to_dbl`KOBAYASHI Shuji
2019-10-28Remove documents about `Regexp` argument from `String#{[],[]=}` [ci skip]KOBAYASHI Shuji
2019-10-27Refine `String#split` documentKOBAYASHI Shuji
2019-10-26Optimize `chars2bytes` with `MRB_UTF8_STRING` to ASCII only stringKOBAYASHI Shuji
### Benchmark (with `MRB_UTF8_STRING`) ``` $ mruby -e ' COUNT = 150000 SIZE = 10000 strs = Array.new(COUNT) do s = "a" * SIZE s.size # set `MRB_STR_ASCII` flag s end i = 0 t = Time.now while i < COUNT strs[i][-2..-1] = "" i += 1 end printf "%.2f sec\n", Time.now - t ' 1.10 sec # before 0.07 sec # after ```
2019-10-23Optimize `str_subseq` with `MRB_UTF8_STRING` to ASCII only stringKOBAYASHI Shuji
### Benchmark (with `MRB_UTF8_STRING`) ```ruby # benchmark.rb COUNT = 300000 SIZE = 10000 s = "a" * SIZE s.size # set `MRB_STR_ASCII` flag i = 0 while i < COUNT s[-1] i += 1 end ``` #### Before this patch: ``` $ time mruby benchmark.rb 2.06 real 2.05 user 0.00 sys ``` #### After this patch: ``` $ time mruby benchmark.rb 0.05 real 0.04 user 0.00 sys ```
2019-10-22Fix incorrect `MRB_STR_ASCII` flag update in `mrb_str_dump`KOBAYASHI Shuji
### Example (with `MRB_UTF8_STRING`) ```ruby s = "\u3042" p s.size s.dump p s.size ``` #### Before this patch: ``` 1 3 ``` #### After this patch: ``` 1 1 ```
2019-10-15Adjust `buf` size in `str_escape`KOBAYASHI Shuji