1

implement basic dynamic string

This commit is contained in:
2022-07-24 00:07:21 +02:00
parent 65ae4e139b
commit 1c87110b70
2 changed files with 146 additions and 0 deletions

37
c_os/user/lib/String.cc Normal file
View File

@ -0,0 +1,37 @@
#include "user/lib/String.h"
#include "user/lib/Math.h"
#include "user/lib/Memory.h"
unsigned int bse::strlen(const char* str) {
const char* current = str;
while (*current != '\0') { ++current; }
return current - str;
}
void bse::strncpy(char* destination, unsigned int n, const char* source) {
memcpy<char>(destination, source, n);
}
// Only compares equal length strings
int bse::strcmp(const char* a, const char* b) {
const unsigned int a_len = strlen(a);
const unsigned int b_len = strlen(b);
if (a_len < b_len) {
return -1;
}
if (b_len < a_len) {
return 1;
}
for (unsigned int i = 0; i < a_len; ++i) {
if (a[i] < b[i]) {
return -1;
}
if (b[i] < a[i]) {
return 1;
}
}
return 0;
}