2023-11-25 19:18:36 +00:00
|
|
|
/**
|
|
|
|
@file
|
2023-11-25 22:29:35 +00:00
|
|
|
@brief String-related utility functions.
|
2023-11-25 19:18:36 +00:00
|
|
|
*/
|
2023-11-25 22:29:35 +00:00
|
|
|
|
|
|
|
#ifndef _BOOTSTRAP_STRING_UTILS_H
|
|
|
|
#define _BOOTSTRAP_STRING_UTILS_H
|
2023-11-23 20:31:54 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-11-25 19:18:36 +00:00
|
|
|
/**
|
|
|
|
@brief Concatenate the list of segments into a Unix-style path.
|
|
|
|
|
|
|
|
This function assumes a forward slash path separator (i.e. `/`).
|
|
|
|
|
|
|
|
@param n
|
|
|
|
The number of segments to join together.
|
|
|
|
@param segments
|
|
|
|
The path components to join together.
|
|
|
|
@return
|
|
|
|
The concatenation of the path components via `/`. The caller takes ownership
|
|
|
|
of this value.
|
|
|
|
*/
|
2023-11-25 22:29:35 +00:00
|
|
|
char *join(size_t n, const char *segments[static n], char sep);
|
2023-11-23 20:31:54 +00:00
|
|
|
|
2023-11-25 22:47:47 +00:00
|
|
|
/**
|
|
|
|
@brief Perform case insensitive string comparison.
|
|
|
|
|
|
|
|
This function operates like `strcmp` except comparison ignores case.
|
|
|
|
|
|
|
|
@param s1
|
|
|
|
C string to be compared.
|
|
|
|
@param s2
|
|
|
|
C string to be compared.
|
|
|
|
@return
|
|
|
|
An integral value indicating the relationship between the strings:
|
|
|
|
- `< 0`: the first character (converted uppercase) that does not match has a
|
|
|
|
lower value in @p s1 than in @p s2.
|
|
|
|
- `= 0`: the contents of both strings are equal.
|
|
|
|
- `> 0`: the first character (converted uppercase) that does not match has a
|
|
|
|
greater value in @p s1 than in @p s2.
|
|
|
|
*/
|
|
|
|
int strcmp_ci(const char *s1, const char *s2);
|
|
|
|
|
2023-11-30 16:33:25 +00:00
|
|
|
/**
|
|
|
|
Removes any leading whitespace characters from the string in-place.
|
|
|
|
|
|
|
|
@param s
|
|
|
|
The string to trim the start of.
|
|
|
|
*/
|
|
|
|
void trim_leading(char *s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes any tailing whitespace characters from the string in-place.
|
|
|
|
|
|
|
|
@param s
|
|
|
|
The string to trim the end of.
|
|
|
|
*/
|
|
|
|
void trim_trailing(char *s);
|
|
|
|
|
2023-11-25 22:29:35 +00:00
|
|
|
#endif /* _BOOTSTRAP_STRING_UTILS_H */
|