Ruby: include/ruby/internal/arithmetic/char.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

char.h
Go to the documentation of this file.
1#ifndef RBIMPL_ARITHMETIC_CHAR_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_ARITHMETIC_CHAR_H
23#include "ruby/internal/arithmetic/int.h" /* NUM2INT is here, but */
24#include "ruby/internal/arithmetic/long.h" /* INT2FIX is here.*/
25#include "ruby/internal/attr/artificial.h"
26#include "ruby/internal/attr/const.h"
27#include "ruby/internal/attr/constexpr.h"
28#include "ruby/internal/cast.h"
29#include "ruby/internal/core/rstring.h"
30#include "ruby/internal/value_type.h"
31
32#define RB_NUM2CHR rb_num2char_inline
33#define NUM2CHR RB_NUM2CHR
34#define CHR2FIX RB_CHR2FIX
37#define RB_CHR2FIX RB_CHR2FIX
40 RBIMPL_ATTR_CONST_UNLESS_DEBUG()
41 RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
42 RBIMPL_ATTR_ARTIFICIAL()
55static inline VALUE
56RB_CHR2FIX(unsigned char c)
57{
58 return RB_INT2FIX(c);
59}
60
72static inline char
73rb_num2char_inline(VALUE x)
74{
75 if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1))
76 return RSTRING_PTR(x)[0];
77 else
78 return RBIMPL_CAST((char)RB_NUM2INT(x));
79}
80
81#endif /* RBIMPL_ARITHMETIC_CHAR_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
RB_CHR2FIX
static VALUE RB_CHR2FIX(unsigned char c)
Converts a C's unsigned char into an instance of rb_cInteger.
Definition char.h:56
rb_num2char_inline
static char rb_num2char_inline(VALUE x)
Converts an instance of rb_cNumeric into C's char.
Definition char.h:73
const.h
Defines RBIMPL_ATTR_CONST.
RBIMPL_ATTR_CONST_UNLESS_DEBUG
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST if and only if.
Definition const.h:41
constexpr.h
RBIMPL_ATTR_CONSTEXPR.
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR if and only if.
Definition constexpr.h:79
int.h
Arithmetic conversion between C's int and Ruby's.
RB_NUM2INT
#define RB_NUM2INT
Just another name of rb_num2int_inline.
Definition int.h:38
long.h
Arithmetic conversion between C's long and Ruby's.
RB_INT2FIX
static VALUE RB_INT2FIX(long i)
Converts a C's long into an instance of rb_cInteger.
Definition long.h:111
rstring.h
Defines struct RString.
RSTRING_LEN
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
Definition rstring.h:484
RSTRING_PTR
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
Definition rstring.h:498
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
value_type.h
Defines enum ruby_value_type.
RB_TYPE_P
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
Definition value_type.h:375
RUBY_T_STRING
@ RUBY_T_STRING
Definition value_type.h:119