Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Macros | Enumerations | Functions
strftime.c File Reference
`#include "ruby/ruby.h"`
`#include "ruby/encoding.h"`
`#include "timev.h"`
`#include "internal.h"`
`#include <stdio.h>`
`#include <ctype.h>`
`#include <string.h>`
`#include <time.h>`
`#include <sys/types.h>`
`#include <errno.h>`
`#include <math.h>`

Go to the source code of this file.

## Macros
#define | SYSV_EXT 1 /* stuff in System V ascftime routine */
#define | SUNOS_EXT 1 /* stuff in SunOS strftime routine */
#define | POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */
#define | VMS_EXT 1 /* include %v for VMS date format */
#define | MAILHEADER_EXT 1 /* add %z for HHMM format */
#define | ISO_DATE_EXT 1 /* %G and %g for year of ISO week */
#define | adddecl(stuff) stuff
#define | const
#define | range(low, item, hi) max((low), min((item), (hi)))
#define | add(x, y) (rb_funcall((x), '+', 1, (y)))
#define | sub(x, y) (rb_funcall((x), '-', 1, (y)))
#define | mul(x, y) (rb_funcall((x), '*', 1, (y)))
#define | quo(x, y) (rb_funcall((x), rb_intern("quo"), 1, (y)))
#define | div(x, y) (rb_funcall((x), rb_intern("div"), 1, (y)))
#define | mod(x, y) (rb_funcall((x), '%', 1, (y)))
#define | BIT_OF(n) (1U<<(n))
#define | TBUFSIZE 100
#define | FLAG_FOUND()
#define | NEEDS(n)
#define | FILL_PADDING(i)
#define | FMT_PADDING(fmt, def_pad)
#define | FMT_PRECISION(def_prec)
#define | FMT(def_pad, def_prec, fmt, val)
#define | STRFTIME(fmt)
#define | FMTV(def_pad, def_prec, fmt, val)

## Enumerations
enum | { LEFT, CHCASE, LOWER, UPPER }

## Functions
| adddecl (static int iso8601wknum();)
VALUE | rb_strftime (const char *format, size_t format_len, rb_encoding *enc, VALUE time, const struct vtm *vtm, VALUE timev, int gmt)
VALUE | rb_strftime_timespec (const char *format, size_t format_len, rb_encoding *enc, VALUE time, const struct vtm *vtm, struct timespec *ts, int gmt)

## Macro Definition Documentation

## ◆ add

#define add | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '+', 1, (y)))

Definition at line 151 of file strftime.c.

## ◆ adddecl

#define adddecl | ( |  | stuff | ) | stuff

Definition at line 95 of file strftime.c.

## ◆ BIT_OF

#define BIT_OF | ( |  | n | ) | (1U<<(n))

Definition at line 161 of file strftime.c.

## ◆ const

#define const

Definition at line 103 of file strftime.c.

## ◆ div

#define div | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), rb_intern("div"), 1, (y)))

Definition at line 155 of file strftime.c.

## ◆ FILL_PADDING

#define FILL_PADDING | ( |  | i | ) |

Value:
do { \
if (!(flags & BIT_OF(LEFT)) && precision > (i)) { \
NEEDS(precision); \
memset(s, padding ? padding : ' ', precision - (i)); \
s += precision - (i); \
} \
else { \
NEEDS(i); \
} \
} while (0);

## ◆ FLAG_FOUND

#define FLAG_FOUND | ( |  | ) |

Value:
do { \
if (precision > 0) \
goto unknown; \
} while (0)

## ◆ FMT

#define FMT | ( |  | def_pad,
|  |  | def_prec,
|  |  | fmt,
|  |  | val
| ) |  |

Value:
do { \
precision = FMT_PRECISION(def_prec); \
len = s - start; \
NEEDS(precision); \
rb_str_set_len(ftime, len); \
rb_str_catf(ftime, FMT_PADDING(fmt, def_pad), \
precision, (val)); \
RSTRING_GETMEM(ftime, s, len); \
endp = (start = s) + rb_str_capacity(ftime); \
s += len; \
} while (0)

## ◆ FMT_PADDING

#define FMT_PADDING | ( |  | fmt,
|  |  | def_pad
| ) |  |

Value:
(&"%*"fmt"\0""%0*"fmt[\
(padding == '0' || (!padding && (def_pad) == '0')) ? \
rb_strlen_lit("%*"fmt)+1 : 0])

## ◆ FMT_PRECISION

#define FMT_PRECISION | ( |  | def_prec | ) |

Value:
((flags & BIT_OF(LEFT)) ? (1) : \
(precision <= 0) ? (def_prec) : (precision))

## ◆ FMTV

#define FMTV | ( |  | def_pad,
|  |  | def_prec,
|  |  | fmt,
|  |  | val
| ) |  |

