diff options
author | pommicket <pommicket@gmail.com> | 2023-07-18 16:32:29 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-07-18 16:32:29 -0400 |
commit | 8f2258fcce0d3bd5e6cf1364bd58669391fbab7c (patch) | |
tree | e8bdc9ea407237beabd8f1c5b9b5307cc14beb6c /util.c | |
parent | 2d2f0a09b180cf3bd6a2bc0ad3d21ea956398822 (diff) |
start "multifonts"
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -12,6 +12,7 @@ #error "Unrecognized operating system." #endif #include <wctype.h> +#include <ctype.h> // on 16-bit systems, this is 16383. on 32/64-bit systems, this is 1073741823 // it is unusual to have a string that long. @@ -235,11 +236,31 @@ void strn_cpy(char *dst, size_t dst_sz, const char *src, size_t src_len) { dst[n] = 0; } -// safer version of strcpy. dst_sz includes a null terminator. void str_cpy(char *dst, size_t dst_sz, const char *src) { strn_cpy(dst, dst_sz, src, SIZE_MAX); } +void str_trim_start(char *str) { + size_t n = strspn(str, "\r\v\t\n\f "); + size_t len = strlen(str); + memmove(str, str + n, len - n); + str[len - n] = '\0'; +} + +void str_trim_end(char *str) { + size_t i = strlen(str); + while (i > 0 && isspace(str[i - 1])) { + str[i - 1] = '\0'; + --i; + } +} + + +void str_trim(char *str) { + str_trim_end(str); + str_trim_start(str); +} + char *a_sprintf(PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2); char *a_sprintf(const char *fmt, ...) { // idk if you can always just pass NULL to vsnprintf |