Repository navigation
Refactor/rewrite string templating in kotlin - #33
Merged
Merged
Conversation
This commit refactors the class from Java to Kotlin, adds support for escaping ${...} templates using backslashes \${...}, and dramatically optimizes the algorithm for longer strings.
Also refactors function to a Kotlin extension function on the String type
Also makes the algorithm more robust against malformed input from both the caller (uses quoteReplacement for templating), and the user (fixes crash when user inputs a syntactically valid template ${...} but no replacement corresponds to the provided placeholder name).
Also significantly improves docstring and variable names; fixes usage example.
…for TPAPlusPlusCommand.java's functionality, where it returns a Supplier<String> to the user, which needs to be ran on every match.
Test Results9 tests +1 9 ✅ +1 1s ⏱️ -1s Results for commit 932be06. ± Comparison against base commit 309b133. This pull request removes 3 and adds 4 tests. Note that renamed tests count towards both. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors string templating to a Kotlin extension function on String, Improves the algorithms performance (previous algorithm was a Schlemiel the painter's algorithm), and makes the algorithm more robust and well defined.
The templating function no longer throws. Also made the algorithm more robust against malformed input from the templated string and the caller.
Adds support for lambdas providing strings, and keeps Supplier support.
Adds new unit tests for new functionality like escaping.