Skip to content

Instantly share code, notes, and snippets.

View Perthys's full-sized avatar
🙉
Troll Face

Perth Perthys

🙉
Troll Face
View GitHub Profile
@Kampfkarren
Kampfkarren / escapeRichText.lua
Created November 14, 2024 18:13
Decently optimized function for escaping rich text in Roblox. 18% faster than a naive gsub implementation in a small pessimistic case, and 53% faster in the hot case of text with no bad characters. CC0
local ESCAPES: { [string]: string? } = {
["&"] = "&",
["<"] = "&lt;",
[">"] = "&gt;",
['"'] = "&quot;",
["'"] = "&apos;",
}
local function escapeRichText(text: string): string
local start, finish = 1, 1