Mercurial > libedl
comparison 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 |
comparison
equal
deleted
inserted
replaced
11:a0bd92c4c0e8 | 12:0cc2555db371 |
---|---|
1 #include "datatypes.h" | 1 #include "datatypes.h" |
2 #include "util.h" | 2 #include "util.h" |
3 #include "str.h" | |
3 | 4 |
4 #include <stdlib.h> | 5 #include <stdlib.h> |
5 #include <string.h> | 6 #include <string.h> |
6 #include <stdio.h> | 7 #include <stdio.h> |
7 | 8 |
98 (*string_return)[s_length] = '\0'; | 99 (*string_return)[s_length] = '\0'; |
99 | 100 |
100 return EDL_internal_append_offset(input, offset, length); | 101 return EDL_internal_append_offset(input, offset, length); |
101 } | 102 } |
102 | 103 |
103 char* EDL_internal_integer_to_string(int value) { | 104 int EDL_internal_append_integer_to_string(EDL_internal_string* str, int value) { |
104 char out[256] = {0}; /* this ought to be enough. */ | 105 char out[32] = {0}; /* this ought to be enough. */ |
105 snprintf(out, 256, "%d", value); | 106 int c = snprintf(out, 32, "%d", value); |
106 out[255] = '\0'; | 107 return EDL_internal_string_append(str, out, (c < 32) ? c : 32); |
107 return EDL_internal_strdup(out); | |
108 } | 108 } |
109 | 109 |
110 char* EDL_internal_double_to_string(double value) { | 110 int EDL_internal_append_double_to_string(EDL_internal_string* str, double value) { |
111 char out[256] = {0}; | 111 char out[128] = {0}; |
112 snprintf(out, 256, "%.6f", value); | 112 int c = snprintf(out, 128, "%.6f", value); |
113 out[255] = '\0'; | 113 return EDL_internal_string_append(str, out, (c < 128) ? c : 128); |
114 return EDL_internal_strdup(out); | |
115 } | 114 } |
116 | 115 |
117 char* EDL_internal_bool_to_string(bool value) { | 116 int EDL_internal_append_bool_to_string(EDL_internal_string* str, bool value) { |
118 return EDL_internal_strdup(value ? "TRUE" : "FALSE"); | 117 if (value) { |
118 EDL_internal_string_append(str, "TRUE", 4); | |
119 } else { | |
120 EDL_internal_string_append(str, "FALSE", 5); | |
121 } | |
119 } | 122 } |
120 | 123 |
121 char* EDL_internal_media_type_to_string(EDL_media_type_t value) { | 124 int EDL_internal_append_media_type_to_string(EDL_internal_string* str, EDL_media_type_t value) { |
122 switch (value) { | 125 switch (value) { |
123 case MEDIATYPE_AUDIO: | 126 case MEDIATYPE_AUDIO: |
124 return EDL_internal_strdup("AUDIO"); | 127 return EDL_internal_string_append(str, "AUDIO", 5); |
125 case MEDIATYPE_VIDEO: | 128 case MEDIATYPE_VIDEO: |
126 case MEDIATYPE_UNKNOWN: | 129 case MEDIATYPE_UNKNOWN: |
127 default: | 130 default: |
128 return EDL_internal_strdup("VIDEO"); | 131 return EDL_internal_string_append(str, "VIDEO", 5); |
129 } | 132 } |
130 } | 133 } |