Skip to content

Refactor/rewrite string templating in kotlin - #33

Merged
SuperRicky14 merged 9 commits into
mainfrom
refactor/rewrite-string-templating-in-kotlin
Jan 25, 2026
Merged

SuperRicky14 merged 9 commits into
mainfrom
refactor/rewrite-string-templating-in-kotlin

Conversation

@SuperRicky14

Copy link
Copy Markdown
Owner

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.

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.
@github-actions

Copy link
Copy Markdown

Test Results

9 tests  +1   9 ✅ +1   1s ⏱️ -1s
1 suites ±0   0 💤 ±0 
1 files   ±0   0 ❌ ±0 

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.
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testMissingPlaceholderValue()
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testNullFormatString()
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testNullValues()
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testEscapingPlaceholderBackslashRemoval()
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testEscapingPlaceholders()
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testMissingPlaceholderReplacement()
net.superricky.tpaplusplus.config.formatters.MsgFmtTest ‑ testNoPlaceholders()

@SuperRicky14
SuperRicky14 merged commit 671f6ce into main Jan 25, 2026
3 checks passed
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.

1 participant