2022-07-20 06:58:14 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2022-03-14 23:09:25 +00:00
|
|
|
#include <libreborn/string.h>
|
|
|
|
|
|
|
|
// Sanitize String
|
|
|
|
void sanitize_string(char **str, int max_length, unsigned int allow_newlines) {
|
|
|
|
// Store Message Length
|
|
|
|
int length = strlen(*str);
|
|
|
|
// Truncate Message
|
|
|
|
if (max_length != -1 && length > max_length) {
|
|
|
|
(*str)[max_length] = '\0';
|
|
|
|
length = max_length;
|
|
|
|
}
|
|
|
|
// Loop Through Message
|
2022-07-20 06:58:14 +00:00
|
|
|
if (!allow_newlines) {
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
if ((*str)[i] == '\n' || (*str)[i] == '\r') {
|
|
|
|
// Replace Newline
|
|
|
|
(*str)[i] = ' ';
|
|
|
|
}
|
2022-03-14 23:09:25 +00:00
|
|
|
}
|
2022-07-20 06:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-25 02:47:34 +00:00
|
|
|
// Starts With
|
|
|
|
int starts_with(const char *str, const char *prefix) {
|
|
|
|
return strncmp(prefix, str, strlen(prefix)) == 0;
|
|
|
|
}
|