Claude Chappe' Curse - A C Game
Logo Institut d'Informatique Claude Chappe Logo Université de Le Mans Logo Raeptor Production
 
Loading...
Searching...
No Matches
String and File I/O Utilities

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.
 

Detailed Description

Utility functions for string and file operations.

Function Documentation

◆ read_filef()

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.

Parameters
fileThe file to read from.
Returns
A pointer to the dynamically allocated string containing the file contents.
Note
The caller is responsible for freeing the allocated memory.
The file must be open and readable.

◆ read_file()

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.

Parameters
pathThe path to the file to be read.
Returns
A pointer to the dynamically allocated string containing the file contents.
Note
The caller is responsible for freeing the allocated memory.

◆ get_folder_path()

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.

Parameters
fullpathThe full file path from which to extract the folder path.
Returns
A pointer to the dynamically allocated string containing the folder path.
Note
The caller is responsible for freeing the allocated memory.

◆ convert_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.

Parameters
pathThe path to convert.
Returns
A pointer to the dynamically allocated string containing the converted path.
Note
The caller is responsible for freeing the allocated memory.

◆ concat_path()

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.

Parameters
path1The first part of the path.
path2The second part of the path.
Returns
A pointer to the dynamically allocated string containing the concatenated path.
Note
The caller is responsible for freeing the allocated memory.

◆ find_string_index()

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.

Parameters
strThe string to search for.
str_listThe list of strings to search within.
list_sizeThe number of strings in the list.
Returns
The index of the first occurrence of the string, or -1 if not found.

◆ format_escaped_newlines()

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.

Parameters
strThe string to format.
Returns
A pointer to the modified string.
Note
This function modifies the input string in place.

◆ is_utf8_start_byte()

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.

Parameters
cThe byte to check.
Returns
1 if the byte is a valid UTF-8 start byte, 0 otherwise.

◆ remove_last_utf8_char()

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.

Parameters
inputBufferThe string from which to remove the last UTF-8 character.