aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/charset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/charset.c')
-rw-r--r--src/nvim/charset.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 20bd364c7e..c611d4cfd6 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1051,7 +1051,7 @@ char *skiptowhite(const char *p)
///
/// @return Pointer to the next whitespace character.
char *skiptowhite_esc(const char *p)
- FUNC_ATTR_PURE
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
{
while (*p != ' ' && *p != '\t' && *p != NUL) {
if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) {
@@ -1457,10 +1457,20 @@ bool rem_backslash(const char *str)
/// @param p
void backslash_halve(char *p)
{
- for (; *p; p++) {
- if (rem_backslash(p)) {
- STRMOVE(p, p + 1);
+ for (; *p && !rem_backslash(p); p++) {}
+ if (*p != NUL) {
+ char *dst = p;
+ goto start;
+ while (*p != NUL) {
+ if (rem_backslash(p)) {
+start:
+ *dst++ = *(p + 1);
+ p += 2;
+ } else {
+ *dst++ = *p++;
+ }
}
+ *dst = '\0';
}
}
@@ -1472,8 +1482,16 @@ void backslash_halve(char *p)
char *backslash_halve_save(const char *p)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
- // TODO(philix): simplify and improve backslash_halve_save algorithm
- char *res = xstrdup(p);
- backslash_halve(res);
+ char *res = xmalloc(strlen(p) + 1);
+ char *dst = res;
+ while (*p != NUL) {
+ if (rem_backslash(p)) {
+ *dst++ = *(p + 1);
+ p += 2;
+ } else {
+ *dst++ = *p++;
+ }
+ }
+ *dst = '\0';
return res;
}