Utility functions for string and file operations. More...
Functions | |
char * | read_filef (FILE *file) |
Reads the contents of a file into a string. | |
char * | read_file (const char *path) |
Reads the contents of a file into a string. | |
char * | get_folder_path (const char *fullpath) |
Extracts the folder path from a full file path. | |
char * | convert_path (const char *path) |
Converts backslashes in a path to forward slashes. | |
char * | concat_path (const char *path1, const char *path2) |
Concatenates two file paths. | |
int | find_string_index (char *str, const char *const *str_list, int list_size) |
Finds the index of a string in a list of strings. | |
char * | format_escaped_newlines (char *str) |
Formats escaped newlines in a string. | |
int | is_utf8_start_byte (unsigned char c) |
Checks if a byte is a valid UTF-8 start byte. | |
void | remove_last_utf8_char (char *inputBuffer) |
Removes the last UTF-8 character from a string. | |
Utility functions for string and file operations.
char * read_filef | ( | FILE * | file | ) |
Reads the contents of a file into a string.
This function reads the contents of a file that is already open and returns them as a dynamically allocated string. The caller is responsible for freeing the allocated memory.
file | The file to read from. |
char * read_file | ( | const char * | path | ) |
Reads the contents of a file into a string.
This function opens the file specified by the given path, reads its contents, and returns them as a dynamically allocated string. The caller is responsible for freeing the allocated memory.
path | The path to the file to be read. |
char * get_folder_path | ( | const char * | fullpath | ) |
Extracts the folder path from a full file path.
This function takes a full file path and returns the folder path portion of it. The returned string is dynamically allocated, and the caller is responsible for freeing the allocated memory.
fullpath | The full file path from which to extract the folder path. |
char * convert_path | ( | const char * | path | ) |
Converts backslashes in a path to forward slashes.
This function takes a path string and converts any backslashes to forward slashes. The returned string is dynamically allocated, and the caller is responsible for freeing the allocated memory.
path | The path to convert. |
char * concat_path | ( | const char * | path1, |
const char * | path2 | ||
) |
Concatenates two file paths.
This function concatenates two file paths, adding a path separator between them if necessary. The returned string is dynamically allocated, and the caller is responsible for freeing the allocated memory.
path1 | The first part of the path. |
path2 | The second part of the path. |
int find_string_index | ( | char * | str, |
const char *const * | str_list, | ||
int | list_size | ||
) |
Finds the index of a string in a list of strings.
This function searches for a given string in a list of strings and returns the index of the first occurrence. If the string is not found, the function returns -1.
str | The string to search for. |
str_list | The list of strings to search within. |
list_size | The number of strings in the list. |
char * format_escaped_newlines | ( | char * | str | ) |
Formats escaped newlines in a string.
This function replaces escaped newline sequences in a string with actual newline characters. It modifies the input string in place.
str | The string to format. |
int is_utf8_start_byte | ( | unsigned char | c | ) |
Checks if a byte is a valid UTF-8 start byte.
This function determines whether a given byte is a valid start byte for a UTF-8 encoded character. A valid start byte is any byte that can begin a multi-byte UTF-8 character.
c | The byte to check. |
void remove_last_utf8_char | ( | char * | inputBuffer | ) |
Removes the last UTF-8 character from a string.
This function removes the last UTF-8 encoded character from the given input buffer. It correctly handles multi-byte UTF-8 characters and adjusts the string length accordingly.
inputBuffer | The string from which to remove the last UTF-8 character. |