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:
parent
f5219fee63
commit
b4974e71dc
5 changed files with 17 additions and 7 deletions
|
@ -1157,6 +1157,7 @@ VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb
|
|||
|
||||
/* util.c (export) */
|
||||
extern const signed char ruby_digit36_to_number_table[];
|
||||
extern const char ruby_hexdigits[];
|
||||
|
||||
/* variable.c (export) */
|
||||
void rb_gc_mark_global_tbl(void);
|
||||
|
|
2
pack.c
2
pack.c
|
@ -1204,7 +1204,7 @@ infected_str_new(const char *ptr, long len, VALUE str)
|
|||
static VALUE
|
||||
pack_unpack(VALUE str, VALUE fmt)
|
||||
{
|
||||
static const char hexdigits[] = "0123456789abcdef";
|
||||
#define hexdigits ruby_hexdigits
|
||||
char *s, *send;
|
||||
char *p, *pend;
|
||||
VALUE ary;
|
||||
|
|
|
@ -1252,6 +1252,8 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
|
|||
#ifdef RUBY_PRI_VALUE_MARK
|
||||
# define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK
|
||||
#endif
|
||||
#define lower_hexdigits (ruby_hexdigits+0)
|
||||
#define upper_hexdigits (ruby_hexdigits+16)
|
||||
#include "vsnprintf.c"
|
||||
|
||||
typedef struct {
|
||||
|
|
5
util.c
5
util.c
|
@ -23,6 +23,9 @@
|
|||
|
||||
#include "ruby/util.h"
|
||||
|
||||
const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF";
|
||||
#define hexdigit ruby_hexdigits
|
||||
|
||||
unsigned long
|
||||
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
|
||||
ruby_scan_hex(const char *start, size_t len, size_t *retlen)
|
||||
{
|
||||
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
|
||||
register const char *s = start;
|
||||
register unsigned long retval = 0;
|
||||
const char *tmp;
|
||||
|
@ -1993,7 +1995,6 @@ ruby_strtod(const char *s00, char **se)
|
|||
break2:
|
||||
if (*s == '0') {
|
||||
if (s[1] == 'x' || s[1] == 'X') {
|
||||
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
|
||||
s0 = ++s;
|
||||
adj = 0;
|
||||
aadj = 1.0;
|
||||
|
|
14
vsnprintf.c
14
vsnprintf.c
|
@ -510,6 +510,12 @@ static int exponent(char *, int, int);
|
|||
|
||||
#endif /* FLOATING_POINT */
|
||||
|
||||
#ifndef lower_hexdigits
|
||||
# define lower_hexdigits "0123456789abcdef"
|
||||
#endif
|
||||
#ifndef upper_hexdigits
|
||||
# define upper_hexdigits "0123456789ABCDEF"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Flags used during conversion.
|
||||
|
@ -993,7 +999,7 @@ fp_begin: _double = va_arg(ap, double);
|
|||
#endif /* _HAVE_SANE_QUAD_ */
|
||||
#endif
|
||||
base = 16;
|
||||
xdigs = "0123456789abcdef";
|
||||
xdigs = lower_hexdigits;
|
||||
ch = 'x';
|
||||
goto nosign;
|
||||
case 's':
|
||||
|
@ -1031,10 +1037,10 @@ fp_begin: _double = va_arg(ap, double);
|
|||
base = 10;
|
||||
goto nosign;
|
||||
case 'X':
|
||||
xdigs = "0123456789ABCDEF";
|
||||
xdigs = upper_hexdigits;
|
||||
goto hex;
|
||||
case 'x':
|
||||
xdigs = "0123456789abcdef";
|
||||
xdigs = lower_hexdigits;
|
||||
hex:
|
||||
#ifdef _HAVE_SANE_QUAD_
|
||||
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') {
|
||||
digits = BSD__hdtoa(value,
|
||||
ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF",
|
||||
ch == 'a' ? lower_hexdigits : upper_hexdigits,
|
||||
ndigits, decpt, &dsgn, &rve);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Reference in a new issue