Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lua/wire/gates/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,36 @@
end
}

GateActions["string_replace_index"] = {
name = "Replace Index",
description = "Replaces the character at a specific index with a new character or string.",
inputs = { "String", "Character", "Index" },
inputtypes = { "STRING", "STRING", "NORMAL" },
outputtypes = { "STRING" },
output = function(gate, str, char, index)
str = str or ""
char = char or ""
index = index or 1

-- Boundary check: if index is out of range, return original string
if index < 1 or index > #str then return str end

if (#str - 1 + #char) > MAX_LEN then return false end

-- Split string at index and insert the new character
local left = string.sub(str, 1, index - 1)
local right = string.sub(str, index + 1)

Check warning on line 443 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
return left .. char .. right
end,
label = function(Out, str, char, index)
return string.format("replace(%s[%s] = %q) = %q",

Check warning on line 447 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
tostring(str),

Check warning on line 448 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
tostring(index),

Check warning on line 449 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
tostring(char),

Check warning on line 450 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
tostring(Out)
)
end
}

GateActions()
Loading