aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/strings.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-19 17:44:19 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-08-19 18:05:46 +0800
commit4c7df98e4eeed20f8a9c461729935b79743d7752 (patch)
treedd49a0e4c1490d1eb660b6321d108d3924f9de62 /src/nvim/strings.c
parentd7ae9ae3e52362da33902c31ecccc79c49d3866e (diff)
downloadrneovim-4c7df98e4eeed20f8a9c461729935b79743d7752.tar.gz
rneovim-4c7df98e4eeed20f8a9c461729935b79743d7752.tar.bz2
rneovim-4c7df98e4eeed20f8a9c461729935b79743d7752.zip
vim-patch:9.0.1515: reverse() does not work for a String
Problem: reverse() does not work for a String. Solution: Implement reverse() for a String. (Yegappan Lakshmanan, closes vim/vim#12179) https://github.com/vim/vim/commit/03ff1c2dde7f15eca5c9baa6dafbda9b49bedc3b 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: vim/vim#12847 https://github.com/vim/vim/commit/4dd266cb66d901cf5324f09405cfea3f004bd29f Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r--src/nvim/strings.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index cfc7738ad7..ec770de4a0 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -2168,20 +2168,17 @@ int kv_do_printf(StringBuilder *str, const char *fmt, ...)
///
/// @return the allocated string.
char *reverse_text(char *s)
- FUNC_ATTR_NONNULL_RET
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
- // Reverse the pattern.
size_t len = strlen(s);
char *rev = xmalloc(len + 1);
- size_t rev_i = len;
- for (size_t s_i = 0; s_i < len; s_i++) {
+ for (size_t s_i = 0, rev_i = len; s_i < len; s_i++) {
const int mb_len = utfc_ptr2len(s + s_i);
rev_i -= (size_t)mb_len;
memmove(rev + rev_i, s + s_i, (size_t)mb_len);
s_i += (size_t)mb_len - 1;
}
rev[len] = NUL;
-
return rev;
}