summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-07-18 16:32:29 -0400
committerpommicket <pommicket@gmail.com>2023-07-19 19:02:27 -0400
commit8d7f6dea1113f48f812f734b4bba510ef35b3f27 (patch)
treeca67375c4def9f7780388b58d3a44092ecab20db /util.c
parent94a6d21d4c2fe5fc2806cd28ae36a2b0e1928914 (diff)
start "multifonts"
Diffstat (limited to 'util.c')
-rw-r--r--util.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/util.c b/util.c
index 02c5fc7..96622ec 100644
--- a/util.c
+++ b/util.c
@@ -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