game/axl_string.cpp

80 lines
1.1 KiB
C++
Raw Normal View History

2025-11-27 20:51:48 +03:00
#include "axl_string.h"
u32 axl_strlen(const i8* s)
{
2025-11-27 21:14:48 +03:00
if(s == NULL)
{
return 0;
}
2025-11-30 17:32:50 +03:00
2025-11-27 20:51:48 +03:00
u32 len = 0;
while(s[len] != '\0')
{
len++;
}
return len;
}
2025-11-27 20:58:48 +03:00
i8* axl_strcpy(i8* dst, const i8* src)
{
2025-11-27 21:14:48 +03:00
if(dst == NULL || src == NULL)
{
return dst;
}
2025-11-27 20:58:48 +03:00
i8* start = dst;
while((*(dst++) = *(src++)) != '\0');
return start;
}
2025-11-27 21:10:44 +03:00
i8* axl_strncpy(i8* dst, const i8* src, u32 n)
{
2025-11-27 21:14:48 +03:00
if(dst == NULL || src == NULL)
{
return dst;
}
2025-11-27 21:10:44 +03:00
u32 i = 0;
for(; i < n && src[i] != '\0'; i++)
{
dst[i] = src[i];
}
for(; i < n; i++)
{
dst[i] = '\0';
}
return dst;
}
2025-11-30 17:18:38 +03:00
i8* axl_strcat(i8* dst, const i8* src)
{
if(dst == NULL || src == NULL)
{
return dst;
}
return axl_strcpy(dst + axl_strlen(dst), src);
}
2025-11-30 17:32:50 +03:00
i8* axl_strncat(i8* dst, const i8* src, u32 n) //n actually means "not more than"
{
if(n == 0 || !dst || !src)
{
return dst;
}
i8* p = dst + axl_strlen(dst);
while (n-- && (*p++ = *src++)); //quick note: '\0' == 0
*p = '\0'; //in case we copied exactly n without '\0'
return dst;
}