* sprintf.c (check_name_arg): utility function for GETNAMEARG().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-07-02 08:03:57 +00:00
Родитель 3f48c1fdf7
Коммит 18a9926ad9
1 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -93,10 +93,7 @@ sign_bits(int base, const char *p)
(((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
#define GETNAMEARG(id, name, len, enc) ( \
posarg > 0 ? \
(rb_enc_raise((enc), rb_eArgError, "named%.*s after unnumbered(%d)", (len), (name), posarg), 0) : \
posarg == -1 ? \
(rb_enc_raise((enc), rb_eArgError, "named%.*s after numbered", (len), (name)), 0) : \
check_name_arg(posarg, name, len, enc), \
(posarg = -2, rb_hash_lookup2(get_hash(&hash, argc, argv), (id), Qundef)))
#define GETNUM(n, val) \
@ -161,6 +158,17 @@ check_pos_arg(int posarg, int n)
}
}
static void
check_name_arg(int posarg, const char *name, int len, rb_encoding *enc)
{
if (posarg > 0) {
rb_enc_raise(enc, rb_eArgError, "named%.*s after unnumbered(%d)", len, name, posarg);
}
if (posarg == -1) {
rb_enc_raise(enc, rb_eArgError, "named%.*s after numbered", len, name);
}
}
static VALUE
get_hash(volatile VALUE *hash, int argc, const VALUE *argv)
{