A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/commit/9625832372e77c8a15f6ebb30df4fcbb6aba6fe8 below:

fix `nil`-index behavior for UTF-8 in `_str_*index_enc` met… · neovim/neovim@9625832 · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+18

-11

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+18

-11

lines changed Original file line number Diff line number Diff line change

@@ -97,15 +97,17 @@ end

97 97

---@param encoding string utf-8|utf-16|utf-32|nil defaults to utf-16

98 98

---@return number `encoding` index of `index` in `line`

99 99

function M._str_utfindex_enc(line, index, encoding)

100 -

if encoding ~= 'utf-8' then

101 -

local col32, col16 = vim.str_utfindex(line, index)

102 -

if encoding == 'utf-32' then

103 -

return col32

104 -

else

105 -

return col16

106 -

end

100 +

if not encoding then encoding = 'utf-16' end

101 +

if encoding == 'utf-8' then

102 +

if index then return index else return #line end

103 +

elseif encoding == 'utf-16' then

104 +

local _, col16 = vim.str_utfindex(line, index)

105 +

return col16

106 +

elseif encoding == 'utf-32' then

107 +

local col32, _ = vim.str_utfindex(line, index)

108 +

return col32

107 109

else

108 -

return index

110 +

error("Invalid encoding: " .. vim.inspect(encoding))

109 111

end

110 112

end

111 113

@@ -117,10 +119,15 @@ end

117 119

---@param encoding string utf-8|utf-16|utf-32|nil defaults to utf-16

118 120

---@return number byte (utf-8) index of `encoding` index `index` in `line`

119 121

function M._str_byteindex_enc(line, index, encoding)

120 -

if encoding ~= 'utf-8' then

121 -

return vim.str_byteindex(line, index, not encoding or encoding ~= 'utf-32')

122 +

if not encoding then encoding = 'utf-16' end

123 +

if encoding == 'utf-8' then

124 +

if index then return index else return #line end

125 +

elseif encoding == 'utf-16' then

126 +

return vim.str_byteindex(line, index, true)

127 +

elseif encoding == 'utf-32' then

128 +

return vim.str_byteindex(line, index)

122 129

else

123 -

return index

130 +

error("Invalid encoding: " .. vim.inspect(encoding))

124 131

end

125 132

end

126 133

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4