Prism Ruby parser
|
A generic string type that can have various ownership semantics. More...
#include "prism/defines.h"
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | pm_string_t |
A generic string type that can have various ownership semantics. More... | |
Macros | |
#define | PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 }) |
Defines an empty string. | |
Enumerations | |
enum | pm_string_init_result_t { PM_STRING_INIT_SUCCESS = 0 , PM_STRING_INIT_ERROR_GENERIC = 1 , PM_STRING_INIT_ERROR_DIRECTORY = 2 } |
Represents the result of calling pm_string_mapped_init or pm_string_file_init. More... | |
Functions | |
PRISM_EXPORTED_FUNCTION size_t | pm_string_sizeof (void) |
Returns the size of the pm_string_t struct. | |
void | pm_string_shared_init (pm_string_t *string, const uint8_t *start, const uint8_t *end) |
Initialize a shared string that is based on initial input. | |
void | pm_string_owned_init (pm_string_t *string, uint8_t *source, size_t length) |
Initialize an owned string that is responsible for freeing allocated memory. | |
void | pm_string_constant_init (pm_string_t *string, const char *source, size_t length) |
Initialize a constant string that doesn't own its memory source. | |
void | pm_string_ensure_owned (pm_string_t *string) |
Ensure the string is owned. | |
int | pm_string_compare (const pm_string_t *left, const pm_string_t *right) |
Compare the underlying lengths and bytes of two strings. | |
A generic string type that can have various ownership semantics.
#define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 }) |
Defines an empty string.
This is useful for initializing a string that will be filled in later.
Represents the result of calling pm_string_mapped_init or pm_string_file_init.
We need this additional information because there is not a platform-agnostic way to indicate that the file that was attempted to be opened was a directory.
PRISM_EXPORTED_FUNCTION size_t pm_string_sizeof | ( | void | ) |
Returns the size of the pm_string_t struct.
This is necessary to allocate the correct amount of memory in the FFI backend.
This is necessary to allocate the correct amount of memory in the FFI backend.
void pm_string_shared_init | ( | pm_string_t * | string, |
const uint8_t * | start, | ||
const uint8_t * | end | ||
) |
Initialize a shared string that is based on initial input.
string | The string to initialize. |
start | The start of the string. |
end | The end of the string. |
void pm_string_owned_init | ( | pm_string_t * | string, |
uint8_t * | source, | ||
size_t | length | ||
) |
Initialize an owned string that is responsible for freeing allocated memory.
string | The string to initialize. |
source | The source of the string. |
length | The length of the string. |
void pm_string_constant_init | ( | pm_string_t * | string, |
const char * | source, | ||
size_t | length | ||
) |
Initialize a constant string that doesn't own its memory source.
string | The string to initialize. |
source | The source of the string. |
length | The length of the string. |
void pm_string_ensure_owned | ( | pm_string_t * | string | ) |
Ensure the string is owned.
If it is not, then reinitialize it as owned and copy over the previous source.
string | The string to ensure is owned. |
If it is not, then reinitialize it as owned and copy over the previous source.
int pm_string_compare | ( | const pm_string_t * | left, |
const pm_string_t * | right | ||
) |
Compare the underlying lengths and bytes of two strings.
Returns 0 if the strings are equal, a negative number if the left string is less than the right string, and a positive number if the left string is greater than the right string.
left | The left string to compare. |
right | The right string to compare. |
Returns 0 if the strings are equal, a negative number if the left string is less than the right string, and a positive number if the left string is greater than the right string.