Value:
do { \
VALUE tmp = (val); \
if (FIXNUM_P(tmp)) { \
FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \
} \
else { \
const int base = ((fmt[0] == 'x') ? 16 : \
(fmt[0] == 'o') ? 8 : \
10); \
precision = FMT_PRECISION(def_prec); \
if (!padding) padding = (def_pad); \
tmp = format_value(tmp, base); \
i = RSTRING_LEN(tmp); \
FILL_PADDING(i); \
rb_str_set_len(ftime, s-start); \
rb_str_append(ftime, tmp); \
RSTRING_GETMEM(ftime, s, len); \
endp = (start = s) + rb_str_capacity(ftime); \
s += len; \
} \
} while (0)

## ◆ ISO_DATE_EXT

#define ISO_DATE_EXT 1 /* %G and %g for year of ISO week */

Definition at line 77 of file strftime.c.

## ◆ MAILHEADER_EXT

#define MAILHEADER_EXT 1 /* add %z for HHMM format */

Definition at line 76 of file strftime.c.

## ◆ mod

#define mod | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '%', 1, (y)))

Definition at line 156 of file strftime.c.

## ◆ mul

#define mul | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '*', 1, (y)))

Definition at line 153 of file strftime.c.

## ◆ NEEDS

#define NEEDS | ( |  | n | ) |

Value:
do { \
if (s >= endp || (n) >= endp - s - 1) { \
s = resize_buffer(ftime, s, &start, &endp, (n), maxsize); \
buffer_size_check(s, format_end, format_len, enc); \
} \
} while (0)

## ◆ POSIX2_DATE

#define POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */

Definition at line 74 of file strftime.c.

## ◆ quo

#define quo | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), rb_intern("quo"), 1, (y)))

Definition at line 154 of file strftime.c.

## ◆ range

#define range | ( |  | low,
|  |  | item,
|  |  | hi
| ) |  | max((low), min((item), (hi)))

## ◆ STRFTIME

#define STRFTIME | ( |  | fmt | ) |

Value:
do { \
len = s - start; \
rb_str_set_len(ftime, len); \
if (!rb_strftime_with_timespec(ftime, (fmt), rb_strlen_lit(fmt), \
enc, time, vtm, timev, ts, gmt, maxsize)) \
return 0; \
s = RSTRING_PTR(ftime); \
i = RSTRING_LEN(ftime) - len; \
endp = (start = s) + rb_str_capacity(ftime); \
s += len; \
if (i > 0) case_conv(s, i, flags); \
if (precision > i) {\
NEEDS(precision); \
memmove(s + precision - i, s, i);\
memset(s, padding ? padding : ' ', precision - i); \
s += precision; \
} \
else s += i; \
} while (0)

## ◆ sub

#define sub | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '-', 1, (y)))

Definition at line 152 of file strftime.c.

## ◆ SUNOS_EXT

#define SUNOS_EXT 1 /* stuff in SunOS strftime routine */

Definition at line 73 of file strftime.c.

## ◆ SYSV_EXT

#define SYSV_EXT 1 /* stuff in System V ascftime routine */

Definition at line 72 of file strftime.c.

## ◆ TBUFSIZE

#define TBUFSIZE 100

## ◆ VMS_EXT

#define VMS_EXT 1 /* include %v for VMS date format */

Definition at line 75 of file strftime.c.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
LEFT |
CHCASE |
LOWER |
UPPER |

Definition at line 160 of file strftime.c.

## Function Documentation

## ◆ adddecl()

adddecl | ( | static int iso8601wknum(); |  | ) |

Definition at line 105 of file strftime.c.

## ◆ rb_strftime()

VALUE rb_strftime | ( | const char * | format,
|  | size_t | format_len,
|  | rb_encoding * | enc,
|  | VALUE | time,
|  | const struct vtm * | vtm,
|  | VALUE | timev,
|  | int | gmt
| ) |  |

Definition at line 919 of file strftime.c.

## ◆ rb_strftime_timespec()

VALUE rb_strftime_timespec | ( | const char * | format,
|  | size_t | format_len,
|  | rb_encoding * | enc,
|  | VALUE | time,
|  | const struct vtm * | vtm,
|  | struct timespec * | ts,
|  | int | gmt
| ) |  |

Definition at line 929 of file strftime.c.

BIT_OF
#define BIT_OF(n)
Definition: strftime.c:161
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:1009
time
time_t time(time_t *_timer)
FIX2LONG
#define FIX2LONG(x)
Definition: ruby.h:394
LEFT
@ LEFT
Definition: strftime.c:160
rb_str_capacity
size_t rb_str_capacity(VALUE str)
Definition: string.c:712
if
if((ID)(DISPID) nameid !=nameid)
Definition: win32ole.c:357
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:396
fmt
const VALUE int int int int int int VALUE char * fmt
Definition: rb_mjit_min_header-2.7.0.h:6462
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
FMT_PRECISION
#define FMT_PRECISION(def_prec)
len
uint8_t len
Definition: escape.c:17
rb_strlen_lit
#define rb_strlen_lit(str)
Definition: intern.h:913
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:1005
FMT_PADDING
#define FMT_PADDING(fmt, def_pad)