\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/cpanel/ea-ruby27/root/usr/local/share/gems/gems/prism-1.9.0/include/prism/util/

Viewing File: pm_buffer.h

/**
 * @file pm_buffer.h
 *
 * A wrapper around a contiguous block of allocated memory.
 */
#ifndef PRISM_BUFFER_H
#define PRISM_BUFFER_H

#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>

/**
 * A pm_buffer_t is a simple memory buffer that stores data in a contiguous
 * block of memory.
 */
typedef struct {
    /** The length of the buffer in bytes. */
    size_t length;

    /** The capacity of the buffer in bytes that has been allocated. */
    size_t capacity;

    /** A pointer to the start of the buffer. */
    char *value;
} pm_buffer_t;

/**
 * Return the size of the pm_buffer_t struct.
 *
 * @returns The size of the pm_buffer_t struct.
 */
PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void);

/**
 * Initialize a pm_buffer_t with the given capacity.
 *
 * @param buffer The buffer to initialize.
 * @param capacity The capacity of the buffer.
 * @returns True if the buffer was initialized successfully, false otherwise.
 */
bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);

/**
 * Initialize a pm_buffer_t with its default values.
 *
 * @param buffer The buffer to initialize.
 * @returns True if the buffer was initialized successfully, false otherwise.
 *
 * \public \memberof pm_buffer_t
 */
PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);

/**
 * Return the value of the buffer.
 *
 * @param buffer The buffer to get the value of.
 * @returns The value of the buffer.
 *
 * \public \memberof pm_buffer_t
 */
PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer);

/**
 * Return the length of the buffer.
 *
 * @param buffer The buffer to get the length of.
 * @returns The length of the buffer.
 *
 * \public \memberof pm_buffer_t
 */
PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer);

/**
 * Append the given amount of space as zeroes to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param length The amount of space to append and zero.
 */
void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length);

/**
 * Append a formatted string to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param format The format string to append.
 * @param ... The arguments to the format string.
 */
void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);

/**
 * Append a string to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param value The string to append.
 * @param length The length of the string to append.
 */
void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length);

/**
 * Append a list of bytes to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param value The bytes to append.
 * @param length The length of the bytes to append.
 */
void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length);

/**
 * Append a single byte to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param value The byte to append.
 */
void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value);

/**
 * Append a 32-bit unsigned integer to the buffer as a variable-length integer.
 *
 * @param buffer The buffer to append to.
 * @param value The integer to append.
 */
void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value);

/**
 * Append a 32-bit signed integer to the buffer as a variable-length integer.
 *
 * @param buffer The buffer to append to.
 * @param value The integer to append.
 */
void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value);

/**
 * Append a double to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param value The double to append.
 */
void pm_buffer_append_double(pm_buffer_t *buffer, double value);

/**
 * Append a unicode codepoint to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param value The character to append.
 * @returns True if the codepoint was valid and appended successfully, false
 *   otherwise.
 */
bool pm_buffer_append_unicode_codepoint(pm_buffer_t *buffer, uint32_t value);

/**
 * The different types of escaping that can be performed by the buffer when
 * appending a slice of Ruby source code.
 */
typedef enum {
    PM_BUFFER_ESCAPING_RUBY,
    PM_BUFFER_ESCAPING_JSON
} pm_buffer_escaping_t;

/**
 * Append a slice of source code to the buffer.
 *
 * @param buffer The buffer to append to.
 * @param source The source code to append.
 * @param length The length of the source code to append.
 * @param escaping The type of escaping to perform.
 */
void pm_buffer_append_source(pm_buffer_t *buffer, const uint8_t *source, size_t length, pm_buffer_escaping_t escaping);

/**
 * Prepend the given string to the buffer.
 *
 * @param buffer The buffer to prepend to.
 * @param value The string to prepend.
 * @param length The length of the string to prepend.
 */
void pm_buffer_prepend_string(pm_buffer_t *buffer, const char *value, size_t length);

/**
 * Concatenate one buffer onto another.
 *
 * @param destination The buffer to concatenate onto.
 * @param source The buffer to concatenate.
 */
void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source);

/**
 * 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.
 *
 * @param buffer The buffer to clear.
 */
void pm_buffer_clear(pm_buffer_t *buffer);

/**
 * Strip the whitespace from the end of the buffer.
 *
 * @param buffer The buffer to strip.
 */
void pm_buffer_rstrip(pm_buffer_t *buffer);

/**
 * Checks if the buffer includes the given value.
 *
 * @param buffer The buffer to check.
 * @param value The value to check for.
 * @returns The index of the first occurrence of the value in the buffer, or
 *   SIZE_MAX if the value is not found.
 */
size_t pm_buffer_index(const pm_buffer_t *buffer, char value);

/**
 * Insert the given string into the buffer at the given index.
 *
 * @param buffer The buffer to insert into.
 * @param index The index to insert at.
 * @param value The string to insert.
 * @param length The length of the string to insert.
 */
void pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length);

/**
 * Free the memory associated with the buffer.
 *
 * @param buffer The buffer to free.
 *
 * \public \memberof pm_buffer_t
 */
PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);

#endif