/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* stream.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */ /* Updated: 2024/10/17 15:57:59 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef STREAM_H # define STREAM_H # include /// @brief Represents a string and an associated cursor. typedef struct s_stream { /// @brief Index of the cursor. int i; /// @brief Pointer to the string. const char *str; } t_stream; /// @brief Read a specific string, error if it isn't the expected string. /// Skip the potential blank space before the string. /// /// @param str Expected string. /// @param stream Stream to use. /// @param err Set to true if an error occured. /// If already true, the function won't do anything. void read_expected_string(const char *str, t_stream *stream, bool *err); /// @brief Read an unsigned int (which fits the pattern /[0-9]+/). /// Skip the potential blank space before the string. /// /// @param dest Will be set to the value of the unsigned integer. /// @param stream Stream to use. /// @param err Set to true if an error occured. /// If already true, the function won't do anything. void read_unsigned(unsigned int *dest, t_stream *stream, bool *err); /// @brief Read a string until limit char or \0. /// Skip the potential blank space before the string. /// /// @param c Limit char. /// @param dest Will be set to an alloc'd pointer to the read string. /// NULL if alloc error. /// @param stream Stream to use. /// @param err Set to true if an error occured. /// If already true, the function won't do anything. void read_until(char c, char **dest, t_stream *stream, bool *err); /// @brief Read blank space until the next non-blank character or the EOF. /// ' ' and '\t' are the only characters considered blank. /// /// @param stream Stream to use. /// @return false if there was no blank space to read, true otherwise. bool read_blank(t_stream *stream); #endif