Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
f455cb6c
Unverified
Commit
f455cb6c
authored
May 25, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
May 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4467 from dearblue/naming-mrb_range_beg_len
Name the return value of `mrb_range_beg_len()`
parents
c6f30e8f
56e0e193
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
18 deletions
+24
-18
include/mruby/range.h
include/mruby/range.h
+7
-1
mrbgems/mruby-array-ext/src/array.c
mrbgems/mruby-array-ext/src/array.c
+1
-1
mrbgems/mruby-kernel-ext/src/kernel.c
mrbgems/mruby-kernel-ext/src/kernel.c
+1
-1
mrbgems/mruby-string-ext/src/string.c
mrbgems/mruby-string-ext/src/string.c
+3
-3
src/array.c
src/array.c
+4
-4
src/range.c
src/range.c
+6
-6
src/string.c
src/string.c
+2
-2
No files found.
include/mruby/range.h
View file @
f455cb6c
...
@@ -64,7 +64,13 @@ MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range);
...
@@ -64,7 +64,13 @@ MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range);
*/
*/
MRB_API
mrb_value
mrb_range_new
(
mrb_state
*
mrb
,
mrb_value
start
,
mrb_value
end
,
mrb_bool
exclude
);
MRB_API
mrb_value
mrb_range_new
(
mrb_state
*
mrb
,
mrb_value
start
,
mrb_value
end
,
mrb_bool
exclude
);
MRB_API
mrb_int
mrb_range_beg_len
(
mrb_state
*
mrb
,
mrb_value
range
,
mrb_int
*
begp
,
mrb_int
*
lenp
,
mrb_int
len
,
mrb_bool
trunc
);
enum
mrb_range_beg_len
{
MRB_RANGE_TYPE_MISMATCH
=
0
,
/* (failure) not range */
MRB_RANGE_OK
=
1
,
/* (success) range */
MRB_RANGE_OUT
=
2
/* (failure) out of range */
};
MRB_API
enum
mrb_range_beg_len
mrb_range_beg_len
(
mrb_state
*
mrb
,
mrb_value
range
,
mrb_int
*
begp
,
mrb_int
*
lenp
,
mrb_int
len
,
mrb_bool
trunc
);
mrb_value
mrb_get_values_at
(
mrb_state
*
mrb
,
mrb_value
obj
,
mrb_int
olen
,
mrb_int
argc
,
const
mrb_value
*
argv
,
mrb_value
(
*
func
)(
mrb_state
*
,
mrb_value
,
mrb_int
));
mrb_value
mrb_get_values_at
(
mrb_state
*
mrb
,
mrb_value
obj
,
mrb_int
olen
,
mrb_int
argc
,
const
mrb_value
*
argv
,
mrb_value
(
*
func
)(
mrb_state
*
,
mrb_value
,
mrb_int
));
void
mrb_gc_mark_range
(
mrb_state
*
mrb
,
struct
RRange
*
r
);
void
mrb_gc_mark_range
(
mrb_state
*
mrb
,
struct
RRange
*
r
);
...
...
mrbgems/mruby-array-ext/src/array.c
View file @
f455cb6c
...
@@ -145,7 +145,7 @@ mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
...
@@ -145,7 +145,7 @@ mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
mrb_get_args
(
mrb
,
"o|i"
,
&
index
,
&
len
);
mrb_get_args
(
mrb
,
"o|i"
,
&
index
,
&
len
);
switch
(
mrb_type
(
index
))
{
switch
(
mrb_type
(
index
))
{
case
MRB_TT_RANGE
:
case
MRB_TT_RANGE
:
if
(
mrb_range_beg_len
(
mrb
,
index
,
&
i
,
&
len
,
ARY_LEN
(
a
),
TRUE
)
==
1
)
{
if
(
mrb_range_beg_len
(
mrb
,
index
,
&
i
,
&
len
,
ARY_LEN
(
a
),
TRUE
)
==
MRB_RANGE_OK
)
{
goto
delete_pos_len
;
goto
delete_pos_len
;
}
}
else
{
else
{
...
...
mrbgems/mruby-kernel-ext/src/kernel.c
View file @
f455cb6c
...
@@ -22,7 +22,7 @@ mrb_f_caller(mrb_state *mrb, mrb_value self)
...
@@ -22,7 +22,7 @@ mrb_f_caller(mrb_state *mrb, mrb_value self)
case
1
:
case
1
:
if
(
mrb_type
(
v
)
==
MRB_TT_RANGE
)
{
if
(
mrb_type
(
v
)
==
MRB_TT_RANGE
)
{
mrb_int
beg
,
len
;
mrb_int
beg
,
len
;
if
(
mrb_range_beg_len
(
mrb
,
v
,
&
beg
,
&
len
,
bt_len
,
TRUE
)
==
1
)
{
if
(
mrb_range_beg_len
(
mrb
,
v
,
&
beg
,
&
len
,
bt_len
,
TRUE
)
==
MRB_RANGE_OK
)
{
lev
=
beg
;
lev
=
beg
;
n
=
len
;
n
=
len
;
}
}
...
...
mrbgems/mruby-string-ext/src/string.c
View file @
f455cb6c
...
@@ -58,11 +58,11 @@ mrb_str_byteslice(mrb_state *mrb, mrb_value str)
...
@@ -58,11 +58,11 @@ mrb_str_byteslice(mrb_state *mrb, mrb_value str)
len
=
RSTRING_LEN
(
str
);
len
=
RSTRING_LEN
(
str
);
switch
(
mrb_range_beg_len
(
mrb
,
a1
,
&
beg
,
&
len
,
len
,
TRUE
))
{
switch
(
mrb_range_beg_len
(
mrb
,
a1
,
&
beg
,
&
len
,
len
,
TRUE
))
{
case
0
:
/* not range */
case
MRB_RANGE_TYPE_MISMATCH
:
break
;
break
;
case
1
:
/* range */
case
MRB_RANGE_OK
:
return
mrb_str_substr
(
mrb
,
str
,
beg
,
len
);
return
mrb_str_substr
(
mrb
,
str
,
beg
,
len
);
case
2
:
/* out of range */
case
MRB_RANGE_OUT
:
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"%S out of range"
,
a1
);
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"%S out of range"
,
a1
);
break
;
break
;
}
}
...
...
src/array.c
View file @
f455cb6c
...
@@ -858,7 +858,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self)
...
@@ -858,7 +858,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self)
switch
(
mrb_type
(
index
))
{
switch
(
mrb_type
(
index
))
{
/* a[n..m] */
/* a[n..m] */
case
MRB_TT_RANGE
:
case
MRB_TT_RANGE
:
if
(
mrb_range_beg_len
(
mrb
,
index
,
&
i
,
&
len
,
ARY_LEN
(
a
),
TRUE
)
==
1
)
{
if
(
mrb_range_beg_len
(
mrb
,
index
,
&
i
,
&
len
,
ARY_LEN
(
a
),
TRUE
)
==
MRB_RANGE_OK
)
{
return
ary_subseq
(
mrb
,
a
,
i
,
len
);
return
ary_subseq
(
mrb
,
a
,
i
,
len
);
}
}
else
{
else
{
...
@@ -927,13 +927,13 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self)
...
@@ -927,13 +927,13 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self)
if
(
mrb_get_args
(
mrb
,
"oo|o"
,
&
v1
,
&
v2
,
&
v3
)
==
2
)
{
if
(
mrb_get_args
(
mrb
,
"oo|o"
,
&
v1
,
&
v2
,
&
v3
)
==
2
)
{
/* a[n..m] = v */
/* a[n..m] = v */
switch
(
mrb_range_beg_len
(
mrb
,
v1
,
&
i
,
&
len
,
RARRAY_LEN
(
self
),
FALSE
))
{
switch
(
mrb_range_beg_len
(
mrb
,
v1
,
&
i
,
&
len
,
RARRAY_LEN
(
self
),
FALSE
))
{
case
0
:
/* not range */
case
MRB_RANGE_TYPE_MISMATCH
:
mrb_ary_set
(
mrb
,
self
,
aget_index
(
mrb
,
v1
),
v2
);
mrb_ary_set
(
mrb
,
self
,
aget_index
(
mrb
,
v1
),
v2
);
break
;
break
;
case
1
:
/* range */
case
MRB_RANGE_OK
:
mrb_ary_splice
(
mrb
,
self
,
i
,
len
,
v2
);
mrb_ary_splice
(
mrb
,
self
,
i
,
len
,
v2
);
break
;
break
;
case
2
:
/* out of range */
case
MRB_RANGE_OUT
:
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"%S out of range"
,
v1
);
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"%S out of range"
,
v1
);
break
;
break
;
}
}
...
...
src/range.c
View file @
f455cb6c
...
@@ -352,7 +352,7 @@ mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, con
...
@@ -352,7 +352,7 @@ mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, con
if
(
mrb_fixnum_p
(
argv
[
i
]))
{
if
(
mrb_fixnum_p
(
argv
[
i
]))
{
mrb_ary_push
(
mrb
,
result
,
func
(
mrb
,
obj
,
mrb_fixnum
(
argv
[
i
])));
mrb_ary_push
(
mrb
,
result
,
func
(
mrb
,
obj
,
mrb_fixnum
(
argv
[
i
])));
}
}
else
if
(
mrb_range_beg_len
(
mrb
,
argv
[
i
],
&
beg
,
&
len
,
olen
,
FALSE
)
==
1
)
{
else
if
(
mrb_range_beg_len
(
mrb
,
argv
[
i
],
&
beg
,
&
len
,
olen
,
FALSE
)
==
MRB_RANGE_OK
)
{
mrb_int
const
end
=
olen
<
beg
+
len
?
olen
:
beg
+
len
;
mrb_int
const
end
=
olen
<
beg
+
len
?
olen
:
beg
+
len
;
for
(
j
=
beg
;
j
<
end
;
++
j
)
{
for
(
j
=
beg
;
j
<
end
;
++
j
)
{
mrb_ary_push
(
mrb
,
result
,
func
(
mrb
,
obj
,
j
));
mrb_ary_push
(
mrb
,
result
,
func
(
mrb
,
obj
,
j
));
...
@@ -398,13 +398,13 @@ mrb_range_new(mrb_state *mrb, mrb_value beg, mrb_value end, mrb_bool excl)
...
@@ -398,13 +398,13 @@ mrb_range_new(mrb_state *mrb, mrb_value beg, mrb_value end, mrb_bool excl)
return
mrb_range_value
(
r
);
return
mrb_range_value
(
r
);
}
}
MRB_API
mrb_int
MRB_API
enum
mrb_range_beg_len
mrb_range_beg_len
(
mrb_state
*
mrb
,
mrb_value
range
,
mrb_int
*
begp
,
mrb_int
*
lenp
,
mrb_int
len
,
mrb_bool
trunc
)
mrb_range_beg_len
(
mrb_state
*
mrb
,
mrb_value
range
,
mrb_int
*
begp
,
mrb_int
*
lenp
,
mrb_int
len
,
mrb_bool
trunc
)
{
{
mrb_int
beg
,
end
;
mrb_int
beg
,
end
;
struct
RRange
*
r
;
struct
RRange
*
r
;
if
(
mrb_type
(
range
)
!=
MRB_TT_RANGE
)
return
0
;
if
(
mrb_type
(
range
)
!=
MRB_TT_RANGE
)
return
MRB_RANGE_TYPE_MISMATCH
;
r
=
mrb_range_ptr
(
mrb
,
range
);
r
=
mrb_range_ptr
(
mrb
,
range
);
beg
=
mrb_int
(
mrb
,
RANGE_BEG
(
r
));
beg
=
mrb_int
(
mrb
,
RANGE_BEG
(
r
));
...
@@ -412,11 +412,11 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
...
@@ -412,11 +412,11 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
if
(
beg
<
0
)
{
if
(
beg
<
0
)
{
beg
+=
len
;
beg
+=
len
;
if
(
beg
<
0
)
return
2
;
if
(
beg
<
0
)
return
MRB_RANGE_OUT
;
}
}
if
(
trunc
)
{
if
(
trunc
)
{
if
(
beg
>
len
)
return
2
;
if
(
beg
>
len
)
return
MRB_RANGE_OUT
;
if
(
end
>
len
)
end
=
len
;
if
(
end
>
len
)
end
=
len
;
}
}
...
@@ -427,7 +427,7 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
...
@@ -427,7 +427,7 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
*
begp
=
beg
;
*
begp
=
beg
;
*
lenp
=
len
;
*
lenp
=
len
;
return
1
;
return
MRB_RANGE_OK
;
}
}
void
void
...
...
src/string.c
View file @
f455cb6c
...
@@ -1041,9 +1041,9 @@ num_index:
...
@@ -1041,9 +1041,9 @@ num_index:
len
=
RSTRING_CHAR_LEN
(
str
);
len
=
RSTRING_CHAR_LEN
(
str
);
switch
(
mrb_range_beg_len
(
mrb
,
indx
,
&
beg
,
&
len
,
len
,
TRUE
))
{
switch
(
mrb_range_beg_len
(
mrb
,
indx
,
&
beg
,
&
len
,
len
,
TRUE
))
{
case
1
:
case
MRB_RANGE_OK
:
return
str_subseq
(
mrb
,
str
,
beg
,
len
);
return
str_subseq
(
mrb
,
str
,
beg
,
len
);
case
2
:
case
MRB_RANGE_OUT
:
return
mrb_nil_value
();
return
mrb_nil_value
();
default:
default:
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment