Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
coderange.h
Go to the documentation of this file.
1 #ifndef RUBY_INTERNAL_ENCODING_CODERANGE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RUBY_INTERNAL_ENCODING_CODERANGE_H
27 #include "ruby/internal/fl_type.h"
28 #include "ruby/internal/value.h"
29 
31 
32 
34 
37 
40 
43 
46 
51 };
52 
64 static inline int
65 rb_enc_coderange_clean_p(int cr)
66 {
67  return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
68 }
69 
79 static inline bool
81 {
82  return rb_enc_coderange_clean_p(cr);
83 }
84 
94 static inline enum ruby_coderange_type
96 {
98 
99  return RBIMPL_CAST((enum ruby_coderange_type)ret);
100 }
101 
113 static inline bool
115 {
117 }
118 
128 static inline void
130 {
132  RB_FL_SET_RAW(obj, cr);
133 }
134 
143 static inline void
145 {
147 }
148 
150 /* assumed ASCII compatibility */
161 static inline enum ruby_coderange_type
163 {
164  if (a == RUBY_ENC_CODERANGE_7BIT) {
165  return b;
166  }
167  else if (a != RUBY_ENC_CODERANGE_VALID) {
169  }
170  else if (b == RUBY_ENC_CODERANGE_7BIT) {
172  }
173  else {
174  return b;
175  }
176 }
177 
178 #define ENC_CODERANGE_MASK RUBY_ENC_CODERANGE_MASK
179 #define ENC_CODERANGE_UNKNOWN RUBY_ENC_CODERANGE_UNKNOWN
180 #define ENC_CODERANGE_7BIT RUBY_ENC_CODERANGE_7BIT
181 #define ENC_CODERANGE_VALID RUBY_ENC_CODERANGE_VALID
182 #define ENC_CODERANGE_BROKEN RUBY_ENC_CODERANGE_BROKEN
183 #define ENC_CODERANGE_CLEAN_P(cr) RB_ENC_CODERANGE_CLEAN_P(cr)
184 #define ENC_CODERANGE(obj) RB_ENC_CODERANGE(obj)
185 #define ENC_CODERANGE_ASCIIONLY(obj) RB_ENC_CODERANGE_ASCIIONLY(obj)
186 #define ENC_CODERANGE_SET(obj,cr) RB_ENC_CODERANGE_SET(obj,cr)
187 #define ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_CLEAR(obj)
188 #define ENC_CODERANGE_AND(a, b) RB_ENC_CODERANGE_AND(a, b)
189 #define ENCODING_CODERANGE_SET(obj, encindex, cr) RB_ENCODING_CODERANGE_SET(obj, encindex, cr)
192 #define RB_ENC_CODERANGE RB_ENC_CODERANGE
193 #define RB_ENC_CODERANGE_AND RB_ENC_CODERANGE_AND
194 #define RB_ENC_CODERANGE_ASCIIONLY RB_ENC_CODERANGE_ASCIIONLY
195 #define RB_ENC_CODERANGE_CLEAN_P RB_ENC_CODERANGE_CLEAN_P
196 #define RB_ENC_CODERANGE_CLEAR RB_ENC_CODERANGE_CLEAR
197 #define RB_ENC_CODERANGE_SET RB_ENC_CODERANGE_SET
201 
202 #endif /* RUBY_INTERNAL_ENCODING_CODERANGE_H */
static void RB_ENC_CODERANGE_CLEAR(VALUE obj)
Destructively clears the passed object's (inline) code range.
Definition: coderange.h:144
ruby_coderange_type
What rb_enc_str_coderange() returns.
Definition: coderange.h:33
@ RUBY_ENC_CODERANGE_MASK
Where the coderange resides.
Definition: coderange.h:48
@ RUBY_ENC_CODERANGE_VALID
The object's encoding and contents are consistent each other.
Definition: coderange.h:42
@ RUBY_ENC_CODERANGE_7BIT
The object holds 0 to 127 inclusive and nothing else.
Definition: coderange.h:39
@ RUBY_ENC_CODERANGE_UNKNOWN
The object's coderange is unclear yet.
Definition: coderange.h:36
@ RUBY_ENC_CODERANGE_BROKEN
The object holds invalid/malformed/broken character(s).
Definition: coderange.h:45
static void RB_ENC_CODERANGE_SET(VALUE obj, enum ruby_coderange_type cr)
Destructively modifies the passed object so that its (inline) code range is the passed one.
Definition: coderange.h:129
static enum ruby_coderange_type RB_ENC_CODERANGE(VALUE obj)
Queries the (inline) code range of the passed object.
Definition: coderange.h:95
static enum ruby_coderange_type RB_ENC_CODERANGE_AND(enum ruby_coderange_type a, enum ruby_coderange_type b)
"Mix" two code ranges into one.
Definition: coderange.h:162
static bool RB_ENC_CODERANGE_CLEAN_P(enum ruby_coderange_type cr)
Queries if a code range is "clean".
Definition: coderange.h:80
static bool RB_ENC_CODERANGE_ASCIIONLY(VALUE obj)
Queries the (inline) code range of the passed object is RUBY_ENC_CODERANGE_7BIT.
Definition: coderange.h:114
Defines RBIMPL_ATTR_CONST.
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
Defines enum ruby_fl_type.
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_TEST().
Definition: fl_type.h:469
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_SET().
Definition: fl_type.h:606
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_UNSET().
Definition: fl_type.h:666
@ RUBY_FL_USER9
User-defined flag.
Definition: fl_type.h:337
@ RUBY_FL_USER8
User-defined flag.
Definition: fl_type.h:336
RBIMPL_ATTR_CONST() int rb_io_oflags_fmode(int oflags)
Converts an oflags (that rb_io_modestr_oflags() returns) to a fmode (that rb_io_mode_flags() returns)...
#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 RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition: pure.h:38
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40