Skip to content

Improve string.replace implementation#549

Merged
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
ark120202:improve-string-replace
May 2, 2019
Merged

Improve string.replace implementation#549
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
ark120202:improve-string-replace

Conversation

@ark120202
Copy link
Copy Markdown
Contributor

Breaking change.

Makes string.replace behave closer to ES:

  • Escape patterns from searchValue and replaceValue (as a string)
  • Support for function replacer
  • Limit replacement count to 1

Limitations wiki page has to be updated with a recommendation to use string.gsub if there is a need for extra functionality.

Optimization ideas for future:

  • If searchValue or replaceValue is a string literal it may be escaped during transpilation
  • If searchValue is a regexp literal has no magic and has only g flag it may be compiled to gsub without a limit

@Perryvw Perryvw merged commit cb2c479 into TypeScriptToLua:master May 2, 2019
ark120202 added a commit to ark120202/TypeScriptToLua that referenced this pull request May 2, 2019
@ark120202 ark120202 deleted the improve-string-replace branch November 26, 2019 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants