Files
Aurora.3/code/__defines/regex.dm
skull132 d07b0f4be6 Optimizing REGEX, fixes #686 (#677)
Less vars instanced every time someone speaks, no more REGEX being compiled every time someone speaks.

Should lower the cost of these procs.
2016-08-06 00:48:51 +03:00

38 lines
1.3 KiB
Plaintext

// Global REGEX datums for regular use without recompiling
// The lazy URL finder. Lazy in that it matches the bare minimum
// Replicates BYOND's own URL parser in functionality.
var/global/regex/url_find_lazy
// REGEX datums used for process_chat_markup.
var/global/regex/markup_bold
var/global/regex/markup_italics
var/global/regex/markup_strike
var/global/regex/markup_underline
// Global list for mark-up REGEX datums.
// Initialized in the hook, to avoid passing by null value.
var/global/list/markup_regex = list()
// Global list for mark-up REGEX tag collection.
var/global/list/markup_tags = list("/" = list("<i>", "</i>"),
"*" = list("<b>", "</b>"),
"~" = list("<strike>", "</strike>"),
"_" = list("<u>", "</u>"))
/hook/startup/proc/initialize_global_regex()
url_find_lazy = new("(https?:\\/\\/\[^\\s\]*)", "g")
markup_bold = new("(\\*)(\[^\\*\]*)(\\*)", "g")
markup_italics = new("(\\/)(\[^\\/\]*)(\\/)", "g")
markup_strike = new("(\\~)(\[^\\~\]*)(\\~)", "g")
markup_underline = new("(\\_)(\[^\\_\]*)(\\_)", "g")
// List needs to be initialized here, due to DM mixing and matching pass-by-value and -reference as it chooses.
markup_regex = list("/" = markup_italics,
"*" = markup_bold,
"~" = markup_strike,
"_" = markup_underline)
return 1