-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.lua
More file actions
50 lines (44 loc) · 1.18 KB
/
utils.lua
File metadata and controls
50 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Utils = {}
---@param this_string string the string
---@param split string sub to split at
function Utils.Splitter(this_string, split)
local new_word = {}
local index = string.find(this_string, split)
if index == nil then
new_word[1] = this_string
new_word[2] = this_string
return new_word
end
local split_index = index
local split_start = ""
for x = 0, split_index - 1, 1 do
split_start = split_start .. string.sub(this_string, x, x)
end
new_word[1] = split_start
local split_end = ""
for x = split_index + #split, #this_string, 1 do
split_end = split_end .. string.sub(this_string, x, x)
end
new_word[2] = split_end
return new_word
end
function Utils.StringContains(str, find)
str = string.upper(str)
find = string.upper(find)
local i, _ = string.find(str, find)
-- core.log(string.format("what does this return? %s",tostring(i)))
return i
end
function Utils.Split(str, delimiter)
local result = {}
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end
function Utils.Distance(x1, y1, z1, x2, y2, z2)
local dx = x2 - x1
local dy = y2 - y1
local dz = z2 - z1
return math.sqrt(dx * dx + dy * dy + dz * dz)
end