MtFmt 1.0.0
MtFmt is a format library on embed. system and wrote by pure C.
载入中...
搜索中...
未找到
mm_string.h
浏览该文件的文档.
1// SPDX-License-Identifier: LGPL-3.0
12#if !defined(_INCLUDE_MM_STRING_H_)
13#define _INCLUDE_MM_STRING_H_ 1
14#include "mm_cfg.h"
15#include "mm_result.h"
16#include "mm_type.h"
17
22#define MSTR_STACK_REGION_SIZE 16
23
48
73
106
111typedef struct tagMStringIter
112{
117 const char* it;
118
123 const char* it_end;
124
131
137#define mstr_init(pstr) \
138 do { \
139 (pstr)->count = 0; \
140 (pstr)->length = 0; \
141 (pstr)->buff = (pstr)->stack_region; \
142 (pstr)->cap_size = MSTR_STACK_REGION_SIZE; \
143 } while (0)
144
154mstr_create(MString* str, const char* content);
155
160#define mstr_create_empty(s) mstr_create(s, "")
161
171MSTR_EXPORT_API(void)
173
184mstr_copy_from(MString* str, const MString* other);
185
194mstr_reserve(MString* str, usize_t new_size);
195
205mstr_concat(MString* str, const MString* other);
206
216mstr_concat_cstr(MString* str, const char* other);
217
229 MString* str, const char* start, const char* end
230);
231
241
252
258MSTR_EXPORT_API(void) mstr_clear(MString* str);
259
266MSTR_EXPORT_API(void) mstr_reverse_self(MString* str);
267
277MSTR_EXPORT_API(void) mstr_reverse_only(MString* str);
278
285MSTR_EXPORT_API(const char*) mstr_c_str(MString* str);
286
296mstr_equal(const MString* a, const MString* b);
297
308mstr_equal_cstr(const MString* a, const mstr_char_t* b, usize_t b_cnt);
309
319 const MString* str, const char* prefix, usize_t prefix_cnt
320);
321
331 const MString* str, const char* suffix, usize_t suffix_cnt
332);
333
346 const MString* str, const char* pattern, usize_t pattern_cnt
347);
348
356mstr_char_at(const MString* str, usize_t idx);
357
367
377
390 const MString* str,
391 MStringMatchResult* f_res,
392 usize_t begin_pos,
393 const char* pattern,
394 usize_t pattern_cnt
395);
396
407 MString* str,
409 const char* pattern,
410 usize_t pattern_cnt
411);
412
425 MString* str,
427 const char* pattern,
428 usize_t pattern_cnt,
429 const char* replace_to,
430 usize_t replace_to_cnt
431);
432
440MSTR_EXPORT_API(void) mstr_iter(MStringIter* it, const MString* str);
441
446#define mstr_iter_move_next(it) \
447 do { \
448 usize_t step = mstr_char_length(*((it).it)); \
449 (it).it += step; \
450 (it).rem_leng -= 1; \
451 } while (0)
452
457#define mstr_iter_is_end(it) ((it).it == (it).it_end)
458
466MSTR_EXPORT_API(usize_t) mstr_char_length(char lead);
467
480mstr_lead_char_offset(const mstr_char_t* buff, usize_t hist_len);
481
492 mstr_codepoint_t code, mstr_char_t* result, usize_t* result_len
493);
494
506 mstr_codepoint_t* code, const mstr_char_t* ch, usize_t byte_count
507);
508
522
528MSTR_EXPORT_API(void) mstr_free(MString* str);
529
530#endif // _INCLUDE_MM_STRING_H_
配置选项
结果类型
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
type alias和type def
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