Ruby: include/ruby/internal/encoding/coderange.h Source File

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

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
24#include "ruby/internal/attr/const.h"
25#include "ruby/internal/attr/pure.h"
26#include "ruby/internal/dllexport.h"
27#include "ruby/internal/fl_type.h"
28#include "ruby/internal/value.h"
29
30 RBIMPL_SYMBOL_EXPORT_BEGIN()
31
32
33enum ruby_coderange_type {
34
36 RUBY_ENC_CODERANGE_UNKNOWN = 0,
37
39 RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8),
40
42 RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9),
43
45 RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)),
46
48 RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT|
49 RUBY_ENC_CODERANGE_VALID|
50 RUBY_ENC_CODERANGE_BROKEN)
51};
52
53 RBIMPL_ATTR_CONST()
64static inline int
65rb_enc_coderange_clean_p(int cr)
66{
67 return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
68}
69
70 RBIMPL_ATTR_CONST()
79static inline bool
80RB_ENC_CODERANGE_CLEAN_P(enum ruby_coderange_type cr)
81{
82 return rb_enc_coderange_clean_p(cr);
83}
84
85 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
94static inline enum ruby_coderange_type
95RB_ENC_CODERANGE(VALUE obj)
96{
97 VALUE ret = RB_FL_TEST_RAW(obj, RUBY_ENC_CODERANGE_MASK);
98
99 return RBIMPL_CAST((enum ruby_coderange_type)ret);
100}
101
102 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
113static inline bool
114RB_ENC_CODERANGE_ASCIIONLY(VALUE obj)
115{
116 return RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT;
117}
118
128static inline void
129RB_ENC_CODERANGE_SET(VALUE obj, enum ruby_coderange_type cr)
130{
131 RB_FL_UNSET_RAW(obj, RUBY_ENC_CODERANGE_MASK);
132 RB_FL_SET_RAW(obj, cr);
133}
134
143static inline void
144RB_ENC_CODERANGE_CLEAR(VALUE obj)
145{
146 RB_FL_UNSET_RAW(obj, RUBY_ENC_CODERANGE_MASK);
147}
148
149 RBIMPL_ATTR_CONST()
150/* assumed ASCII compatibility */
161static inline enum ruby_coderange_type
162RB_ENC_CODERANGE_AND(enum ruby_coderange_type a, enum ruby_coderange_type b)
163{
164 if (a == RUBY_ENC_CODERANGE_7BIT) {
165 return b;
166 }
167 else if (a != RUBY_ENC_CODERANGE_VALID) {
168 return RUBY_ENC_CODERANGE_UNKNOWN;
169 }
170 else if (b == RUBY_ENC_CODERANGE_7BIT) {
171 return RUBY_ENC_CODERANGE_VALID;
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
200 RBIMPL_SYMBOL_EXPORT_END()
201
202#endif /* RUBY_INTERNAL_ENCODING_CODERANGE_H */
RB_ENC_CODERANGE_CLEAR
static void RB_ENC_CODERANGE_CLEAR(VALUE obj)
Destructively clears the passed object's (inline) code range.
Definition coderange.h:144
ruby_coderange_type
ruby_coderange_type
What rb_enc_str_coderange() returns.
Definition coderange.h:33
RUBY_ENC_CODERANGE_MASK
@ RUBY_ENC_CODERANGE_MASK
Where the coderange resides.
Definition coderange.h:48
RUBY_ENC_CODERANGE_VALID
@ RUBY_ENC_CODERANGE_VALID
The object's encoding and contents are consistent each other.
Definition coderange.h:42
RUBY_ENC_CODERANGE_7BIT
@ RUBY_ENC_CODERANGE_7BIT
The object holds 0 to 127 inclusive and nothing else.
Definition coderange.h:39
RUBY_ENC_CODERANGE_UNKNOWN
@ RUBY_ENC_CODERANGE_UNKNOWN
The object's coderange is unclear yet.
Definition coderange.h:36
RUBY_ENC_CODERANGE_BROKEN
@ RUBY_ENC_CODERANGE_BROKEN
The object holds invalid/malformed/broken character(s).
Definition coderange.h:45
RB_ENC_CODERANGE_SET
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
RB_ENC_CODERANGE
static enum ruby_coderange_type RB_ENC_CODERANGE(VALUE obj)
Queries the (inline) code range of the passed object.
Definition coderange.h:95
RB_ENC_CODERANGE_AND
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
RB_ENC_CODERANGE_CLEAN_P
static bool RB_ENC_CODERANGE_CLEAN_P(enum ruby_coderange_type cr)
Queries if a code range is "clean".
Definition coderange.h:80
RB_ENC_CODERANGE_ASCIIONLY
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
const.h
Defines RBIMPL_ATTR_CONST.
RBIMPL_ATTR_CONST
#define RBIMPL_ATTR_CONST()
Wraps (or simulates) __attribute__((const))
Definition const.h:36
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
fl_type.h
Defines enum ruby_fl_type.
RB_FL_TEST_RAW
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_TEST().
Definition fl_type.h:501
RB_FL_SET_RAW
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_SET().
Definition fl_type.h:638
RB_FL_UNSET_RAW
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_UNSET().
Definition fl_type.h:698
RUBY_FL_USER9
@ RUBY_FL_USER9
User-defined flag.
Definition fl_type.h:369
RUBY_FL_USER8
@ RUBY_FL_USER8
User-defined flag.
Definition fl_type.h:368
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE_UNLESS_DEBUG
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition pure.h:38
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40