diff src/datatypes.c @ 12:0cc2555db371

*: make our string functions not stupid strncat() made everything slow! new addition internally: an EDL_header structure to make things not stupid. if we were using C++ it wouldn't really be necessary, but alas :)
author Paper <paper@paper.us.eu.org>
date Wed, 27 Mar 2024 13:38:30 -0400
parents 0c98b46eaf73
children 2d7c810a1ac2
line wrap: on
line diff
--- a/src/datatypes.c	Fri Mar 22 20:51:46 2024 -0400
+++ b/src/datatypes.c	Wed Mar 27 13:38:30 2024 -0400
@@ -1,5 +1,6 @@
 #include "datatypes.h"
 #include "util.h"
+#include "str.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -100,31 +101,33 @@
 	return EDL_internal_append_offset(input, offset, length);
 }
 
-char* EDL_internal_integer_to_string(int value) {
-	char out[256] = {0}; /* this ought to be enough. */
-	snprintf(out, 256, "%d", value);
-	out[255] = '\0';
-	return EDL_internal_strdup(out);
+int EDL_internal_append_integer_to_string(EDL_internal_string* str, int value) {
+	char out[32] = {0}; /* this ought to be enough. */
+	int c = snprintf(out, 32, "%d", value);
+	return EDL_internal_string_append(str, out, (c < 32) ? c : 32);
+}
+
+int EDL_internal_append_double_to_string(EDL_internal_string* str, double value) {
+	char out[128] = {0};
+	int c = snprintf(out, 128, "%.6f", value);
+	return EDL_internal_string_append(str, out, (c < 128) ? c : 128);
 }
 
-char* EDL_internal_double_to_string(double value) {
-	char out[256] = {0};
-	snprintf(out, 256, "%.6f", value);
-	out[255] = '\0';
-	return EDL_internal_strdup(out);
+int EDL_internal_append_bool_to_string(EDL_internal_string* str, bool value) {
+	if (value) {
+		EDL_internal_string_append(str, "TRUE", 4);
+	} else {
+		EDL_internal_string_append(str, "FALSE", 5);
+	}
 }
 
-char* EDL_internal_bool_to_string(bool value) {
-	return EDL_internal_strdup(value ? "TRUE" : "FALSE");
-}
-
-char* EDL_internal_media_type_to_string(EDL_media_type_t value) {
+int EDL_internal_append_media_type_to_string(EDL_internal_string* str, EDL_media_type_t value) {
 	switch (value) {
 		case MEDIATYPE_AUDIO:
-			return EDL_internal_strdup("AUDIO");
+			return EDL_internal_string_append(str, "AUDIO", 5);
 		case MEDIATYPE_VIDEO:
 		case MEDIATYPE_UNKNOWN:
 		default:
-			return EDL_internal_strdup("VIDEO");
+			return EDL_internal_string_append(str, "VIDEO", 5);
 	}
 }