Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
Macros | Enumerations | Functions
coderange.h File Reference

(892c46283a5ea4179500d951c9d4866c0051f27b)

Routines for code ranges. More...

#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value.h"
Include dependency graph for coderange.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ENC_CODERANGE_MASK   RUBY_ENC_CODERANGE_MASK
 Old name of RUBY_ENC_CODERANGE_MASK. More...
 
#define ENC_CODERANGE_UNKNOWN   RUBY_ENC_CODERANGE_UNKNOWN
 Old name of RUBY_ENC_CODERANGE_UNKNOWN. More...
 
#define ENC_CODERANGE_7BIT   RUBY_ENC_CODERANGE_7BIT
 Old name of RUBY_ENC_CODERANGE_7BIT. More...
 
#define ENC_CODERANGE_VALID   RUBY_ENC_CODERANGE_VALID
 Old name of RUBY_ENC_CODERANGE_VALID. More...
 
#define ENC_CODERANGE_BROKEN   RUBY_ENC_CODERANGE_BROKEN
 Old name of RUBY_ENC_CODERANGE_BROKEN. More...
 
#define ENC_CODERANGE_CLEAN_P(cr)   RB_ENC_CODERANGE_CLEAN_P(cr)
 Old name of RB_ENC_CODERANGE_CLEAN_P. More...
 
#define ENC_CODERANGE(obj)   RB_ENC_CODERANGE(obj)
 Old name of RB_ENC_CODERANGE. More...
 
#define ENC_CODERANGE_ASCIIONLY(obj)   RB_ENC_CODERANGE_ASCIIONLY(obj)
 Old name of RB_ENC_CODERANGE_ASCIIONLY. More...
 
#define ENC_CODERANGE_SET(obj, cr)   RB_ENC_CODERANGE_SET(obj,cr)
 Old name of RB_ENC_CODERANGE_SET. More...
 
#define ENC_CODERANGE_CLEAR(obj)   RB_ENC_CODERANGE_CLEAR(obj)
 Old name of RB_ENC_CODERANGE_CLEAR. More...
 
#define ENC_CODERANGE_AND(a, b)   RB_ENC_CODERANGE_AND(a, b)
 Old name of RB_ENC_CODERANGE_AND. More...
 
#define ENCODING_CODERANGE_SET(obj, encindex, cr)   RB_ENCODING_CODERANGE_SET(obj, encindex, cr)
 Old name of RB_ENCODING_CODERANGE_SET. More...
 

Enumerations

enum  ruby_coderange_type {
  RUBY_ENC_CODERANGE_UNKNOWN = 0 , RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8) , RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9) , RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)) ,
  RUBY_ENC_CODERANGE_MASK
}
 What rb_enc_str_coderange() returns. More...
 

Functions

static bool RB_ENC_CODERANGE_CLEAN_P (enum ruby_coderange_type cr)
 Queries if a code range is "clean". More...
 
static enum ruby_coderange_type RB_ENC_CODERANGE (VALUE obj)
 Queries the (inline) code range of the passed object. More...
 
static bool RB_ENC_CODERANGE_ASCIIONLY (VALUE obj)
 Queries the (inline) code range of the passed object is RUBY_ENC_CODERANGE_7BIT. More...
 
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. More...
 
static void RB_ENC_CODERANGE_CLEAR (VALUE obj)
 Destructively clears the passed object's (inline) code range. More...
 
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. More...
 

Detailed Description

Routines for code ranges.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file coderange.h.

Enumeration Type Documentation

◆ ruby_coderange_type

What rb_enc_str_coderange() returns.

Enumerator
RUBY_ENC_CODERANGE_UNKNOWN 

The object's coderange is unclear yet.

RUBY_ENC_CODERANGE_7BIT 

The object holds 0 to 127 inclusive and nothing else.

RUBY_ENC_CODERANGE_VALID 

The object's encoding and contents are consistent each other.

RUBY_ENC_CODERANGE_BROKEN 

The object holds invalid/malformed/broken character(s).

RUBY_ENC_CODERANGE_MASK 

Where the coderange resides.

Definition at line 33 of file coderange.h.

Function Documentation

◆ RB_ENC_CODERANGE()

static enum ruby_coderange_type RB_ENC_CODERANGE ( VALUE  obj)
inlinestatic

Queries the (inline) code range of the passed object.

The object must be capable of having inline encoding. Using this macro needs deep understanding of bit level object binary layout.

Parameters
[in]objTarget object.
Returns
An enum ruby_coderange_type.

Definition at line 80 of file coderange.h.

Referenced by RB_ENC_CODERANGE_ASCIIONLY().

◆ RB_ENC_CODERANGE_AND()

static enum ruby_coderange_type RB_ENC_CODERANGE_AND ( enum ruby_coderange_type  a,
enum ruby_coderange_type  b 
)
inlinestatic

"Mix" two code ranges into one.

This is handy for instance when you concatenate two strings into one. Consider one of then is valid but the other isn't. The result must be invalid. This macro computes that kind of mixture.

Parameters
[in]aAn enum ruby_coderange_type.
[in]bAnother enum ruby_coderange_type.
Returns
The a "and" b.

Definition at line 144 of file coderange.h.

Referenced by rb_str_buf_append().

◆ RB_ENC_CODERANGE_ASCIIONLY()

static bool RB_ENC_CODERANGE_ASCIIONLY ( VALUE  obj)
inlinestatic

Queries the (inline) code range of the passed object is RUBY_ENC_CODERANGE_7BIT.

The object must be capable of having inline encoding. Using this macro needs deep understanding of bit level object binary layout.

Parameters
[in]objTarget object.
Return values
1It is ascii only.
0Otherwise (including cases when the range is not known).

Definition at line 114 of file coderange.h.

◆ RB_ENC_CODERANGE_CLEAN_P()

static bool RB_ENC_CODERANGE_CLEAN_P ( enum ruby_coderange_type  cr)
inlinestatic

Queries if a code range is "clean".

"Clean" in this context means it is known and valid.

Parameters
[in]crAn enum ruby_coderange_type.
Return values
1It is.
0It isn't.

Definition at line 80 of file coderange.h.

◆ RB_ENC_CODERANGE_CLEAR()

static void RB_ENC_CODERANGE_CLEAR ( VALUE  obj)
inlinestatic

Destructively clears the passed object's (inline) code range.

The object must be capable of having inline encoding. Using this macro needs deep understanding of bit level object binary layout.

Parameters
[out]objTarget object.
Postcondition
obj's code range is RUBY_ENC_CODERANGE_UNKNOWN.

Definition at line 144 of file coderange.h.

◆ RB_ENC_CODERANGE_SET()

static void RB_ENC_CODERANGE_SET ( VALUE  obj,
enum ruby_coderange_type  cr 
)
inlinestatic

Destructively modifies the passed object so that its (inline) code range is the passed one.

The object must be capable of having inline encoding. Using this macro needs deep understanding of bit level object binary layout.

Parameters
[out]objTarget object.
[out]crAn enum ruby_coderange_type.
Postcondition
obj's code range is cr.

Definition at line 129 of file coderange.h.

Referenced by RB_ENCODING_CODERANGE_SET().