diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-27 13:33:14 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-27 13:33:14 +0900 |
| commit | 70718d5935ed0ae96ac3c782330e1195114b6463 (patch) | |
| tree | 922d89240befe8eed3844b8628fea827cc04fef6 /src/string.c | |
| parent | 9434506035c3fc01de55ac0bc8b75497f8b5df5f (diff) | |
| download | mruby-70718d5935ed0ae96ac3c782330e1195114b6463.tar.gz mruby-70718d5935ed0ae96ac3c782330e1195114b6463.zip | |
an int literal may have multiple underscores inside
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/string.c b/src/string.c index 0bee35d0e..439cb5409 100644 --- a/src/string.c +++ b/src/string.c @@ -1954,7 +1954,7 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) { const char *p; char sign = 1; - int c, us; + int c, uscore; unsigned long n = 0; mrb_int val; @@ -2042,14 +2042,14 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) break; } /* end of switch (base) { */ if (*str == '0') { /* squeeze preceeding 0s */ - us = 0; + uscore = 0; while ((c = *++str) == '0' || c == '_') { if (c == '_') { - if (++us >= 2) + if (++uscore >= 2) break; } else - us = 0; + uscore = 0; } if (!(c = *str) || ISSPACE(c)) --str; } @@ -2060,16 +2060,17 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) return mrb_fixnum_value(0); } - us = 0; + uscore = 0; for (p=str;*p;p++) { if (*p == '_') { - if (us == 0) { - us++; + if (uscore == 0) { + uscore++; continue; } if (badcheck) goto bad; break; } + uscore = 0; c = conv_digit(*p); if (c < 0 || c >= base) { if (badcheck) goto bad; |
