12#if !defined(_INCLUDE_MM_STRING_H_)
13#define _INCLUDE_MM_STRING_H_ 1
22#define MSTR_STACK_REGION_SIZE 16
137#define mstr_init(pstr) \
140 (pstr)->length = 0; \
141 (pstr)->buff = (pstr)->stack_region; \
142 (pstr)->cap_size = MSTR_STACK_REGION_SIZE; \
160#define mstr_create_empty(s) mstr_create(s, "")
229 MString*
str,
const char* start,
const char* end
429 const char* replace_to,
446#define mstr_iter_move_next(it) \
448 usize_t step = mstr_char_length(*((it).it)); \
450 (it).rem_leng -= 1; \
457#define mstr_iter_is_end(it) ((it).it == (it).it_end)
enum tagMStrResult mstr_result_t
结果类型
struct tagMStringMatchResult MStringMatchResult
字符串匹配信息
mstr_codepoint_of(mstr_codepoint_t *code, const mstr_char_t *ch, usize_t byte_count)
取得lead字符ch[0]所跟着的内容的unicode代码点值 如果未启用UTF-8, 该函数返回未实现错误
Definition mm_string.c:644
mstr_start_with(const MString *str, const char *prefix, usize_t prefix_cnt)
判断字符串是否以某个字串开始
Definition mm_string.c:313
mstr_contains(const MString *str, const char *pattern, usize_t pattern_cnt)
判断字符串是否含有pattern
Definition mm_string.c:342
mstr_append(MString *str, mstr_codepoint_t ch)
向字符串尾部插入一个字符
Definition mm_string.c:144
mstr_as_utf8(mstr_codepoint_t code, mstr_char_t *result, usize_t *result_len)
转换为UTF-8, 如果未启用UTF-8, 该函数返回未实现错误
Definition mm_string.c:633
struct tagMStringIter MStringIter
字符串迭代器
mstr_find(const MString *str, MStringMatchResult *f_res, usize_t begin_pos, const char *pattern, usize_t pattern_cnt)
查找子串第一次出现的位置
Definition mm_pattern.c:60
#define MSTR_STACK_REGION_SIZE
栈上分配的空间大小
Definition mm_string.h:22
tagMStringReplaceOption
字符串替换选项
Definition mm_string.h:29
@ MStringReplaceOption_EndWith
仅替换末尾位置
Definition mm_string.h:40
@ MStringReplaceOption_StartWith
仅替换开始位置
Definition mm_string.h:34
@ MStringReplaceOption_All
全部替换
Definition mm_string.h:46
mstr_replace(MString *str, MStringReplaceOption opt, const char *pattern, usize_t pattern_cnt, const char *replace_to, usize_t replace_to_cnt)
进行字符串替换(单个目标)
Definition mm_pattern.c:100
const MString * str
Definition mm_string.h:440
mstr_char_at(const MString *str, usize_t idx)
取得第idx位置的字符ch
Definition mm_string.c:358
mstr_end_with(const MString *str, const char *suffix, usize_t suffix_cnt)
判断字符串是否以某个字串结束
Definition mm_string.c:327
mstr_equal(const MString *a, const MString *b)
判断两个字符串是否相等
Definition mm_string.c:296
mstr_insert(MString *str, usize_t idx, mstr_codepoint_t ch)
从字符串中idx位置插入一个字符
Definition mm_string.c:418
mstr_concat(MString *str, const MString *other)
拼接字符串
Definition mm_string.c:195
mstr_repeat_append(MString *str, mstr_codepoint_t ch, usize_t cnt)
向字符串尾部重复插入一个字符
Definition mm_string.c:150
struct tagMString MString
字符串
mstr_char_offset_at(const MString *str, usize_t idx)
找到第idx个字符的offset
Definition mm_string.c:656
mstr_lead_char_offset(const mstr_char_t *buff, usize_t hist_len)
判断buff的lead字符偏移量(相反数, 比如偏移量是-2但是会返回2)
Definition mm_string.c:493
mstr_reserve(MString *str, usize_t new_size)
保留 sz 个char数的内存区
Definition mm_string.c:121
MSTR_EXPORT_API(void) mstr_clear(MString *str)
清空字符串
Definition mm_heap.c:147
enum tagMStringReplaceOption MStringReplaceOption
字符串替换选项
mstr_concat_cstr_slice(MString *str, const char *start, const char *end)
拼接字符串(cstr slice)
Definition mm_string.c:238
mstr_copy_from(MString *str, const MString *other)
从other复制字符串到str
Definition mm_string.c:110
mstr_move_from(MString *str, MString *other)
从other移动字符串到str
Definition mm_string.c:86
mstr_equal_cstr(const MString *a, const mstr_char_t *b, usize_t b_cnt)
判断两个字符串是否相等(cstr)
Definition mm_string.c:302
mstr_create(MString *str, const char *content)
创建字符串
Definition mm_string.c:50
mstr_remove(MString *str, mstr_codepoint_t *removed_ch, usize_t idx)
从字符串中移除idx位置的字符
Definition mm_string.c:382
mstr_concat_cstr(MString *str, const char *other)
拼接字符串(cstr)
Definition mm_string.c:220
mstr_retain(MString *str, MStringReplaceOption opt, const char *pattern, usize_t pattern_cnt)
从字符串中移除所有匹配substr的字符
Definition mm_pattern.c:114
uint32_t mstr_codepoint_t
unicode代码点
Definition mm_type.h:74
char mstr_char_t
字符
Definition mm_type.h:68
bool mstr_bool_t
布尔值
Definition mm_type.h:57
size_t usize_t
尺寸(无符号)
Definition mm_type.h:32
字符串迭代器
Definition mm_string.h:112
usize_t rem_length
剩余的长度
Definition mm_string.h:129
const char * it_end
结束位置
Definition mm_string.h:123
const char * it
位置
Definition mm_string.h:117
字符串匹配信息
Definition mm_string.h:54
usize_t begin_offset
目标位置的字符char的偏移
Definition mm_string.h:71
usize_t begin_pos
目标位置的字符索引
Definition mm_string.h:65
usize_t is_matched
是否找到了目标
Definition mm_string.h:59
字符串
Definition mm_string.h:79
char stack_region[MSTR_STACK_REGION_SIZE]
栈上分配的内存区
Definition mm_string.h:86
usize_t length
字符串长度
Definition mm_string.h:98
usize_t cap_size
已经分配了的内存大小, cap_size >= count + 1
Definition mm_string.h:104
usize_t count
字符串的字节长度
Definition mm_string.h:92
char * buff
Definition mm_string.h:80