Change project structure;
Added new c# binding;
This commit is contained in:
105
native/header/Common/String.h
Normal file
105
native/header/Common/String.h
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
inline char* string_copy(const char* source)
|
||||
{
|
||||
if (source == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = strlen(source) + 1;
|
||||
char* copy = (char*)malloc(len);
|
||||
if (copy == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy_s(copy, len, source);
|
||||
return copy;
|
||||
}
|
||||
|
||||
inline bool is_absolute_path(const char* path)
|
||||
{
|
||||
if (path == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// 1) Drive-letter paths: "C:\…", "D:/…"
|
||||
if (isalpha((unsigned char)path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2) UNC paths: "\\server\share\…"
|
||||
if (path[0] == '\\' && path[1] == '\\')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
// POSIX: anything starting with '/'
|
||||
return path[0] == '/';
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void get_path_directory(const char* path, char* out, size_t out_size)
|
||||
{
|
||||
if (path == NULL || out == NULL || out_size == 0)
|
||||
{
|
||||
if (out && out_size > 0)
|
||||
{
|
||||
out[0] = '\0'; // ensure output is empty on invalid input
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const char* last_slash = strrchr(path, '/');
|
||||
|
||||
if (last_slash == NULL)
|
||||
{
|
||||
if (out_size > 0)
|
||||
{
|
||||
out[0] = '\0';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
size_t dir_len = (size_t)(last_slash - path + 1);
|
||||
|
||||
if (dir_len >= out_size)
|
||||
{
|
||||
dir_len = out_size - 1;
|
||||
}
|
||||
|
||||
memcpy(out, path, dir_len);
|
||||
out[dir_len - 1] = '/';
|
||||
out[dir_len] = '\0';
|
||||
}
|
||||
|
||||
inline void string_join(const char* a, const char* b, char* out, size_t out_size)
|
||||
{
|
||||
if (a == NULL || b == NULL || out == NULL || out_size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t a_len = strlen(a);
|
||||
size_t b_len = strlen(b);
|
||||
|
||||
if (a_len + b_len + 1 >= out_size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy_s(out, out_size, a);
|
||||
strcat_s(out, out_size, b);
|
||||
}
|
||||
|
||||
#endif // STRING_H
|
||||
Reference in New Issue
Block a user