1

use std::size_t

This commit is contained in:
2022-07-29 14:19:26 +02:00
parent 3eb0e8e1fb
commit b70024a973
2 changed files with 12 additions and 12 deletions

View File

@ -1,20 +1,20 @@
#include "user/lib/String.h"
#include "user/lib/mem/Memory.h"
unsigned int bse::strlen(const char* str) {
std::size_t 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) {
void bse::strncpy(char* destination, std::size_t 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);
std::size_t a_len = strlen(a);
std::size_t b_len = strlen(b);
if (a_len < b_len) {
return -1;
@ -23,7 +23,7 @@ int bse::strcmp(const char* a, const char* b) {
return 1;
}
for (unsigned int i = 0; i < a_len; ++i) {
for (std::size_t i = 0; i < a_len; ++i) {
if (a[i] < b[i]) {
return -1;
}

View File

@ -12,7 +12,7 @@ namespace bse {
class string {
private:
unsigned int len = 0;
std::size_t len = 0;
char* buf = nullptr;
public:
@ -25,9 +25,9 @@ namespace bse {
}
// Convert char array to string
template<unsigned int N>
template<std::size_t N>
explicit string(const array<char, N>& arr) : len(N), buf(new char[len + 1]) {
for (unsigned int i = 0; i < N; ++i) {
for (std::size_t i = 0; i < N; ++i) {
buf[i] = arr[i];
}
buf[N] = '\0';
@ -68,8 +68,8 @@ namespace bse {
delete[] buf;
}
iterator begin() { return iterator(&buf[0]); }
iterator begin() const { return iterator(&buf[0]); }
iterator begin() { return iterator(buf); }
iterator begin() const { return iterator(buf); }
iterator end() { return iterator(&buf[len]); }
iterator end() const { return iterator(&buf[len]); }
@ -91,7 +91,7 @@ namespace bse {
}
string operator+(const char* other) const {
unsigned int other_len = strlen(other);
std::size_t other_len = strlen(other);
string new_str;
new_str.len = len + other_len;
@ -140,7 +140,7 @@ namespace bse {
return strcmp(buf, other.buf) != 0;
}
unsigned int size() const {
std::size_t size() const {
return len;
}
};