1
0
forked from aniani/vim

patch 9.0.1738: Duplicate code to reverse a string

Problem:  Duplicate code to reverse a string
Solution: Move reverse_text() to strings.c and remove string_reverse().

closes: #12847

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
zeertzjq
2023-08-19 11:35:03 +02:00
committed by Christian Brabandt
parent b102728c20
commit 4dd266cb66
6 changed files with 40 additions and 85 deletions

View File

@@ -203,47 +203,6 @@ get_search_pat(void)
return mr_pattern;
}
#if defined(FEAT_RIGHTLEFT) || defined(PROTO)
/*
* Reverse text into allocated memory.
* Returns the allocated string, NULL when out of memory.
*/
char_u *
reverse_text(char_u *s)
{
unsigned len;
unsigned s_i, rev_i;
char_u *rev;
/*
* Reverse the pattern.
*/
len = (unsigned)STRLEN(s);
rev = alloc(len + 1);
if (rev == NULL)
return NULL;
rev_i = len;
for (s_i = 0; s_i < len; ++s_i)
{
if (has_mbyte)
{
int mb_len;
mb_len = (*mb_ptr2len)(s + s_i);
rev_i -= mb_len;
mch_memmove(rev + rev_i, s + s_i, mb_len);
s_i += mb_len - 1;
}
else
rev[--rev_i] = s[s_i];
}
rev[len] = NUL;
return rev;
}
#endif
void
save_re_pat(int idx, char_u *pat, int magic)
{