Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
sprintf.c File Reference
#include "mruby.h"
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "mruby/hash.h"
#include "mruby/numeric.h"
#include <math.h>
#include <ctype.h>
Include dependency graph for sprintf.c:

Go to the source code of this file.

Macros

#define BIT_DIGITS(N)   (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
#define BITSPERDIG   (sizeof(mrb_int)*CHAR_BIT)
#define EXTENDSIGN(n, l)   (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))
#define FNONE   0
#define FSHARP   1
#define FMINUS   2
#define FPLUS   4
#define FZERO   8
#define FSPACE   16
#define FWIDTH   32
#define FPREC   64
#define FPREC0   128
#define CHECK(l)
#define PUSH(s, l)
#define FILL(c, l)
#define GETARG()
#define GETPOSARG(n)
#define GETNTHARG(nth)   ((nth >= argc) ? (mrb_raise(mrb, E_ARGUMENT_ERROR, "too few arguments"), mrb_undef_value()) : argv[nth])
#define GETNAMEARG(id, name, len)
#define GETNUM(n, val)
#define GETASTER(num)
#define CHECK_FOR_WIDTH(f)
#define CHECK_FOR_FLAGS(f)

Functions

mrb_value mrb_f_sprintf (mrb_state *mrb, mrb_value obj)
mrb_value mrb_str_format (mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)

Macro Definition Documentation

#define BIT_DIGITS (   N)    (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */

Definition at line 22 of file sprintf.c.

#define BITSPERDIG   (sizeof(mrb_int)*CHAR_BIT)

Definition at line 23 of file sprintf.c.

#define CHECK (   l)
Value:
do {\
/* int cr = ENC_CODERANGE(result);*/\
while (blen + (l) >= bsiz) {\
bsiz*=2;\
}\
mrb_str_resize(mrb, result, bsiz);\
/* ENC_CODERANGE_SET(result, cr);*/\
buf = RSTRING_PTR(result);\
} while (0)

Definition at line 124 of file sprintf.c.

#define CHECK_FOR_FLAGS (   f)
Value:
if ((f) & FWIDTH) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "flag after width"); \
} \
if ((f) & FPREC0) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "flag after precision"); \
}
#define CHECK_FOR_WIDTH (   f)
Value:
if ((f) & FWIDTH) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "width given twice"); \
} \
if ((f) & FPREC0) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "width after precision"); \
}
#define EXTENDSIGN (   n,
 
)    (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))

Definition at line 24 of file sprintf.c.

#define FILL (   c,
 
)
Value:
do { \
CHECK(l);\
memset(&buf[blen], c, l);\
blen += (l);\
} while (0)

Definition at line 140 of file sprintf.c.

#define FMINUS   2

Definition at line 116 of file sprintf.c.

#define FNONE   0

Definition at line 114 of file sprintf.c.

#define FPLUS   4

Definition at line 117 of file sprintf.c.

#define FPREC   64

Definition at line 121 of file sprintf.c.

#define FPREC0   128

Definition at line 122 of file sprintf.c.

#define FSHARP   1

Definition at line 115 of file sprintf.c.

#define FSPACE   16

Definition at line 119 of file sprintf.c.

#define FWIDTH   32

Definition at line 120 of file sprintf.c.

#define FZERO   8

Definition at line 118 of file sprintf.c.

#define GETARG ( )
Value:
(!mrb_undef_p(nextvalue) ? nextvalue : \
posarg == -1 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with numbered", mrb_fixnum_value(nextarg)), mrb_undef_value()) : \
posarg == -2 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with named", mrb_fixnum_value(nextarg)), mrb_undef_value()) : \
(posarg = nextarg++, GETNTHARG(posarg)))

Definition at line 146 of file sprintf.c.

#define GETASTER (   num)
Value:
do { \
t = p++; \
n = 0; \
GETNUM(n, val); \
if (*p == '$') { \
tmp = GETPOSARG(n); \
} \
else { \
tmp = GETARG(); \
p = t; \
} \
num = mrb_fixnum(tmp); \
} while (0)

Definition at line 183 of file sprintf.c.

#define GETNAMEARG (   id,
  name,
  len 
)
Value:
( \
posarg > 0 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after unnumbered(%S)", mrb_str_new(mrb, (name), (len)), mrb_fixnum_value(posarg)), mrb_undef_value()) : \
posarg == -1 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after numbered", mrb_str_new(mrb, (name), (len))), mrb_undef_value()) : \
(posarg = -2, mrb_hash_fetch(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value())))

Definition at line 164 of file sprintf.c.

#define GETNTHARG (   nth)    ((nth >= argc) ? (mrb_raise(mrb, E_ARGUMENT_ERROR, "too few arguments"), mrb_undef_value()) : argv[nth])

Definition at line 161 of file sprintf.c.

#define GETNUM (   n,
  val 
)
Value:
for (; p < end && ISDIGIT(*p); p++) {\
int next_n = 10 * n + (*p - '0'); \
if (next_n / 10 != n) {\
mrb_raise(mrb, E_ARGUMENT_ERROR, #val " too big"); \
} \
n = next_n; \
} \
if (p >= end) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "malformed format string - %*[0-9]"); \
}

Definition at line 171 of file sprintf.c.

#define GETPOSARG (   n)
Value:
(posarg > 0 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after unnumbered(%S)", mrb_fixnum_value(n), mrb_fixnum_value(posarg)), mrb_undef_value()) : \
posarg == -2 ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after named", mrb_fixnum_value(n)), mrb_undef_value()) : \
((n < 1) ? \
(mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid index - %S$", mrb_fixnum_value(n)), mrb_undef_value()) : \
(posarg = -1, GETNTHARG(n))))

Definition at line 153 of file sprintf.c.

#define PUSH (   s,
 
)
Value:
do { \
CHECK(l);\
memcpy(&buf[blen], s, l);\
blen += (l);\
} while (0)

Definition at line 134 of file sprintf.c.

Function Documentation

mrb_value mrb_f_sprintf ( mrb_state mrb,
mrb_value  obj 
)

Definition at line 475 of file sprintf.c.

Here is the call graph for this function:

Here is the caller graph for this function:

mrb_value mrb_str_format ( mrb_state mrb,
int  argc,
const mrb_value argv,
mrb_value  fmt 
)

Definition at line 492 of file sprintf.c.

Here is the call graph for this function:

Here is the caller graph for this function: