summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-02 08:03:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-02 08:03:57 +0000
commit18a9926ad992f166cd1287ded00e9b7929c897c3 (patch)
treefe151dff8944d1c8f91ee7917634fdf79bfe557e /sprintf.c
parent3f48c1fdf785f0d5a9939fc6163d9015d40e2b79 (diff)
sprintf.c: check_name_arg
* 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
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/sprintf.c b/sprintf.c
index e7b9c1f..27c477f 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -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)
{