Macro libyml::WIDTH

source ·
macro_rules! WIDTH {
    ($string:expr) => { ... };
}
Expand description

Returns the width of the Unicode character at the current position in a string.

This macro calculates the width of the Unicode character that the pointer in the given string is currently pointing to. The width is determined by checking the first byte of the character at the current position in the string, using the WIDTH_AT! macro with an offset of 0.

§Parameters

  • string: A reference to a struct containing a pointer field that points to a byte in a string. This byte is expected to be the start of a Unicode character.

§Return

The width of the Unicode character at the current position of the pointer in the string:

  • If the first byte is in the range 0x00 to 0x7F, the width is 1 byte.
  • If the first byte is in the range 0xC0 to 0xDF, the width is 2 bytes.
  • If the first byte is in the range 0xE0 to 0xEF, the width is 3 bytes.
  • If the first byte is in the range 0xF0 to 0xF7, the width is 4 bytes.
  • If the first byte does not match any of the above patterns, the width is 0, indicating an invalid or unsupported character.

§Safety

The caller must ensure that the pointer in the string is pointing to valid memory and that the memory contains a valid Unicode sequence. Using this macro on an invalid or corrupted string may result in undefined behavior or incorrect results.