Skip to content

Commit

Permalink
Improved support for replacements with symbols in them
Browse files Browse the repository at this point in the history
Now, only word-only substitutions will not be replaced when part of a
larger word.
  • Loading branch information
varkor committed Feb 27, 2016
1 parent 9bbc36b commit 7b1e41a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions battle/scripts/objects/unique/Textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ const Textbox = FunctionObject.new({
text = "" + text.trim();
var replacements = Settings._("text replacements").data;
forevery(Settings._("text replacements"), function (replacement, original) {
var symbolReplacement = /^\W*$/.test(original);
if (symbolReplacement) {
var wordReplacement = /^\w+$/.test(original);
// Word replacements are not allowed to occur if they are part of a larger word — otherwise, matches inside a word may be replaced
if (!wordReplacement) {
text = text.replace(new RegExp("(\\\\)?(" + original + ")", "g"), function (match, escaped, text) {
return escaped ? original : replacement;
});
Expand Down

0 comments on commit 7b1e41a

Please sign in to comment.