Added strdisplaywidth() function.
diff --git a/src/charset.c b/src/charset.c
index ef162e4..87ad303 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -839,14 +839,25 @@
#endif
/*
- * return the number of characters the string 's' will take on the screen,
- * taking into account the size of a tab
+ * Return the number of characters the string 's' will take on the screen,
+ * taking into account the size of a tab.
*/
int
linetabsize(s)
char_u *s;
{
- colnr_T col = 0;
+ return linetabsize_col(0, s);
+}
+
+/*
+ * Like linetabsize(), but starting at column "startcol".
+ */
+ int
+linetabsize_col(startcol, s)
+ int startcol;
+ char_u *s;
+{
+ colnr_T col = startcol;
while (*s != NUL)
col += lbr_chartabsize_adv(&s, col);
diff --git a/src/eval.c b/src/eval.c
index a344cd2..3a0d85c 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -710,6 +710,7 @@
static void f_strpart __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strridx __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strtrans __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_strdisplaywidth __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strwidth __ARGS((typval_T *argvars, typval_T *rettv));
static void f_submatch __ARGS((typval_T *argvars, typval_T *rettv));
static void f_substitute __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7859,6 +7860,7 @@
#endif
{"str2nr", 1, 2, f_str2nr},
{"strchars", 1, 1, f_strchars},
+ {"strdisplaywidth", 1, 2, f_strdisplaywidth},
#ifdef HAVE_STRFTIME
{"strftime", 1, 2, f_strftime},
#endif
@@ -16805,6 +16807,23 @@
}
/*
+ * "strdisplaywidth()" function
+ */
+ static void
+f_strdisplaywidth(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv;
+{
+ char_u *s = get_tv_string(&argvars[0]);
+ int col = 0;
+
+ if (argvars[1].v_type != VAR_UNKNOWN)
+ col = get_tv_number(&argvars[1]);
+
+ rettv->vval.v_number = (varnumber_T)(linetabsize_col(col, s));
+}
+
+/*
* "strwidth()" function
*/
static void
diff --git a/src/proto/charset.pro b/src/proto/charset.pro
index 1e6a708..472f1cd 100644
--- a/src/proto/charset.pro
+++ b/src/proto/charset.pro
@@ -15,6 +15,7 @@
int vim_strnsize __ARGS((char_u *s, int len));
int chartabsize __ARGS((char_u *p, colnr_T col));
int linetabsize __ARGS((char_u *s));
+int linetabsize_col __ARGS((int startcol, char_u *s));
int win_linetabsize __ARGS((win_T *wp, char_u *p, colnr_T len));
int vim_isIDc __ARGS((int c));
int vim_iswordc __ARGS((int c));