From 1807b785ffa86f6e49ff68a0c5689e867a423f76 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Wed, 7 Sep 2022 11:17:43 +0530 Subject: buffer_utils: Validate rgb_hex too | trie: Add exact param to longest_prefix --- lua/colorizer/buffer_utils.lua | 2 +- lua/colorizer/trie.lua | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/colorizer/buffer_utils.lua b/lua/colorizer/buffer_utils.lua index d0b0faa..498804b 100644 --- a/lua/colorizer/buffer_utils.lua +++ b/lua/colorizer/buffer_utils.lua @@ -161,7 +161,7 @@ function highlight_buffer(buf, ns, lines, line_start, options, options_local) local i = 1 while i < #line do local length, rgb_hex = loop_parse_fn(line, i) - if length then + if length and rgb_hex then local name = create_highlight(rgb_hex, mode) local d = data[current_linenum] or {} table.insert(d, { name = name, range = { i - 1, i + length - 1 } }) diff --git a/lua/colorizer/trie.lua b/lua/colorizer/trie.lua index 1f7a0de..a7d9994 100644 --- a/lua/colorizer/trie.lua +++ b/lua/colorizer/trie.lua @@ -52,7 +52,7 @@ end local total_char = 255 local INDEX_LOOKUP_TABLE = ffi.new("uint8_t[?]", total_char) -local CHAR_LOOKUP_TABLE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +local CHAR_LOOKUP_TABLE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-" do local b = string.byte local extra_char = { @@ -111,7 +111,7 @@ local function trie_search(trie, value, start) return node.is_leaf end -local function trie_longest_prefix(trie, value, start) +local function trie_longest_prefix(trie, value, start, exact) if trie == nil then return false end @@ -138,7 +138,9 @@ local function trie_longest_prefix(trie, value, start) -- Avoid a copy if the whole string is a match. if start == 1 and last_i == #value then return value - else + end + + if not exact then return value:sub(start, last_i) end end -- cgit v1.2.3-70-g09d2