mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
sprintf.c: check_pos_arg
* sprintf.c (check_pos_arg): utility function for GETPOSARG(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
420523389e
commit
3f48c1fdf7
1 changed files with 17 additions and 6 deletions
23
sprintf.c
23
sprintf.c
|
@ -85,12 +85,9 @@ sign_bits(int base, const char *p)
|
|||
check_next_arg(posarg, nextarg), \
|
||||
(posarg = nextarg++, GETNTHARG(posarg)))
|
||||
|
||||
#define GETPOSARG(n) (posarg > 0 ? \
|
||||
(rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", (n), posarg), 0) : \
|
||||
posarg == -2 ? \
|
||||
(rb_raise(rb_eArgError, "numbered(%d) after named", (n)), 0) : \
|
||||
(((n) < 1) ? (rb_raise(rb_eArgError, "invalid index - %d$", (n)), 0) : \
|
||||
(posarg = -1, GETNTHARG(n))))
|
||||
#define GETPOSARG(n) ( \
|
||||
check_pos_arg(posarg, (n)), \
|
||||
(posarg = -1, GETNTHARG(n)))
|
||||
|
||||
#define GETNTHARG(nth) \
|
||||
(((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
|
||||
|
@ -150,6 +147,20 @@ check_next_arg(int posarg, int nextarg)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_pos_arg(int posarg, int n)
|
||||
{
|
||||
if (posarg > 0) {
|
||||
rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", n, posarg);
|
||||
}
|
||||
if (posarg == -2) {
|
||||
rb_raise(rb_eArgError, "numbered(%d) after named", n);
|
||||
}
|
||||
if (n < 1) {
|
||||
rb_raise(rb_eArgError, "invalid index - %d$", n);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
get_hash(volatile VALUE *hash, int argc, const VALUE *argv)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue