Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)
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
28typedef struct {
30 const uint8_t *start;
31
33 size_t size;
34
36 size_t capacity;
37
39 size_t *offsets;
41
45typedef struct {
47 size_t line;
48
50 size_t column;
52
62bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
63
73bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor);
74
84bool pm_newline_list_check_append(pm_newline_list_t *list, const uint8_t *cursor);
85
95pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor);
96
103
104#endif
void pm_newline_list_free(pm_newline_list_t *list)
Free the internal memory allocated for the newline list.
pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor)
Returns the line and column of the given offset.
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.
bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor)
Append a new offset to the newline list.
bool pm_newline_list_check_append(pm_newline_list_t *list, const uint8_t *cursor)
Conditionally append a new offset to the newline list, if the value passed in is a newline.
Macro definitions used throughout the prism library.
C99 shim for <stdbool.h>
A line and column in a string.
size_t column
The column number.
size_t line
The line number.
A list of offsets of newlines in a string.
const uint8_t * start
A pointer to the start of the source string.
size_t capacity
The capacity of the list that has been allocated.
size_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.