You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lua/neo-tree/utils.lua
+157Lines changed: 157 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -823,4 +823,161 @@ M.unique = function(list)
823
823
returnresult
824
824
end
825
825
826
+
---Splits string by sep on first occurrence. brace_expand_split("a,b,c", ",") -> { "a", "b,c" }. nil if separator not found.
827
+
---@paramsstring: input string
828
+
---@paramseparatorstring: separator
829
+
---@returnstring, string | nil
830
+
localbrace_expand_split=function(s, separator)
831
+
localpos=1
832
+
localdepth=0
833
+
whilepos<=s:len() do
834
+
localc=s:sub(pos, pos)
835
+
ifc=='\\' then
836
+
pos=pos+1
837
+
elseifc==separatoranddepth==0then
838
+
returns:sub(1, pos-1), s:sub(pos+1)
839
+
elseifc=='{' then
840
+
depth=depth+1
841
+
elseifc=='}' then
842
+
ifdepth>0then
843
+
depth=depth-1
844
+
end
845
+
end
846
+
pos=pos+1
847
+
end
848
+
returns, nil
849
+
end
850
+
851
+
---Perform brace expansion on a string and return the sequence of the results
852
+
---@paramsstring?: input string which is inside braces, if nil return { "" }
853
+
---@returnstring[] | nil: list of strings each representing the individual expanded strings
854
+
localbrace_expand_contents=function(s)
855
+
ifs==nilthen-- no closing brace "}"
856
+
return { "" }
857
+
elseifs=="" then-- brace with no content "{}"
858
+
return { "{}" }
859
+
end
860
+
861
+
---Generate a sequence from from..to..step and apply `func`
862
+
---@paramfromstring | number: initial value
863
+
---@paramtostring | number: end value
864
+
---@paramstepstring | number: step value
865
+
---@paramfuncfun(i: number): string | nil function(string | number) -> string | nil: function applied to all values in sequence. if return is nil, the value will be ignored.
866
+
---@returnstring[]: generated string list
867
+
---@private
868
+
localfunctionresolve_sequence(from, to, step, func)
869
+
localf, t=tonumber(from), tonumber(to)
870
+
localst= (t<fand-1or1) *math.abs(tonumber(step) or1) -- reverse (negative) step if t < f
871
+
---@typestring[]
872
+
localitems= {}
873
+
fori=f, t, stdo
874
+
localr=func(i)
875
+
ifr~=nilthen
876
+
table.insert(items, r)
877
+
end
878
+
end
879
+
returnitems
880
+
end
881
+
882
+
---If pattern matches the input string `s`, apply an expansion by `resolve_func`
883
+
---@parampatternstring: regex to match on `s`
884
+
---@paramresolve_funcfun(from: string, to: string, step: string): string[]
885
+
---@returnstring[] | nil: expanded sequence or nil if failed
0 commit comments