12#if !defined(_INCLUDE_MM_STRING_HPP_)
13#define _INCLUDE_MM_STRING_HPP_ 1
42template <std::
size_t N>
44 const mstr_char_t (&u8char)[N], std::size_t idx, uint32_t mask
48 return static_cast<uint32_t
>(
49 static_cast<uint8_t
>(u8char[idx]) & mask
53template <std::
size_t N>
54constexpr typename std::enable_if<N == 3, unicode_t>::type
unicode_char(
62template <std::
size_t N>
63constexpr typename std::enable_if<N == 4, unicode_t>::type
unicode_char(
72template <std::
size_t N>
73constexpr typename std::enable_if<N == 5, unicode_t>::type
unicode_char(
88template <std::
size_t N>
89constexpr typename std::enable_if<N <= 2, unicode_t>::type
unicode_char(
121 using value_type = unicode_t;
122 using pointer =
const value_type*;
123 using reference =
const value_type&;
124 using difference_type =
iptr_t;
125 using iterator_category = std::bidirectional_iterator_tag;
130 : beg(_beg), it(_buff), rem_length(_leng)
134 string_iterator(string_iterator&&) =
default;
135 string_iterator(
const string_iterator&) =
default;
136 string_iterator& operator=(string_iterator&&) =
default;
137 string_iterator& operator=(
const string_iterator&) =
default;
139 reference operator*()
const
143 usize_t len = mstr_char_length(*it);
146#if _MSTR_USE_CPP_EXCEPTION
160 string_iterator& operator++()
162 if (rem_length > 0) {
163 usize_t len = mstr_char_length(*it);
168#if _MSTR_USE_CPP_EXCEPTION
177 string_iterator operator++(
int)
179 string_iterator tmp = *
this;
184 string_iterator& operator--()
195#if _MSTR_USE_CPP_EXCEPTION
204 string_iterator operator--(
int)
206 string_iterator tmp = *
this;
211 bool operator==(
const string_iterator& rhs)
const noexcept
216 bool operator!=(
const string_iterator& rhs)
const noexcept
226template <
typename T>
struct fixed_wrapper
237template <
typename T>
using wrapper_t =
typename T::value_t;
263 std::reverse_iterator<const_iterator>;
353 template <std::
size_t N>
363 template <std::
size_t N>
377 return !(*
this ==
str);
384 template <std::
size_t N>
387 return !(*
this ==
str);
394 template <std::
size_t N>
399 return !(pthis ==
str);
422 template <std::
size_t N>
443 const char* buff = prefix->this_obj.buff;
444 usize_t buff_len = prefix->this_obj.count;
452 template <std::
size_t N>
473 const char* buff = suffix->this_obj.buff;
474 usize_t buff_len = suffix->this_obj.count;
529 template <std::
size_t N>
592 auto ch = std::get<0>(rhs);
593 auto cnt = std::get<1>(rhs);
669 template <std::
size_t N>
706 patt_len == 0 ? strlen(patt) : patt_len
715 return static_cast<isize_t>(-1);
725 template <std::
size_t N>
730 return find(patt, begin_pos, N);
762 patt_cnt == 0 ? strlen(patt) : patt_cnt
780 template <std::
size_t N>
821 patt_cnt == 0 ? strlen(patt) : patt_cnt
838 template <std::
size_t N>
844 return retain(patt, mode, N);
859 return retain(patt.this_obj.buff, mode, patt.this_obj.count);
931#if _MSTR_USE_CPP_EXCEPTION
947 template <
typename T>
949 std::is_signed<T>::value &&
950 std::numeric_limits<T>::is_integer &&
951 sizeof(T) <=
sizeof(int32_t),
960 &
this_obj,
static_cast<int32_t
>(value), index, sign
976 template <
typename T>
978 std::is_unsigned<T>::value &&
979 std::numeric_limits<T>::is_integer &&
980 sizeof(T) <=
sizeof(uint32_t),
981 result<unit_t, error_code_t>>
987 &
this_obj,
static_cast<uint32_t
>(value), index
1007 template <
typename T>
1009 std::is_signed<details::wrapper_t<T>>::value &&
1011 result<unit_t, error_code_t>>
1038 template <
typename T>
1040 std::is_unsigned<details::wrapper_t<T>>::value &&
1063 template <
typename T>
1065 std::is_signed<T>::value &&
1066 std::numeric_limits<T>::is_integer &&
1093 template <
typename T>
1095 std::is_unsigned<T>::value &&
1096 std::numeric_limits<T>::is_integer &&
1097 sizeof(T) <=
sizeof(uint32_t),
1098 result<string, error_code_t>>
1105 &ret_str.this_obj,
static_cast<uint32_t
>(value), index
1125 template <
typename T>
1127 std::is_signed<details::wrapper_t<T>>::value &&
1129 result<string, error_code_t>>
1139 static_cast<int32_t>(value.value),
1160 template <
typename T>
1162 std::is_unsigned<details::wrapper_t<T>>::value &&
1185 template <std::
size_t N>
1205 template <std::size_t N,
typename...
Args>
1223 template <
typename...
Args>
1230 &
str.raw_object_mut(),
1233 std::forward<Args&&>(
args)...
1270template <
typename T>
1273 return details::fixed_wrapper<T>{value};
表示存在错误
Definition mm_result.hpp:400
结果类
Definition mm_result.hpp:415
字符串类
Definition mm_string.hpp:246
bool contains(const string &patt) const noexcept
判断字符串是否包括字符串B (string对象)
Definition mm_string.hpp:682
const value_t * const_pointer
Definition mm_string.hpp:256
bool start_with(const value_t *prefix) const noexcept
判断字符串是否以另一个字串开始(c_str)
Definition mm_string.hpp:432
static result< string, error_code_t > format(const value_t(&fmt_str)[N], Args &&... args)
进行格式化(字符串数组)
Definition mm_string.hpp:1206
MString & raw_object_mut() noexcept
返回raw object(可变的)
Definition mm_string.hpp:1257
static constexpr unicode_t unicode_char(const value_t(&u8char)[N])
取得Unicode代码点的字符
Definition mm_string.hpp:1186
bool start_with(const string *prefix) const noexcept
判断字符串是否以另一个字串开始(MString)
Definition mm_string.hpp:441
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition mm_string.hpp:263
result< usize_t, error_code_t > find_or_err(const mtfmt::string &patt, usize_t begin_pos=0) const noexcept
查找字符串 (mtfmt::string)
Definition mm_string.hpp:793
string & operator+=(unicode_t rhs)
字符串拼接 (字符)
Definition mm_string.hpp:576
friend bool operator==(const value_t(&str)[N], const string &pthis) noexcept
相等(cstr left)
Definition mm_string.hpp:364
bool end_with(const value_t *suffix) const noexcept
判断字符串是否以另一个字串结束(c_str)
Definition mm_string.hpp:462
const value_t * c_str() noexcept
取得C风格字符串
Definition mm_string.hpp:867
result< unit_t, mstr_result_t > concat(const string &rhs) noexcept
放入一个字符串
Definition mm_string.hpp:514
const MString & raw_object() const noexcept
返回raw object
Definition mm_string.hpp:1248
string & operator+=(const value_t(&rhs)[N])
字符串拼接 (self, c_str)
Definition mm_string.hpp:562
value_t & reference
Definition mm_string.hpp:257
const_iterator begin() const noexcept
取得迭代器起始 (const)
Definition mm_string.hpp:885
result< unit_t, mstr_result_t > push(unicode_t uni_char) noexcept
放入一个字符
Definition mm_string.hpp:482
friend bool operator!=(const value_t(&str)[N], const string &pthis) noexcept
不等(cstr left)
Definition mm_string.hpp:395
result< unit_t, mstr_result_t > reserve(usize_t new_size) noexcept
保留足够的内存
Definition mm_string.hpp:407
bool end_with(const value_t(&suffix)[N]) const noexcept
判断字符串是否以另一个字串结束(c_str buffer)
Definition mm_string.hpp:453
string & operator=(const string &str) noexcept
copy
Definition mm_string.hpp:315
unicode_t operator[](std::size_t i) const
取得第n个unicode字符
Definition mm_string.hpp:927
details::string_iterator const_iterator
Definition mm_string.hpp:261
std::string as_std_string()
取得std::string
Definition mm_string.hpp:876
ptrdiff_t difference_type
Definition mm_string.hpp:260
void clear() noexcept
取得C风格字符串
Definition mm_string.hpp:603
string & operator+=(const string &rhs)
字符串拼接 (self)
Definition mm_string.hpp:548
string(const value_t *c_str)
从C字符串创建
Definition mm_string.hpp:281
string(const string &str) noexcept
从self创建
Definition mm_string.hpp:301
details::enable_if_t< std::is_unsigned< details::wrapper_t< T > >::value &&details::is_instance_of< details::fixed_wrapper, T >::value, result< unit_t, error_code_t > > append_from(const T &value, uint32_t p) noexcept
对无符号量化值进行格式化, 并填充到this中
Definition mm_string.hpp:1043
result< unit_t, mstr_result_t > concat(const value_t(&rhs)[N]) noexcept
放入一个字符串 (c_str)
Definition mm_string.hpp:530
result< unit_t, error_code_t > insert(usize_t idx, unicode_t ch) noexcept
在idx位置插入字符
Definition mm_string.hpp:621
bool operator==(const value_t(&str)[N]) const noexcept
相等(cstr)
Definition mm_string.hpp:354
result< usize_t, error_code_t > find_or_err(const value_t(&patt)[N], usize_t begin_pos=0) const noexcept
查找字符串 (c_str array)
Definition mm_string.hpp:781
result< unit_t, error_code_t > retain(const mtfmt::string &patt, MStringReplaceOption mode=MStringReplaceOption_All) noexcept
剔除掉patt字符(string object)
Definition mm_string.hpp:854
result< unicode_t, error_code_t > remove(usize_t idx) noexcept
移除idx位置的字符, 并返回被移除的字符
Definition mm_string.hpp:638
result< unit_t, error_code_t > retain(const value_t(&patt)[N], MStringReplaceOption mode=MStringReplaceOption_All) noexcept
剔除掉patt字符(c str array)
Definition mm_string.hpp:839
value_t * pointer
Definition mm_string.hpp:255
details::enable_if_t< std::is_signed< T >::value &&std::numeric_limits< T >::is_integer &&sizeof(T)<=sizeof(int32_t), result< unit_t, error_code_t > > append_from(const T &value, MStrFmtIntIndex index=MStrFmtIntIndex_Dec, MStrFmtSignDisplay sign=MStrFmtSignDisplay_NegOnly) noexcept { error_code_t res=mstr_fmt_itoa(&this_obj, static_cast< int32_t >(value), index, sign);if(MSTR_SUCC(res)) { return unit_t{};} else { return res;} } template< typename T > details::enable_if_t< std::is_unsigned< T >::value &&std::numeric_limits< T >::is_integer &&sizeof(T)<=sizeof(uint32_t), result< unit_t, error_code_t > > append_from(const T &value, MStrFmtIntIndex index=MStrFmtIntIndex_Dec) noexcept { error_code_t res=mstr_fmt_utoa(&this_obj, static_cast< uint32_t >(value), index);if(MSTR_SUCC(res)) { return unit_t{};} else { return res;} } template< typename T > details::enable_if_t< std::is_signed< details::wrapper_t< T > >::value &&details::is_instance_of< details::fixed_wrapper, T >::value, result< unit_t, error_code_t > > append_from(const T &value, int32_t p, MStrFmtSignDisplay sign=MStrFmtSignDisplay_NegOnly) noexcept
对有符号整数值进行格式化, 并填充到this中
Definition mm_string.hpp:1012
void reverse() noexcept
翻转字符串
Definition mm_string.hpp:612
string() noexcept
创建空的字符串
Definition mm_string.hpp:271
~string()
Definition mm_string.hpp:307
const_reverse_iterator rend() const noexcept
取得反向迭代器结束 (const)
Definition mm_string.hpp:916
result< unit_t, error_code_t > retain(const value_t *patt, MStringReplaceOption mode=MStringReplaceOption_All, usize_t patt_cnt=0) noexcept
剔除掉patt字符
Definition mm_string.hpp:810
size_t size_type
Definition mm_string.hpp:259
usize_t length() const noexcept
取得字符串长度
Definition mm_string.hpp:326
bool start_with(const value_t(&prefix)[N]) const noexcept
判断字符串是否以另一个字串开始(c_str buffer)
Definition mm_string.hpp:423
mstr_char_t value_t
Definition mm_string.hpp:254
static result< string, error_code_t > format_variable(const string::value_t *fmt_str, Args &&... args)
进行格式化(动态的格式化串)
Definition mm_string.hpp:1224
static details::enable_if_t< std::is_unsigned< details::wrapper_t< T > >::value &&details::is_instance_of< details::fixed_wrapper, T >::value, result< string, error_code_t > > from(const T &value, uint32_t p) noexcept
对无符号量化值进行格式化并返回
Definition mm_string.hpp:1165
bool end_with(const string *suffix) const noexcept
判断字符串是否以另一个字串结束(MString)
Definition mm_string.hpp:471
bool operator!=(const value_t(&str)[N]) const noexcept
不等(cstr)
Definition mm_string.hpp:385
result< isize_t, error_code_t > find(const value_t *patt, usize_t begin_pos=0, usize_t patt_len=0) const noexcept
查找字符串 (c_str)
Definition mm_string.hpp:695
string & operator+=(const repeat_char_t &rhs)
字符串拼接 (重复n个)
Definition mm_string.hpp:590
bool operator!=(const string &str) const noexcept
不等
Definition mm_string.hpp:375
const_reverse_iterator rbegin() const noexcept
取得反向迭代器起始 (const)
Definition mm_string.hpp:907
result< usize_t, error_code_t > find_or_err(const value_t *patt, usize_t begin_pos=0, usize_t patt_cnt=0) const noexcept
查找字符串 (c_str)
Definition mm_string.hpp:751
bool operator==(const string &str) const noexcept
相等
Definition mm_string.hpp:344
const value_t & const_reference
Definition mm_string.hpp:258
std::tuple< unicode_t, std::size_t > repeat_char_t
Definition mm_string.hpp:265
usize_t byte_count() const noexcept
取得字符串占用的字节数
Definition mm_string.hpp:335
MString this_obj
c对象
Definition mm_string.hpp:251
result< unit_t, mstr_result_t > push(unicode_t ch, std::size_t repeat) noexcept
重复放入一个字符
Definition mm_string.hpp:497
result< isize_t, error_code_t > find(const mtfmt::string &patt, usize_t begin_pos=0) const noexcept
查找字符串 (mtfmt::string)
Definition mm_string.hpp:739
const_iterator end() const noexcept
取得迭代器结束 (const)
Definition mm_string.hpp:896
string(const std::string &str)
从std::string创建
Definition mm_string.hpp:291
bool contains(const value_t(&patt)[N]) const noexcept
判断字符串是否包括字符串B (cstr数组)
Definition mm_string.hpp:670
bool contains(const value_t *patt) const noexcept
判断字符串是否包括字符串B
Definition mm_string.hpp:657
static static details::enable_if_t< std::is_signed< T >::value &&std::numeric_limits< T >::is_integer &&sizeof(T)<=sizeof(int32_t), result< string, error_code_t > > from(const T &value, MStrFmtIntIndex index=MStrFmtIntIndex_Dec, MStrFmtSignDisplay sign=MStrFmtSignDisplay_NegOnly) noexcept { string ret_str;error_code_t res=mstr_fmt_itoa(&ret_str.this_obj, static_cast< int32_t >(value), index, sign);if(MSTR_SUCC(res)) { return ret_str;} else { return res;} } template< typename T > static details::enable_if_t< std::is_unsigned< T >::value &&std::numeric_limits< T >::is_integer &&sizeof(T)<=sizeof(uint32_t), result< string, error_code_t > > from(const T &value, MStrFmtIntIndex index=MStrFmtIntIndex_Dec) noexcept { string ret_str;error_code_t res=mstr_fmt_utoa(&ret_str.this_obj, static_cast< uint32_t >(value), index);if(MSTR_SUCC(res)) { return ret_str;} else { return res;} } template< typename T > details::enable_if_t< std::is_signed< details::wrapper_t< T > >::value &&details::is_instance_of< details::fixed_wrapper, T >::value, result< string, error_code_t > > from(const T &value, int32_t p, MStrFmtSignDisplay sign=MStrFmtSignDisplay_NegOnly) noexcept
对有符号整数值进行格式化并返回
Definition mm_string.hpp:1130
result< isize_t, error_code_t > find(const value_t(&patt)[N], usize_t begin_pos=0) const noexcept
查找字符串 (c_str array)
Definition mm_string.hpp:726
#define mstr_cause_exception(code)
Definition mm_cfg.h:395
mstr_format(MString *res_str, const char *fmt, usize_t fmt_place,...)
格式化字符串
Definition mm_fmt.c:66
@ MStrFmtIntIndex_Dec
转换为十进制字符串
Definition mm_fmt.h:54
enum tagMStrFmtIntIndex MStrFmtIntIndex
转换整数时采用的进制
mstr_fmt_itoa(MString *str, int32_t value, MStrFmtIntIndex index, MStrFmtSignDisplay sign)
将有符号整数转换为字符串
Definition mm_into.c:34
mstr_fmt_uqtoa(MString *res_str, uint32_t value, uint32_t quat)
将无符号量化值转换为字符串
Definition mm_into.c:115
mstr_fmt_iqtoa(MString *res_str, int32_t value, uint32_t quat, MStrFmtSignDisplay sign)
将有符号量化值转换为字符串
Definition mm_into.c:96
mstr_fmt_utoa(MString *res_str, uint32_t value, MStrFmtIntIndex index)
将无符号整数转换为字符串
Definition mm_into.c:51
@ MStrFmtSignDisplay_NegOnly
仅在值小于0时显示符号
Definition mm_parser.h:157
enum tagMStrFmtSignDisplay MStrFmtSignDisplay
格式化值时候的符号显示方式
mstr_find(const MString *str, MStringMatchResult *f_res, usize_t begin_pos, const char *pattern, usize_t pattern_cnt)
查找子串第一次出现的位置
Definition mm_pattern.c:60
mstr_retain(MString *str, MStringReplaceOption opt, const char *patt, usize_t patt_cnt)
从字符串中移除所有匹配substr的字符
Definition mm_pattern.c:114
enum tagMStrResult mstr_result_t
结果类型
#define MSTR_SUCC(s)
Definition mm_result.h:83
@ MStr_Err_UnicodeEncodingError
Definition mm_result.h:27
@ MStr_Err_IteratorOutOfBound
Definition mm_result.h:35
@ MStr_Err_IndexOutOfBound
Definition mm_result.h:31
@ MStr_Err_NoSubstrFound
Definition mm_result.h:33
#define MSTR_FAILED(s)
Definition mm_result.h:86
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_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
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_copy_from(MString *str, const MString *other)
从other复制字符串到str
Definition mm_string.c:110
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
@ MStringReplaceOption_All
全部替换
Definition mm_string.h:46
const MString * str
Definition mm_string.h:440
#define mstr_init(pstr)
初始化一个空的字符串
Definition mm_string.h:137
enum tagMStringReplaceOption MStringReplaceOption
字符串替换选项
intptr_t isize_t
尺寸(有符号, sizeof(isize_t) == sizeof(usize_t) == sizeof(iptr_t))
Definition mm_type.h:39
uint32_t mstr_codepoint_t
unicode代码点
Definition mm_type.h:74
char mstr_char_t
字符
Definition mm_type.h:68
intptr_t iptr_t
Definition mm_type.h:39
size_t usize_t
尺寸(无符号)
Definition mm_type.h:32
constexpr uint32_t utf8_meta(const mstr_char_t(&u8char)[N], std::size_t idx, uint32_t mask)
Definition mm_string.hpp:43
constexpr std::enable_if< N==3, unicode_t >::type unicode_char(const mstr_char_t(&u8char)[N])
Definition mm_string.hpp:54
typename std::enable_if< cond, T >::type enable_if_t
enable_if_t, 和cpp14一样(但是这里是cpp11呜呜呜)
Definition mm_type.hpp:205
Definition mm_parser.hpp:17
details::fixed_wrapper< T > fixed_value(const T &value)
标记该值是一个定点数
Definition mm_string.hpp:1271
mstr_codepoint_t unicode_t
unicode字符
Definition mm_string.hpp:37
details::unit_t unit_t
表示单位类型
Definition mm_result.hpp:388
mstr_result_t error_code_t
返回值的错误结果
Definition mm_result.hpp:394
判断Ti是否为模板Tt的实例化
Definition mm_type.hpp:150
static constexpr bool value
Definition mm_type.hpp:151
单位类型
Definition mm_type.hpp:29
字符串匹配信息
Definition mm_string.h:54
usize_t begin_pos
目标位置的字符索引
Definition mm_string.h:65
usize_t is_matched
是否找到了目标
Definition mm_string.h:59
字符串
Definition mm_string.h:79
usize_t length
字符串长度
Definition mm_string.h:98
usize_t count
字符串的字节长度
Definition mm_string.h:92
char * buff
Definition mm_string.h:80