aboutsummaryrefslogtreecommitdiff
path: root/src/un_strings.c
diff options
context:
space:
mode:
authorbonmas14 <bonmas14@gmail.com>2025-08-03 19:24:03 +0000
committerbonmas14 <bonmas14@gmail.com>2025-08-03 19:24:03 +0000
commit471b539bdbf658ff7924b7500f89fd237df8be9b (patch)
treea6a0b1d8a7a37ebe288cd7e1accf9b16dee203aa /src/un_strings.c
parenta4d37d76512c293b12aab1f77961f96d572557b7 (diff)
downloadungrateful-471b539bdbf658ff7924b7500f89fd237df8be9b.tar.gz
ungrateful-471b539bdbf658ff7924b7500f89fd237df8be9b.zip
Reordering of stuff + plans
Diffstat (limited to 'src/un_strings.c')
-rw-r--r--src/un_strings.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/un_strings.c b/src/un_strings.c
index 7d73d0b..ff74c39 100644
--- a/src/un_strings.c
+++ b/src/un_strings.c
@@ -32,8 +32,6 @@ String un_string_copy(String source, Allocator alloc) {
u8 *mem;
String result;
- assert(source.size >= 0);
-
mem = (u8*)un_memory_alloc(source.size, alloc);
un_memory_copy(mem, source.data, (u64)source.size);
@@ -64,8 +62,6 @@ s32 un_string_compare(String left, String right) {
String un_string_concat(String left, String right, Allocator alloc) {
String result = { 0 };
- assert(left.size >= 0 && right.size >= 0);
-
if (left.size == right.size && left.size == 0) {
return result;
}
@@ -89,7 +85,7 @@ String un_string_concat(String left, String right, Allocator alloc) {
}
String un_string_swap(String input, u8 from, u8 to, Allocator alloc) {
- s64 i;
+ u64 i;
String output;
output = un_string_copy(input, alloc);
@@ -107,7 +103,7 @@ String un_string_swap(String input, u8 from, u8 to, Allocator alloc) {
List un_string_split(String input, String pattern, Allocator alloc) {
List splits;
String string;
- s64 i, start;
+ u64 i, start;
u64 matches, size;
u8 *buffer;
@@ -196,18 +192,17 @@ String un_string_join(List string_list, String separator, Allocator alloc) {
return un_string_copy(cont, alloc);
}
-String un_string_substring(String input, s64 start, s64 max_size) {
+String un_string_substring(String input, u64 start, u64 max_size) {
String slice;
- assert(start >= 0);
assert(max_size > 0);
- slice.size = UN_MIN(max_size, (input.size - (s64)max_size));
+ slice.size = UN_MIN(max_size, (input.size - (u64)max_size));
slice.data = input.data + start;
if (start > (input.size - max_size)) {
- slice.size = UN_MIN(max_size, (input.size - (s64)max_size));
+ slice.size = UN_MIN(max_size, (input.size - (u64)max_size));
} else {
slice.size = max_size;
}
@@ -217,7 +212,7 @@ String un_string_substring(String input, s64 start, s64 max_size) {
}
s64 un_string_index_of(String input, u8 value, u64 skip_count) {
- s64 i;
+ u64 i;
for (i = 0; i < input.size; i++) {
if (input.data[i] != value) {
@@ -233,12 +228,12 @@ s64 un_string_index_of(String input, u8 value, u64 skip_count) {
return -1;
}
-extern s64 un_string_index_of_last(String input, u8 value) {
+s64 un_string_index_of_last(String input, u8 value) {
s64 i, index;
index = -1;
- for (i = 0; i < input.size; i++) {
+ for (i = 0; i < (s64)input.size; i++) {
if (input.data[i] == value) index = i;
}
@@ -319,16 +314,23 @@ static String format_s64(s64 value) {
String un_string_format(Allocator alloc, String buffer, ...) {
va_list args;
- String s;
+ String result;
+ va_start(args, buffer);
+ result = un_string_vformat(alloc, buffer, args);
+ va_end(args);
+ return result;
+}
+
+String un_string_vformat(Allocator alloc, String buffer, va_list args) {
List output;
- s64 i, j;
+ String s;
+ u64 i, j;
u32 b;
Allocator talloc = un_allocator_get_temporary();
+ // @todo @bug: this would fail on realloc, because we need to realloc
output = un_list_create(UN_KB(1), sizeof(u8), talloc);
- va_start(args, buffer);
-
for (i = 0; i < buffer.size; i++) {
if (buffer.data[i] != '%') {
un_list_append(&output, buffer.data + i);
@@ -374,8 +376,6 @@ String un_string_format(Allocator alloc, String buffer, ...) {
}
}
- va_end(args);
-
s.size = (s64)output.count;
s.data = output.data;