aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-07-01 15:29:20 +0200
committerGitHub <noreply@github.com>2018-07-01 15:29:20 +0200
commitef9ef75a7b1e29002745d596e31a1d5ecff1be89 (patch)
tree11026785224fb64c4a524f87d66a1ef71ec30db7
parent22d95e462ec32e1b6c28b310e80c9c001edc0fe1 (diff)
parent3e4a058b01db779e087eaf97826cee545de2a923 (diff)
downloadrneovim-ef9ef75a7b1e29002745d596e31a1d5ecff1be89.tar.gz
rneovim-ef9ef75a7b1e29002745d596e31a1d5ecff1be89.tar.bz2
rneovim-ef9ef75a7b1e29002745d596e31a1d5ecff1be89.zip
Merge #8635 from janlazo/vim-8.0.0252
-rw-r--r--src/nvim/charset.c23
-rw-r--r--src/nvim/mbyte.c21
-rw-r--r--test/unit/mbyte_spec.lua10
3 files changed, 35 insertions, 19 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 99ced6c8c2..ab20996df7 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -826,7 +826,7 @@ bool vim_isIDc(int c)
/// For multi-byte characters mb_get_class() is used (builtin rules).
///
/// @param c character to check
-bool vim_iswordc(int c)
+bool vim_iswordc(const int c)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
return vim_iswordc_buf(c, curbuf);
@@ -842,7 +842,7 @@ bool vim_iswordc_tab(const int c, const uint64_t *const chartab)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
return (c >= 0x100
- ? (utf_class(c) >= 2)
+ ? (utf_class_tab(c, chartab) >= 2)
: (c > 0 && GET_CHARTAB_TAB(chartab, c) != 0));
}
@@ -852,7 +852,7 @@ bool vim_iswordc_tab(const int c, const uint64_t *const chartab)
///
/// @param c character to check
/// @param buf buffer whose keywords to use
-bool vim_iswordc_buf(int c, buf_T *buf)
+bool vim_iswordc_buf(const int c, buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2)
{
return vim_iswordc_tab(c, buf->b_chartab);
@@ -863,13 +863,10 @@ bool vim_iswordc_buf(int c, buf_T *buf)
/// @param p pointer to the multi-byte character
///
/// @return true if "p" points to a keyword character.
-bool vim_iswordp(char_u *p)
+bool vim_iswordp(const char_u *const p)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
- if (MB_BYTE2LEN(*p) > 1) {
- return mb_get_class(p) >= 2;
- }
- return GET_CHARTAB(curbuf, *p) != 0;
+ return vim_iswordp_buf(p, curbuf);
}
/// Just like vim_iswordc_buf() but uses a pointer to the (multi-byte)
@@ -879,13 +876,15 @@ bool vim_iswordp(char_u *p)
/// @param buf buffer whose keywords to use
///
/// @return true if "p" points to a keyword character.
-bool vim_iswordp_buf(char_u *p, buf_T *buf)
+bool vim_iswordp_buf(const char_u *const p, buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
- if (MB_BYTE2LEN(*p) > 1) {
- return mb_get_class(p) >= 2;
+ int c = *p;
+
+ if (MB_BYTE2LEN(c) > 1) {
+ c = utf_ptr2char(p);
}
- return GET_CHARTAB(buf, *p) != 0;
+ return vim_iswordc_buf(c, buf);
}
/// Check that "c" is a valid file-name character.
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index ea538fb4fc..65a1a8246c 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -428,7 +428,7 @@ int mb_get_class_tab(const char_u *p, const uint64_t *const chartab)
}
return 1;
}
- return utf_class(utf_ptr2char(p));
+ return utf_class_tab(utf_ptr2char(p), chartab);
}
/*
@@ -1039,7 +1039,12 @@ bool utf_printable(int c)
* 1: punctuation
* 2 or bigger: some class of word character.
*/
-int utf_class(int c)
+int utf_class(const int c)
+{
+ return utf_class_tab(c, curbuf->b_chartab);
+}
+
+int utf_class_tab(const int c, const uint64_t *const chartab)
{
/* sorted list of non-overlapping intervals */
static struct clinterval {
@@ -1122,11 +1127,13 @@ int utf_class(int c)
/* First quick check for Latin1 characters, use 'iskeyword'. */
if (c < 0x100) {
- if (c == ' ' || c == '\t' || c == NUL || c == 0xa0)
- return 0; /* blank */
- if (vim_iswordc(c))
- return 2; /* word character */
- return 1; /* punctuation */
+ if (c == ' ' || c == '\t' || c == NUL || c == 0xa0) {
+ return 0; // blank
+ }
+ if (vim_iswordc_tab(c, chartab)) {
+ return 2; // word character
+ }
+ return 1; // punctuation
}
/* binary search in table */
diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua
index 6feef4e601..1e7e9fd6e6 100644
--- a/test/unit/mbyte_spec.lua
+++ b/test/unit/mbyte_spec.lua
@@ -5,6 +5,7 @@ local ffi = helpers.ffi
local eq = helpers.eq
local mbyte = helpers.cimport("./src/nvim/mbyte.h")
+local charset = helpers.cimport('./src/nvim/charset.h')
describe('mbyte', function()
@@ -42,6 +43,15 @@ describe('mbyte', function()
-- Sequences with more than four bytes
end)
+ itp('utf_char2bytes', function()
+ local char_p = ffi.typeof('char[?]')
+ for c = 0, 0xFFFF do
+ local p = char_p(4, 0)
+ mbyte.utf_char2bytes(c, p)
+ eq(c, mbyte.utf_ptr2char(p))
+ eq(charset.vim_iswordc(c), charset.vim_iswordp(p))
+ end
+ end)
describe('utfc_ptr2char_len', function()