Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
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.*/
28 #include "ruby/internal/cast.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
55 static inline VALUE
56 RB_CHR2FIX(unsigned char c)
57 {
58  return RB_INT2FIX(c);
59 }
60 
72 static inline char
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 */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
static VALUE RB_CHR2FIX(unsigned char c)
Converts a C's unsigned char into an instance of rb_cInteger.
Definition: char.h:56
static char rb_num2char_inline(VALUE x)
Converts an instance of rb_cNumeric into C's char.
Definition: char.h:73
Defines RBIMPL_ATTR_CONST.
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST if and only if.
Definition: const.h:41
RBIMPL_ATTR_CONSTEXPR.
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR if and only if.
Definition: constexpr.h:79
Arithmetic conversion between C's int and Ruby's.
#define RB_NUM2INT
Just another name of rb_num2int_inline.
Definition: int.h:38
Arithmetic conversion between C's long and Ruby's.
static VALUE RB_INT2FIX(long i)
Converts a C's long into an instance of rb_cInteger.
Definition: long.h:111
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88
Defines struct RString.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
Definition: rstring.h:416
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
Definition: rstring.h:367
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40
Defines enum ruby_value_type.
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:376
@ RUBY_T_STRING
Definition: value_type.h:120