feat(core): 添加字符串长度计算函数并优化数据结构定义
- 在 `core_mem.h` 中新增 `smcc_strlen` 函数,用于计算字符串长度 - 调整 `VEC` 宏定义参数,移除冗余的 name 参数,增强结构体声明一致性 - 修改 `cstring_from_cstr` 返回值字段顺序,保持代码风格统一 - 在 `libcore.h` 中增加日志相关宏定义的保护判断,防止重复定义冲突
This commit is contained in:
@@ -17,6 +17,15 @@ static inline u32 smcc_strhash32(const char *s) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
static inline usize smcc_strlen(const char *str) {
|
||||
usize len = 0;
|
||||
while (*str) {
|
||||
len++;
|
||||
str++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static inline int smcc_strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && *s2 && *s1 == *s2) {
|
||||
s1++;
|
||||
|
||||
@@ -36,7 +36,7 @@ static inline cstring_t cstring_from_cstr(const char *s) {
|
||||
smcc_memcpy(data, s, len);
|
||||
data[len] = '\0';
|
||||
|
||||
return (cstring_t){.data = data, .size = len + 1, .cap = len + 1};
|
||||
return (cstring_t){.size = len + 1, .cap = len + 1, .data = data};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,22 +17,24 @@
|
||||
/** @defgroup vec_struct 数据结构定义 */
|
||||
|
||||
/**
|
||||
* @def VEC(name, type)
|
||||
* @def VEC(type)
|
||||
* @brief 声明向量结构体
|
||||
* @param name 结构体变量名
|
||||
* @param type 存储的数据类型
|
||||
*
|
||||
* 生成包含size/cap/data三个字段的结构体定义:
|
||||
* - size: 当前元素数量
|
||||
* - cap: 数组容量
|
||||
* - data: 存储数组指针
|
||||
* @example
|
||||
* VEC(char) string; <=> char[dynamic_array] string;
|
||||
* struct people { VEC(char) name; int age; VEC(struct people) children; };
|
||||
*/
|
||||
#define VEC(name, type) \
|
||||
#define VEC(type) \
|
||||
struct { \
|
||||
usize size; \
|
||||
usize cap; \
|
||||
type *data; \
|
||||
} name
|
||||
}
|
||||
|
||||
/** @defgroup vec_operations 动态数组操作宏 */
|
||||
|
||||
|
||||
@@ -6,9 +6,15 @@
|
||||
#include <core_mem.h>
|
||||
|
||||
#define __SMCC_LOG_NO_STD_IMPL__
|
||||
#ifndef log_snprintf
|
||||
#define log_snprintf smcc_snprintf
|
||||
#endif
|
||||
#ifndef log_printf
|
||||
#define log_printf smcc_eprintf
|
||||
#endif
|
||||
#ifndef log_exit
|
||||
#define log_exit smcc_exit
|
||||
#endif
|
||||
#include <log.h>
|
||||
|
||||
#define _SMCC_STR(str) #str
|
||||
|
||||
1994
runtime/libcore/include/utest/acutest.h
Normal file
1994
runtime/libcore/include/utest/acutest.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user