aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkianonymus <anonymus.aki@gmail.com>2022-09-07 11:17:43 +0530
committerAkianonymus <anonymus.aki@gmail.com>2022-09-07 11:17:43 +0530
commit1807b785ffa86f6e49ff68a0c5689e867a423f76 (patch)
tree386c507445c48ec27e9ad6605c5b8130739b8bf6
parentutils: Improve percent_or_hex function (diff)
buffer_utils: Validate rgb_hex too | trie: Add exact param to longest_prefix
-rw-r--r--lua/colorizer/buffer_utils.lua2
-rw-r--r--lua/colorizer/trie.lua8
2 files changed, 6 insertions, 4 deletions
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