Ruby: prism/util/pm_newline_list.h Source File

Ruby 4.0.5p0 (2026-05-20 revision 64336ffd0ee9e1f4c05891695a3d7b49cb709721)

pm_newline_list.h
Go to the documentation of this file.
1
14#ifndef PRISM_NEWLINE_LIST_H
15#define PRISM_NEWLINE_LIST_H
16
17#include "prism/defines.h"
18
19#include <assert.h>
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdlib.h>
23
28 typedef struct {
30 const uint8_t *start;
31
33 size_t size;
34
36 size_t capacity;
37
39 size_t *offsets;
40} pm_newline_list_t;
41
45 typedef struct {
47 int32_t line;
48
50 uint32_t column;
51} pm_line_column_t;
52
62bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
63
69void
70 pm_newline_list_clear(pm_newline_list_t *list);
71
81bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor);
82
92int32_t pm_newline_list_line(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line);
93
104 pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line);
105
111void pm_newline_list_free(pm_newline_list_t *list);
112
113#endif
assert.h
pm_newline_list_line_column
pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line)
Returns the line and column of the given offset.
Definition pm_newline_list.c:92
pm_newline_list_free
void pm_newline_list_free(pm_newline_list_t *list)
Free the internal memory allocated for the newline list.
Definition pm_newline_list.c:123
pm_newline_list_line
int32_t pm_newline_list_line(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line)
Returns the line of the given offset.
Definition pm_newline_list.c:62
pm_newline_list_init
bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity)
Initialize a new newline list with the given capacity.
Definition pm_newline_list.c:8
pm_newline_list_append
bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor)
Append a new offset to the newline list.
Definition pm_newline_list.c:35
pm_newline_list_clear
void pm_newline_list_clear(pm_newline_list_t *list)
Clear out the newlines that have been appended to the list.
Definition pm_newline_list.c:26
defines.h
Macro definitions used throughout the prism library.
stdbool.h
C99 shim for <stdbool.h>.
pm_line_column_t
A line and column in a string.
Definition pm_newline_list.h:45
pm_line_column_t::column
uint32_t column
The column number.
Definition pm_newline_list.h:50
pm_line_column_t::line
int32_t line
The line number.
Definition pm_newline_list.h:47
pm_newline_list_t
A list of offsets of newlines in a string.
Definition pm_newline_list.h:28
pm_newline_list_t::start
const uint8_t * start
A pointer to the start of the source string.
Definition pm_newline_list.h:30
pm_newline_list_t::capacity
size_t capacity
The capacity of the list that has been allocated.
Definition pm_newline_list.h:36
pm_newline_list_t::offsets
size_t * offsets
The list of offsets.
Definition pm_newline_list.h:39
pm_newline_list_t::size
size_t size
The number of offsets in the list.
Definition pm_newline_list.h:33