Rename string_clean in string_reset to avoid confusing _clean & _clear functions. See #97

This commit is contained in:
Patrick Pelissier committed 2021-10-28 17:27:41 +02:00
1 parent ae6b87d646
commit 9176953a8e
4 files changed
+33 -20

No files matched your search

+2 -2
View File
@@ -5212,9 +5212,9 @@ representing a C string, giving back ownership of this array to the caller.
This array will have to be freed. It can return NULL if no array
was allocated by the string.
##### void string\_clean(string\_t str)
##### void string\_reset(string\_t str)
Set the string 'str' to an empty string.
Reset the string 'str' to an empty string.
##### size\_t string\_size(const string\_t str)
+1
View File
@@ -68,4 +68,5 @@ V0.5.*: * M_INVERT is renamed into M_REVERSE to be more coherent with the REVERS
it will default to use INIT_SET instead of INIT_WITH.
==> Encapsulate the argument between () to force use of INIT_WITH.
* Remove of UPDATE operator. Use of SET for RBTREE or ADD for DICT instead.
* Make the _clean suffix for reseting the container to empty deprecated. Use new _reset suffix instead.
+19 -7
View File
@@ -222,7 +222,7 @@ string_clear_get_str(string_t v)
/* Make the string empty */
static inline void
string_clean(string_t v)
string_reset(string_t v)
{
M_STR1NG_CONTRACT (v);
m_str1ng_set_size(v, 0);
@@ -230,6 +230,12 @@ string_clean(string_t v)
M_STR1NG_CONTRACT (v);
}
static inline void M_ATTR_DEPRECATED
string_clean(string_t v)
{
string_reset(v);
}
/* Return the selected character of the string */
static inline char
string_get_char(const string_t v, size_t index)
@@ -1337,7 +1343,7 @@ string_in_str(string_t v, FILE *f)
M_ASSERT (f != NULL);
int c = fgetc(f);
if (c != '"') return false;
string_clean(v);
string_reset(v);
c = fgetc(f);
while (c != '"' && c != EOF) {
if (M_UNLIKELY (c == '\\')) {
@@ -1389,7 +1395,7 @@ string_parse_str(string_t v, const char str[], const char **endptr)
bool success = false;
int c = *str++;
if (c != '"') goto exit;
string_clean(v);
string_reset(v);
c = *str++;
while (c != '"' && c != 0) {
if (M_UNLIKELY (c == '\\')) {
@@ -1734,7 +1740,7 @@ string_utf8_p(string_t str)
const string_t str) \
{ \
bool init_done = false; \
string_clean (dst); \
string_reset (dst); \
for M_EACH(item, cont, oplist) { \
if (init_done) { \
string_cat(dst, str); \
@@ -1823,7 +1829,7 @@ namespace m_lib {
(INIT(string_init),INIT_SET(string_init_set), SET(string_set), \
INIT_WITH(M_STRING_INIT_WITH), \
INIT_MOVE(string_init_move), MOVE(string_move), \
SWAP(string_swap), CLEAN(string_clean), \
SWAP(string_swap), CLEAN(string_reset), \
EMPTY_P(string_empty_p), \
CLEAR(string_clear), HASH(string_hash), EQUAL(string_equal_p), \
CMP(string_cmp), TYPE(string_t), \
@@ -1887,7 +1893,7 @@ namespace m_lib {
/* Set a string to a set strings (or const char * if C1)) */
#define string_sets(a, ...) \
(string_clean(a), M_MAP2_C(string_cat, a, __VA_ARGS__) )
(string_reset(a), M_MAP2_C(string_cat, a, __VA_ARGS__) )
/* Macro encapsulation for C11 */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
@@ -2039,12 +2045,18 @@ namespace m_lib {
} \
\
static inline void \
M_C(name, _clean)(bounded_t s) \
M_C(name, _reset)(bounded_t s) \
{ \
M_BOUNDED_STR1NG_CONTRACT(s, max_size); \
s->s[0] = 0; \
} \
\
static inline void M_ATTR_DEPRECATED \
M_C(name, _clean)(bounded_t s) \
{ \
M_C(name, _reset)(s); \
} \
\
static inline size_t \
M_C(name, _size)(const bounded_t s) \
{ \
+11 -11
View File
@@ -50,7 +50,7 @@ static void test_utf8_basic(void)
assert (m_str1ng_utf8_length(buf) == 1);
assert (m_str1ng_utf8_valid_str_p(buf) == true);
/* Higher level access */
string_clean(s);
string_reset(s);
string_push_u(s, i);
assert(string_utf8_p(s) == true);
assert(string_length_u(s) == 1);
@@ -59,13 +59,13 @@ static void test_utf8_basic(void)
/* Reject out of range value */
for (string_unicode_t i = 0x110000; i < 0x1fffff; i++) {
string_clean(s);
string_reset(s);
string_push_u(s, i);
assert(string_utf8_p(s) == false);
}
/* Test rejection of surrogate halves */
for (string_unicode_t i = 0xd800; i <= 0xdfff; i++) {
string_clean(s);
string_reset(s);
string_push_u(s, i);
assert(string_utf8_p(s) == false);
}
@@ -108,7 +108,7 @@ static void test_utf8_it(void)
assert(tab2[i] == *string_cref(it2));
}
assert (i == 19);
string_clean(s);
string_reset(s);
for(i = 0 ; i < 19; i++)
string_push_u(s, tab2[i]);
assert (string_equal_str_p(s, "H€llo René Chaînôr¬"));
@@ -137,17 +137,17 @@ static void test0(void)
assert (string_get_char(s1, 1) == 'E');
string_set_char(s1, 1, 'e');
string_clean(s1);
string_reset(s1);
assert (string_size(s1) == 0);
assert (string_empty_p(s1) == true);
assert (strcmp(string_get_cstr(s1), "") == 0);
string_set_strn(s1, "Hello, world!", 14);
assert (strcmp(string_get_cstr(s1), "Hello, world!") == 0);
string_clean(s1);
string_reset(s1);
string_set_strn(s1, "Hello, world!", 5);
assert (strcmp(string_get_cstr(s1), "Hello") == 0);
string_clean(s1);
string_reset(s1);
string_set_str (s1, "Hello");
string_set_str (s2, "Hello, world!");
@@ -158,7 +158,7 @@ static void test0(void)
assert (string_size(s1) == 22);
assert (strcmp(string_get_cstr(s1), "Hello beautiful world!") == 0);
string_clean(s1);
string_reset(s1);
string_set_n (s2, s1, 0, 5);
assert(string_empty_p(s2));
@@ -624,7 +624,7 @@ static void test0(void)
h = string_search_pbrk(s1, "oO");
assert(h==4);
string_clean(s1);
string_reset(s1);
string_reserve(s1, 0);
string_cat_printf(s1, "%d little %s.", 42, "suns");
string_set_str(s2, "42 little suns.");
@@ -654,7 +654,7 @@ static void test_bounded1(void)
assert (string16_cmp_str(s, "Hello") == 0);
assert (string16_get_char(s, 1) == 'e');
assert (strcmp(string16_get_cstr(s), "Hello") == 0);
string16_clean(s);
string16_reset(s);
assert (string16_empty_p(s));
assert (string16_size(s) == 0);
string16_set_str(s, "Hello, world! How do you do?");
@@ -683,7 +683,7 @@ static void test_bounded1(void)
string16_set_strn(s, "Hello, world! How do you do?", 15);
string16_init_set(d, s);
string16_clean(s);
string16_reset(s);
assert (string16_equal_str_p(d, "Hello, world! H"));
string16_clear(d);