Ruby: pm_encoding_t Struct Reference

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

Data Fields
pm_encoding_t Struct Reference

This struct defines the functions necessary to implement the encoding interface so we can determine how many bytes the subsequent character takes. More...

`#include <encoding.h>`

## Data Fields
size_t(* | char_width )(const uint8_t *b, ptrdiff_t n)
| Return the number of bytes that the next character takes if it is valid in the encoding.
size_t(* | alpha_char )(const uint8_t *b, ptrdiff_t n)
| Return the number of bytes that the next character takes if it is valid in the encoding and is alphabetical.
size_t(* | alnum_char )(const uint8_t *b, ptrdiff_t n)
| Return the number of bytes that the next character takes if it is valid in the encoding and is alphanumeric.
bool(* | isupper_char )(const uint8_t *b, ptrdiff_t n)
| Return true if the next character is valid in the encoding and is an uppercase character.
const char * | name
| The name of the encoding.
bool | multibyte
| Return true if the encoding is a multibyte encoding.

## Detailed Description

This struct defines the functions necessary to implement the encoding interface so we can determine how many bytes the subsequent character takes.

Each callback should return the number of bytes, or 0 if the next bytes are invalid for the encoding and type.

Definition at line 23 of file encoding.h.

## Field Documentation

## ◆ alnum_char

size_t(* pm_encoding_t::alnum_char) (const uint8_t *b, ptrdiff_t n)

Return the number of bytes that the next character takes if it is valid in the encoding and is alphanumeric.

Does not read more than n bytes. It is assumed that n is at least 1.

Definition at line 43 of file encoding.h.

## ◆ alpha_char

size_t(* pm_encoding_t::alpha_char) (const uint8_t *b, ptrdiff_t n)

Return the number of bytes that the next character takes if it is valid in the encoding and is alphabetical.

Does not read more than n bytes. It is assumed that n is at least 1.

Definition at line 36 of file encoding.h.

## ◆ char_width

size_t(* pm_encoding_t::char_width) (const uint8_t *b, ptrdiff_t n)

Return the number of bytes that the next character takes if it is valid in the encoding.

Does not read more than n bytes. It is assumed that n is at least 1.

Definition at line 29 of file encoding.h.

Referenced by pm_memchr().

## ◆ isupper_char

bool(* pm_encoding_t::isupper_char) (const uint8_t *b, ptrdiff_t n)

Return true if the next character is valid in the encoding and is an uppercase character.

Does not read more than n bytes. It is assumed that n is at least 1.

Definition at line 50 of file encoding.h.

## ◆ multibyte

bool pm_encoding_t::multibyte

Return true if the encoding is a multibyte encoding.

Definition at line 61 of file encoding.h.

Referenced by pm_memchr(), and pm_strpbrk().

## ◆ name

const char* pm_encoding_t::name

The name of the encoding.

This should correspond to a value that can be passed to Encoding.find in Ruby.

Definition at line 56 of file encoding.h.

Referenced by pm_serialize_encoding().

The documentation for this struct was generated from the following file:

- prism/encoding.h