Add bxs_last_char_ptr() in bxstring module

This commit is contained in:
Thomas Jensen 2023-08-05 21:19:27 +02:00
parent 6ce0f86898
commit c4982a15df
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
5 changed files with 41 additions and 0 deletions

View File

@ -366,6 +366,16 @@ uint32_t *bxs_first_char_ptr(bxstr_t *pString, size_t n)
uint32_t *bxs_last_char_ptr(bxstr_t *pString)
{
if (pString == NULL) {
return NULL;
}
return pString->memory + pString->first_char[pString->num_chars_visible];
}
uint32_t *bxs_unindent_ptr(bxstr_t *pString)
{
if (pString == NULL) {

View File

@ -163,6 +163,14 @@ bxstr_t *bxs_cut_front(bxstr_t *pString, size_t n);
uint32_t *bxs_first_char_ptr(bxstr_t *pString, size_t n);
/**
* Return a pointer to the NUL terminator of the given string's `memory`.
* @param pString the string to use
* @return a pointer into existing memory
*/
uint32_t *bxs_last_char_ptr(bxstr_t *pString);
/**
* Return the first character of the visible character directly following the indent (for example a letter following
* some spaces).

View File

@ -487,6 +487,26 @@ void test_bxs_cut_front_zero(void **state)
void test_bxs_last_char_ptr(void **state)
{
UNUSED(state);
uint32_t *ustr32 = u32_strconv_from_arg("abc", "ASCII");
assert_non_null(ustr32);
bxstr_t *input = bxs_from_unicode(ustr32);
assert_null(bxs_last_char_ptr(NULL));
uint32_t *actual = bxs_last_char_ptr(input);
assert_true(*actual == char_nul);
assert_int_equal(3, actual - input->memory);
BFREE(ustr32);
bxs_free(input);
}
void test_bxs_trimdup_null(void **state)
{
UNUSED(state);

View File

@ -45,6 +45,8 @@ void test_bxs_strdup(void **state);
void test_bxs_cut_front(void **state);
void test_bxs_cut_front_zero(void **state);
void test_bxs_last_char_ptr(void **state);
void test_bxs_trimdup_null(void **state);
void test_bxs_trimdup_invalid_startidx(void **state);
void test_bxs_trimdup_invalid_endidx(void **state);

View File

@ -139,6 +139,7 @@ int main(void)
cmocka_unit_test_setup(test_bxs_strdup, beforeTest),
cmocka_unit_test_setup(test_bxs_cut_front, beforeTest),
cmocka_unit_test_setup(test_bxs_cut_front_zero, beforeTest),
cmocka_unit_test_setup(test_bxs_last_char_ptr, beforeTest),
cmocka_unit_test_setup(test_bxs_trimdup_null, beforeTest),
cmocka_unit_test_setup(test_bxs_trimdup_invalid_startidx, beforeTest),
cmocka_unit_test_setup(test_bxs_trimdup_invalid_endidx, beforeTest),