Add string_set_char function
This commit is contained in:
1 parent
39eeb3aec7
commit
61f8dcdbae
3 files changed
+18
-1
No files matched your search
@@ -5030,7 +5030,12 @@ reallocation of the underlying array of char has to be performed.
|
|||||||
|
|
||||||
##### char string\_get\_char(const string\_t v, size\_t index)
|
##### char string\_get\_char(const string\_t v, size\_t index)
|
||||||
|
|
||||||
Return the byte 'index' of the string 'v'.
|
Return the byte at position 'index' of the string 'v'.
|
||||||
|
'index' shall be within the allowed range of bytes of the string.
|
||||||
|
|
||||||
|
##### void string\_set\_char(string\_t v, size\_t index, const char c)
|
||||||
|
|
||||||
|
Set the byte at position 'index' of the string 'v' to 'c'.
|
||||||
'index' shall be within the allowed range of bytes of the string.
|
'index' shall be within the allowed range of bytes of the string.
|
||||||
|
|
||||||
##### bool string\_empty\_p(const string\_t v)
|
##### bool string\_empty\_p(const string\_t v)
|
||||||
|
|||||||
@@ -239,6 +239,15 @@ string_get_char(const string_t v, size_t index)
|
|||||||
return string_get_cstr(v)[index];
|
return string_get_cstr(v)[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set the selected character of the string */
|
||||||
|
static inline void
|
||||||
|
string_set_char(string_t v, size_t index, const char c)
|
||||||
|
{
|
||||||
|
M_STR1NG_CONTRACT (v);
|
||||||
|
M_ASSERT_INDEX(index, string_size(v));
|
||||||
|
m_str1ng_get_cstr(v)[index] = c;
|
||||||
|
}
|
||||||
|
|
||||||
/* Test if the string is empty or not */
|
/* Test if the string is empty or not */
|
||||||
static inline bool
|
static inline bool
|
||||||
string_empty_p(const string_t v)
|
string_empty_p(const string_t v)
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ static void test0(void)
|
|||||||
string_set_str (s1, "Hello, world!");
|
string_set_str (s1, "Hello, world!");
|
||||||
assert (string_size(s1) == 13);
|
assert (string_size(s1) == 13);
|
||||||
assert (string_get_char(s1, 1) == 'e');
|
assert (string_get_char(s1, 1) == 'e');
|
||||||
|
string_set_char(s1, 1, 'E');
|
||||||
|
assert (string_get_char(s1, 1) == 'E');
|
||||||
|
string_set_char(s1, 1, 'e');
|
||||||
|
|
||||||
string_clean(s1);
|
string_clean(s1);
|
||||||
assert (string_size(s1) == 0);
|
assert (string_size(s1) == 0);
|
||||||
|
|||||||
Reference in new issue
Block a user