1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

util.c: hexdigit

* util.c (hexdigit): extract identical constants.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-02-13 07:07:39 +00:00
parent f5219fee63
commit b4974e71dc
5 changed files with 17 additions and 7 deletions

View file

@ -1157,6 +1157,7 @@ VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb
/* util.c (export) */ /* util.c (export) */
extern const signed char ruby_digit36_to_number_table[]; extern const signed char ruby_digit36_to_number_table[];
extern const char ruby_hexdigits[];
/* variable.c (export) */ /* variable.c (export) */
void rb_gc_mark_global_tbl(void); void rb_gc_mark_global_tbl(void);

2
pack.c
View file

@ -1204,7 +1204,7 @@ infected_str_new(const char *ptr, long len, VALUE str)
static VALUE static VALUE
pack_unpack(VALUE str, VALUE fmt) pack_unpack(VALUE str, VALUE fmt)
{ {
static const char hexdigits[] = "0123456789abcdef"; #define hexdigits ruby_hexdigits
char *s, *send; char *s, *send;
char *p, *pend; char *p, *pend;
VALUE ary; VALUE ary;

View file

@ -1252,6 +1252,8 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
#ifdef RUBY_PRI_VALUE_MARK #ifdef RUBY_PRI_VALUE_MARK
# define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK # define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK
#endif #endif
#define lower_hexdigits (ruby_hexdigits+0)
#define upper_hexdigits (ruby_hexdigits+16)
#include "vsnprintf.c" #include "vsnprintf.c"
typedef struct { typedef struct {

5
util.c
View file

@ -23,6 +23,9 @@
#include "ruby/util.h" #include "ruby/util.h"
const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF";
#define hexdigit ruby_hexdigits
unsigned long unsigned long
ruby_scan_oct(const char *start, size_t len, size_t *retlen) ruby_scan_oct(const char *start, size_t len, size_t *retlen)
{ {
@ -40,7 +43,6 @@ ruby_scan_oct(const char *start, size_t len, size_t *retlen)
unsigned long unsigned long
ruby_scan_hex(const char *start, size_t len, size_t *retlen) ruby_scan_hex(const char *start, size_t len, size_t *retlen)
{ {
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
register const char *s = start; register const char *s = start;
register unsigned long retval = 0; register unsigned long retval = 0;
const char *tmp; const char *tmp;
@ -1993,7 +1995,6 @@ ruby_strtod(const char *s00, char **se)
break2: break2:
if (*s == '0') { if (*s == '0') {
if (s[1] == 'x' || s[1] == 'X') { if (s[1] == 'x' || s[1] == 'X') {
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
s0 = ++s; s0 = ++s;
adj = 0; adj = 0;
aadj = 1.0; aadj = 1.0;

View file

@ -510,6 +510,12 @@ static int exponent(char *, int, int);
#endif /* FLOATING_POINT */ #endif /* FLOATING_POINT */
#ifndef lower_hexdigits
# define lower_hexdigits "0123456789abcdef"
#endif
#ifndef upper_hexdigits
# define upper_hexdigits "0123456789ABCDEF"
#endif
/* /*
* Flags used during conversion. * Flags used during conversion.
@ -993,7 +999,7 @@ fp_begin: _double = va_arg(ap, double);
#endif /* _HAVE_SANE_QUAD_ */ #endif /* _HAVE_SANE_QUAD_ */
#endif #endif
base = 16; base = 16;
xdigs = "0123456789abcdef"; xdigs = lower_hexdigits;
ch = 'x'; ch = 'x';
goto nosign; goto nosign;
case 's': case 's':
@ -1031,10 +1037,10 @@ fp_begin: _double = va_arg(ap, double);
base = 10; base = 10;
goto nosign; goto nosign;
case 'X': case 'X':
xdigs = "0123456789ABCDEF"; xdigs = upper_hexdigits;
goto hex; goto hex;
case 'x': case 'x':
xdigs = "0123456789abcdef"; xdigs = lower_hexdigits;
hex: hex:
#ifdef _HAVE_SANE_QUAD_ #ifdef _HAVE_SANE_QUAD_
if (flags & QUADINT) if (flags & QUADINT)
@ -1251,7 +1257,7 @@ cvt(double value, int ndigits, int flags, char *sign, int *decpt, int ch, int *l
} }
if (ch == 'a' || ch =='A') { if (ch == 'a' || ch =='A') {
digits = BSD__hdtoa(value, digits = BSD__hdtoa(value,
ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF", ch == 'a' ? lower_hexdigits : upper_hexdigits,
ndigits, decpt, &dsgn, &rve); ndigits, decpt, &dsgn, &rve);
} }
else { else {