aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-13 11:34:59 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-13 12:04:36 -0400
commit163680a58ebb7d3b7c650454a3307f62e6d87f15 (patch)
tree226908e0b4033dd59b121559a44b23beb2f5bbd2 /src/nvim/eval.c
parente346c01c314bcb8e673cef72dd761b9612ea86db (diff)
downloadrneovim-163680a58ebb7d3b7c650454a3307f62e6d87f15.tar.gz
rneovim-163680a58ebb7d3b7c650454a3307f62e6d87f15.tar.bz2
rneovim-163680a58ebb7d3b7c650454a3307f62e6d87f15.zip
vim-patch:8.0.1630: trimming white space is not that easy
Problem: Trimming white space is not that easy. Solution: Add the trim() function. (Bukn, closes vim/vim#1280) https://github.com/vim/vim/commit/295ac5ab5e840af6051bed5ec9d9acc3c73445de
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 22cb544f54..77f5360614 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -17218,6 +17218,69 @@ error:
return;
}
+// "trim({expr})" function
+static void f_trim(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ char buf1[NUMBUFLEN];
+ char buf2[NUMBUFLEN];
+ const char_u *head = (const char_u *)tv_get_string_buf_chk(&argvars[0], buf1);
+ const char_u *mask = NULL;
+ const char_u *tail;
+ const char_u *prev;
+ const char_u *p;
+ int c1;
+
+ rettv->v_type = VAR_STRING;
+ if (head == NULL) {
+ rettv->vval.v_string = NULL;
+ return;
+ }
+
+ if (argvars[1].v_type == VAR_STRING) {
+ mask = (const char_u *)tv_get_string_buf_chk(&argvars[1], buf2);
+ }
+
+ while (*head != NUL) {
+ c1 = PTR2CHAR(head);
+ if (mask == NULL) {
+ if (c1 > ' ' && c1 != 0xa0) {
+ break;
+ }
+ } else {
+ for (p = mask; *p != NUL; MB_PTR_ADV(p)) {
+ if (c1 == PTR2CHAR(p)) {
+ break;
+ }
+ }
+ if (*p == NUL) {
+ break;
+ }
+ }
+ MB_PTR_ADV(head);
+ }
+
+ for (tail = head + STRLEN(head); tail > head; tail = prev) {
+ prev = tail;
+ MB_PTR_BACK(head, prev);
+ c1 = PTR2CHAR(prev);
+ if (mask == NULL) {
+ if (c1 > ' ' && c1 != 0xa0) {
+ break;
+ }
+ } else {
+ for (p = mask; *p != NUL; MB_PTR_ADV(p)) {
+ if (c1 == PTR2CHAR(p)) {
+ break;
+ }
+ }
+ if (*p == NUL) {
+ break;
+ }
+ }
+ }
+ rettv->vval.v_string = vim_strnsave(head, (int)(tail - head));
+}
+
/*
* "type(expr)" function
*/