-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions: add Replace, and RegexpReplace from Terraform #45
Conversation
Codecov Report
@@ Coverage Diff @@
## master #45 +/- ##
==========================================
- Coverage 76.08% 70.19% -5.90%
==========================================
Files 77 79 +2
Lines 6172 7096 +924
==========================================
+ Hits 4696 4981 +285
- Misses 1060 1672 +612
- Partials 416 443 +27
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay here, @azr! Thanks for working on these.
I do like the separation of plain string replace vs. regexp replace, and would like to run with it. However, I'd prefer to see the function Replace
be the ReplaceAll
behavior you implemented here, and to omit the "replace with count" function for now. I say this because replacing all instances seems to be the common case and replacing a specific number seems to be a more marginal thing. I'd rather omit the specific number version until there's a clear use-case for it, and have the "all" versions have the more concise name reflecting that they are (I presume) what most people will want to use.
TLDR, I'm suggesting the following:
- Remove
Replace
as currently implemented. - Rename
ReplaceAll
to justReplace
. - Rename
RegexpReplaceAll
to justRegexpReplace
.
What do you think? 🤔
Hey @apparentlymart ! No worries, thanks for reviewing, I had kept the names of the go standard library, because, naming is hard ! I agree with you that from a HCL/CTY standing point it makes more sense to have a replace call replace everything. In programming people sorts of often have the performances in mind. Changing this. |
…expReplace + tests
Here we go, I also added some tests ! |
|
||
// We search/replace using a regexp if the string is surrounded | ||
// in forward slashes. | ||
if len(substr) > 1 && substr[0] == '/' && substr[len(substr)-1] == '/' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm sorry I didn't catch this on the initial read yesterday)
Now that we have a separate function name as a more "normal" way to select between plain string or regex-based replacement, I'd prefer to drop this special case and just expect the whole string to be a valid regular expression. That will then be consistent with the behavior of the existing Regex
and RegexAll
functions already in this package. I think if leading and trailing slashes are present then they should be interpreted as a literal part of the given pattern, not as special markers.
The rest of this looks great! Thanks for the updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks for reviewing, this is updated and I think this is good to go noew 🙂
…rapping '/' ) To remain consistent with `Regex` and `RegexAll`.
remove double '\n'
Thanks! 🎉 |
While I was writing the changelog entry for this I noticed that the new function was called For consistency, I made follow up commit 440c597 to rename to |
Ah no worries :) Thanks !!! 🚀 🚀 🚀 |
No description provided.