diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-01-23 14:35:26 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-01-23 14:35:26 +0900 |
| commit | 5e1d923381072ebcbe002d70bc198a6e95c31f50 (patch) | |
| tree | a34b1dd90e3931d91d4cc11666187907f10de877 /src/string.c | |
| parent | 708088c5fafd469d04a1b428fc49b8b7c27607d2 (diff) | |
| download | mruby-5e1d923381072ebcbe002d70bc198a6e95c31f50.tar.gz mruby-5e1d923381072ebcbe002d70bc198a6e95c31f50.zip | |
Changed the behavior of mrb_range_beg_len(); close #3411
The new API is:
int mrb_range_beg_len(mrb, range, &beg, &len, len, trunc)
The new argument `trunc` is a boolean value that specifies
whether the function truncates the range. The new return value
is an integer instead of a boolean, that is:
0: not a range
1: range with proper edges
2: out of range
To get the old behavior, you have to rewrite:
mrb_range_beg_len(mrb, range, &beg, &len, len)
to:
mrn_range_beg_len(mrb, range, &beg, &len, len, TRUE) == 1
[Breaking Change]
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/string.c b/src/string.c index 02c7ce426..7a75bb63e 100644 --- a/src/string.c +++ b/src/string.c @@ -1091,22 +1091,25 @@ num_index: return mrb_nil_value(); case MRB_TT_RANGE: - /* check if indx is Range */ - { - mrb_int beg, len; + goto range_arg; - len = RSTRING_CHAR_LEN(str); - if (mrb_range_beg_len(mrb, indx, &beg, &len, len)) { - return str_subseq(mrb, str, beg, len); - } - else { - return mrb_nil_value(); - } - } - case MRB_TT_FLOAT: default: indx = mrb_Integer(mrb, indx); if (mrb_nil_p(indx)) { + range_arg: + { + mrb_int beg, len; + + len = RSTRING_CHAR_LEN(str); + switch (mrb_range_beg_len(mrb, indx, &beg, &len, len, TRUE)) { + case 1: + return str_subseq(mrb, str, beg, len); + case 2: + return mrb_nil_value(); + default: + break; + } + } mrb_raise(mrb, E_TYPE_ERROR, "can't convert to Fixnum"); } idx = mrb_fixnum(indx); |
