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

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

Macros | Enumerations | Functions
coderange.h File Reference

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"`

Go to the source code of this file.

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

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

## Detailed Description

Routines for code ranges.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

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

enum 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()

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] | obj | Target object.

Returns
  An enum ruby_coderange_type.

Definition at line 95 of file coderange.h.

Referenced by RB_ENC_CODERANGE(), and RB_ENC_CODERANGE_ASCIIONLY().

## ◆ RB_ENC_CODERANGE_AND()

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] | a | An enum ruby_coderange_type.
  [in] | b | Another enum ruby_coderange_type.

Returns
  The a "and" b.

Definition at line 162 of file coderange.h.

Referenced by RB_ENC_CODERANGE_AND(), and rb_str_buf_append().

## ◆ RB_ENC_CODERANGE_ASCIIONLY()

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] | obj | Target object.

Return values

  1 | It is ascii only.
  0 | Otherwise (including cases when the range is not known).

Definition at line 114 of file coderange.h.

Referenced by RB_ENC_CODERANGE_ASCIIONLY().

## ◆ RB_ENC_CODERANGE_CLEAN_P()

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] | cr | An enum ruby_coderange_type.

Return values

  1 | It is.
  0 | It isn't.

Definition at line 80 of file coderange.h.

Referenced by RB_ENC_CODERANGE_CLEAN_P().

## ◆ RB_ENC_CODERANGE_CLEAR()

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] | obj | Target object.

Postcondition
  obj's code range is RUBY_ENC_CODERANGE_UNKNOWN.

Definition at line 144 of file coderange.h.

## ◆ RB_ENC_CODERANGE_SET()

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] | obj | Target object.
  [out] | cr | An 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().