Renemed all variables to fit into a namespace

Basically, all Toy varaibles, functions, etc. are prepended with "Toy_",
and macros are prepended with "TOY_". This is to reduce namespace
pollution, which was an issue pointed out to be - blame @GyroVorbis.

I've also bumped the minor version number - theoretically I should bump
the major number, but I'm not quite ready for 1.0 yet.
This commit is contained in:
2023-01-25 12:52:07 +00:00
parent 047ccc5f16
commit 2e2bee4fa3
55 changed files with 4837 additions and 4707 deletions

View File

@@ -1,4 +1,4 @@
#include "refstring.h"
#include "toy_refstring.h"
#include <string.h>
#include <assert.h>
@@ -6,27 +6,27 @@
//test variable sizes based on platform (safety)
#define STATIC_ASSERT(test_for_true) static_assert((test_for_true), "(" #test_for_true ") failed")
STATIC_ASSERT(sizeof(RefString) == 12);
STATIC_ASSERT(sizeof(Toy_RefString) == 12);
STATIC_ASSERT(sizeof(int) == 4);
STATIC_ASSERT(sizeof(char) == 1);
//memory allocation
static RefStringAllocatorFn allocate;
static Toy_RefStringAllocatorFn allocate;
void setRefStringAllocatorFn(RefStringAllocatorFn allocator) {
void Toy_setRefStringAllocatorFn(Toy_RefStringAllocatorFn allocator) {
allocate = allocator;
}
//API
RefString* createRefString(char* cstring) {
Toy_RefString* Toy_createRefString(char* cstring) {
int length = strnlen(cstring, 4096);
return createRefStringLength(cstring, length);
return Toy_createRefStringLength(cstring, length);
}
RefString* createRefStringLength(char* cstring, int length) {
Toy_RefString* Toy_createRefStringLength(char* cstring, int length) {
//allocate the memory area (including metadata space)
RefString* refString = (RefString*)allocate(NULL, 0, sizeof(int) * 2 + sizeof(char) * length + 1);
Toy_RefString* refString = (Toy_RefString*)allocate(NULL, 0, sizeof(int) * 2 + sizeof(char) * length + 1);
//set the data
refString->refcount = 1;
@@ -38,7 +38,7 @@ RefString* createRefStringLength(char* cstring, int length) {
return refString;
}
void deleteRefString(RefString* refString) {
void Toy_deleteRefString(Toy_RefString* refString) {
//decrement, then check
refString->refcount--;
if (refString->refcount <= 0) {
@@ -46,30 +46,30 @@ void deleteRefString(RefString* refString) {
}
}
int countRefString(RefString* refString) {
int Toy_countRefString(Toy_RefString* refString) {
return refString->refcount;
}
int lengthRefString(RefString* refString) {
int Toy_lengthRefString(Toy_RefString* refString) {
return refString->length;
}
RefString* copyRefString(RefString* refString) {
Toy_RefString* Toy_copyRefString(Toy_RefString* refString) {
//Cheaty McCheater Face
refString->refcount++;
return refString;
}
RefString* deepCopyRefString(RefString* refString) {
Toy_RefString* Toy_deepCopyRefString(Toy_RefString* refString) {
//create a new string, with a new refcount
return createRefStringLength(refString->data, refString->length);
return Toy_createRefStringLength(refString->data, refString->length);
}
char* toCString(RefString* refString) {
char* Toy_toCString(Toy_RefString* refString) {
return refString->data;
}
bool equalsRefString(RefString* lhs, RefString* rhs) {
bool Toy_equalsRefString(Toy_RefString* lhs, Toy_RefString* rhs) {
//same pointer
if (lhs == rhs) {
return true;
@@ -84,7 +84,7 @@ bool equalsRefString(RefString* lhs, RefString* rhs) {
return strncmp(lhs->data, rhs->data, lhs->length) == 0;
}
bool equalsRefStringCString(RefString* lhs, char* cstring) {
bool Toy_equalsRefStringCString(Toy_RefString* lhs, char* cstring) {
//get the rhs length
int length = strnlen(cstring, 4096);