mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-04 22:11:07 +01:00
Add bxs_last_char_ptr()
in bxstring module
This commit is contained in:
parent
6ce0f86898
commit
c4982a15df
@ -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) {
|
||||
|
@ -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).
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user