Ruby
3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
|
A wrapper around a contiguous block of allocated memory. More...
#include "prism/defines.h"
#include "prism/util/pm_char.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | pm_buffer_t |
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory. More... | |
Enumerations | |
enum | pm_buffer_escaping_t { PM_BUFFER_ESCAPING_RUBY , PM_BUFFER_ESCAPING_JSON } |
The different types of escaping that can be performed by the buffer when appending a slice of Ruby source code. More... | |
Functions | |
PRISM_EXPORTED_FUNCTION size_t | pm_buffer_sizeof (void) |
Return the size of the pm_buffer_t struct. More... | |
bool | pm_buffer_init_capacity (pm_buffer_t *buffer, size_t capacity) |
Initialize a pm_buffer_t with the given capacity. More... | |
PRISM_EXPORTED_FUNCTION bool | pm_buffer_init (pm_buffer_t *buffer) |
Initialize a pm_buffer_t with its default values. More... | |
PRISM_EXPORTED_FUNCTION char * | pm_buffer_value (const pm_buffer_t *buffer) |
Return the value of the buffer. More... | |
PRISM_EXPORTED_FUNCTION size_t | pm_buffer_length (const pm_buffer_t *buffer) |
Return the length of the buffer. More... | |
void | pm_buffer_append_zeroes (pm_buffer_t *buffer, size_t length) |
Append the given amount of space as zeroes to the buffer. More... | |
void | pm_buffer_append_format (pm_buffer_t *buffer, const char *format,...) PRISM_ATTRIBUTE_FORMAT(2 |
Append a formatted string to the buffer. More... | |
void void | pm_buffer_append_string (pm_buffer_t *buffer, const char *value, size_t length) |
Append a string to the buffer. More... | |
void | pm_buffer_append_bytes (pm_buffer_t *buffer, const uint8_t *value, size_t length) |
Append a list of bytes to the buffer. More... | |
void | pm_buffer_append_byte (pm_buffer_t *buffer, uint8_t value) |
Append a single byte to the buffer. More... | |
void | pm_buffer_append_varuint (pm_buffer_t *buffer, uint32_t value) |
Append a 32-bit unsigned integer to the buffer as a variable-length integer. More... | |
void | pm_buffer_append_varsint (pm_buffer_t *buffer, int32_t value) |
Append a 32-bit signed integer to the buffer as a variable-length integer. More... | |
void | pm_buffer_append_double (pm_buffer_t *buffer, double value) |
Append a double to the buffer. More... | |
void | pm_buffer_append_source (pm_buffer_t *buffer, const uint8_t *source, size_t length, pm_buffer_escaping_t escaping) |
Append a slice of source code to the buffer. More... | |
void | pm_buffer_prepend_string (pm_buffer_t *buffer, const char *value, size_t length) |
Prepend the given string to the buffer. More... | |
void | pm_buffer_concat (pm_buffer_t *destination, const pm_buffer_t *source) |
Concatenate one buffer onto another. More... | |
void | pm_buffer_clear (pm_buffer_t *buffer) |
Clear the buffer by reducing its size to 0. More... | |
void | pm_buffer_rstrip (pm_buffer_t *buffer) |
Strip the whitespace from the end of the buffer. More... | |
size_t | pm_buffer_index (const pm_buffer_t *buffer, char value) |
Checks if the buffer includes the given value. More... | |
void | pm_buffer_insert (pm_buffer_t *buffer, size_t index, const char *value, size_t length) |
Insert the given string into the buffer at the given index. More... | |
PRISM_EXPORTED_FUNCTION void | pm_buffer_free (pm_buffer_t *buffer) |
Free the memory associated with the buffer. More... | |
A wrapper around a contiguous block of allocated memory.
Definition in file pm_buffer.h.
enum pm_buffer_escaping_t |
The different types of escaping that can be performed by the buffer when appending a slice of Ruby source code.
Definition at line 144 of file pm_buffer.h.
void pm_buffer_append_byte | ( | pm_buffer_t * | buffer, |
uint8_t | value | ||
) |
Append a single byte to the buffer.
buffer | The buffer to append to. |
value | The byte to append. |
Definition at line 135 of file pm_buffer.c.
Referenced by pm_buffer_append_varuint(), pm_dump_json(), pm_integer_string(), pm_serialize(), pm_serialize_lex(), pm_serialize_parse(), pm_serialize_parse_lex(), and pm_serialize_parse_stream().
void pm_buffer_append_bytes | ( | pm_buffer_t * | buffer, |
const uint8_t * | value, | ||
size_t | length | ||
) |
Append a list of bytes to the buffer.
buffer | The buffer to append to. |
value | The bytes to append. |
length | The length of the bytes to append. |
Definition at line 127 of file pm_buffer.c.
Referenced by pm_serialize_content().
void pm_buffer_append_double | ( | pm_buffer_t * | buffer, |
double | value | ||
) |
Append a double to the buffer.
buffer | The buffer to append to. |
value | The double to append. |
Definition at line 170 of file pm_buffer.c.
void pm_buffer_append_format | ( | pm_buffer_t * | buffer, |
const char * | format, | ||
... | |||
) |
Append a formatted string to the buffer.
buffer | The buffer to append to. |
format | The format string to append. |
... | The arguments to the format string. |
Referenced by pm_dump_json(), and pm_integer_string().
void pm_buffer_append_source | ( | pm_buffer_t * | buffer, |
const uint8_t * | source, | ||
size_t | length, | ||
pm_buffer_escaping_t | escaping | ||
) |
Append a slice of source code to the buffer.
buffer | The buffer to append to. |
source | The source code to append. |
length | The length of the source code to append. |
escaping | The type of escaping to perform. |
Definition at line 179 of file pm_buffer.c.
Referenced by pm_dump_json().
void void pm_buffer_append_string | ( | pm_buffer_t * | buffer, |
const char * | value, | ||
size_t | length | ||
) |
Append a string to the buffer.
buffer | The buffer to append to. |
value | The string to append. |
length | The length of the string to append. |
Definition at line 119 of file pm_buffer.c.
Referenced by pm_buffer_insert(), pm_dump_json(), pm_integer_string(), and pm_serialize_encoding().
void pm_buffer_append_varsint | ( | pm_buffer_t * | buffer, |
int32_t | value | ||
) |
Append a 32-bit signed integer to the buffer as a variable-length integer.
buffer | The buffer to append to. |
value | The integer to append. |
Definition at line 161 of file pm_buffer.c.
Referenced by pm_serialize_parse_comments().
void pm_buffer_append_varuint | ( | pm_buffer_t * | buffer, |
uint32_t | value | ||
) |
Append a 32-bit unsigned integer to the buffer as a variable-length integer.
buffer | The buffer to append to. |
value | The integer to append. |
Definition at line 144 of file pm_buffer.c.
Referenced by pm_buffer_append_varsint(), pm_serialize_comment_list(), pm_serialize_content(), and pm_serialize_encoding().
void pm_buffer_append_zeroes | ( | pm_buffer_t * | buffer, |
size_t | length | ||
) |
Append the given amount of space as zeroes to the buffer.
buffer | The buffer to append to. |
length | The amount of space to append and zero. |
Definition at line 86 of file pm_buffer.c.
Referenced by pm_buffer_insert(), and pm_serialize_content().
void pm_buffer_clear | ( | pm_buffer_t * | buffer | ) |
Clear the buffer by reducing its size to 0.
This does not free the allocated memory, but it does allow the buffer to be reused.
buffer | The buffer to clear. |
This does not free the allocated memory, but it does allow the buffer to be reused.
Definition at line 272 of file pm_buffer.c.
void pm_buffer_concat | ( | pm_buffer_t * | destination, |
const pm_buffer_t * | source | ||
) |
Concatenate one buffer onto another.
destination | The buffer to concatenate onto. |
source | The buffer to concatenate. |
Definition at line 261 of file pm_buffer.c.
PRISM_EXPORTED_FUNCTION void pm_buffer_free | ( | pm_buffer_t * | buffer | ) |
Free the memory associated with the buffer.
buffer | The buffer to free. |
Definition at line 315 of file pm_buffer.c.
Referenced by pm_prettyprint(), and pm_serialize_parse_stream().
size_t pm_buffer_index | ( | const pm_buffer_t * | buffer, |
char | value | ||
) |
Checks if the buffer includes the given value.
buffer | The buffer to check. |
value | The value to check for. |
Definition at line 290 of file pm_buffer.c.
PRISM_EXPORTED_FUNCTION bool pm_buffer_init | ( | pm_buffer_t * | buffer | ) |
Initialize a pm_buffer_t with its default values.
buffer | The buffer to initialize. |
Definition at line 27 of file pm_buffer.c.
Referenced by pm_parse_stream().
bool pm_buffer_init_capacity | ( | pm_buffer_t * | buffer, |
size_t | capacity | ||
) |
Initialize a pm_buffer_t with the given capacity.
buffer | The buffer to initialize. |
capacity | The capacity of the buffer. |
Definition at line 15 of file pm_buffer.c.
Referenced by pm_buffer_init().
void pm_buffer_insert | ( | pm_buffer_t * | buffer, |
size_t | index, | ||
const char * | value, | ||
size_t | length | ||
) |
Insert the given string into the buffer at the given index.
buffer | The buffer to insert into. |
index | The index to insert at. |
value | The string to insert. |
length | The length of the string to insert. |
Definition at line 299 of file pm_buffer.c.
PRISM_EXPORTED_FUNCTION size_t pm_buffer_length | ( | const pm_buffer_t * | buffer | ) |
Return the length of the buffer.
buffer | The buffer to get the length of. |
Definition at line 43 of file pm_buffer.c.
Referenced by pm_parse_stream().
void pm_buffer_prepend_string | ( | pm_buffer_t * | buffer, |
const char * | value, | ||
size_t | length | ||
) |
Prepend the given string to the buffer.
buffer | The buffer to prepend to. |
value | The string to prepend. |
length | The length of the string to prepend. |
Definition at line 249 of file pm_buffer.c.
void pm_buffer_rstrip | ( | pm_buffer_t * | buffer | ) |
Strip the whitespace from the end of the buffer.
buffer | The buffer to strip. |
Definition at line 280 of file pm_buffer.c.
PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof | ( | void | ) |
Return the size of the pm_buffer_t struct.
Definition at line 7 of file pm_buffer.c.
PRISM_EXPORTED_FUNCTION char* pm_buffer_value | ( | const pm_buffer_t * | buffer | ) |
Return the value of the buffer.
buffer | The buffer to get the value of. |
Definition at line 35 of file pm_buffer.c.
Referenced by pm_parse_stream().