bootstrap/include/string_utils.h

62 lines
1.5 KiB
C
Raw Permalink Normal View History

/**
@file
2023-11-25 22:29:35 +00:00
@brief String-related utility functions.
*/
2023-11-25 22:29:35 +00:00
#ifndef _BOOTSTRAP_STRING_UTILS_H
#define _BOOTSTRAP_STRING_UTILS_H
#include <stdlib.h>
/**
@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);
/**
@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);
/**
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 */