Skip to content

Add EqualsIgnoreCase string builtin function#509

Merged
xoofx merged 3 commits intoscriban:masterfrom
ranger-turtle:NewBuiltin
Jun 11, 2023
Merged

Add EqualsIgnoreCase string builtin function#509
xoofx merged 3 commits intoscriban:masterfrom
ranger-turtle:NewBuiltin

Conversation

@ranger-turtle
Copy link
Copy Markdown
Contributor

I have added EqualsIgnoreCase string builtin function which would be faster way for case insensitive string comparison than the workaround I have mentioned in my comment in #508 .

@binarycow
Copy link
Copy Markdown
Contributor

(Note - I'm not the maintainer of Scriban - just another occasional contributer)

You beat me to it!

While you're at it, I have a suggestion, if you have the time...

Add an overload for the normal equals method that accepts StringComparison.

Could also do that for all of the other methods, where the .NET method also accepts StringComparison.

IIRC, Scriban supports optional parameters, so it would be as easy as copy/pasting the StringComparison parameter in three places for each method:

  • Parameter list
  • Method call
  • XML docs

If Scriban doesn't support optional parameters, then.... Maybe I'll add that?

@ranger-turtle
Copy link
Copy Markdown
Contributor Author

I considered making general equals builtin function with StringComparison type parameter but I decided to make the EqualsIgnoreCase function instead, since case sensitive comparison can be accomplished using == operator and I found making equals unnecessary.

However, I think I may add an optional parameter to such functions, like StartsWith or Contains. I will wait for @xoofx 's answer to ensure if this PR makes sense according to him.

Comment thread src/Scriban/Functions/StringFunctions.cs Outdated
@xoofx
Copy link
Copy Markdown
Member

xoofx commented Jun 10, 2023

Adding string.equals_ignore_case is fine. Tests are failing (but due to the flood of logs, can't see it easily in GitHub, you need to check this locally)

I would prefer not to change existing methods. For 6+ years nobody has been looking for configurable string comparisons, so this is not necessary to change all these. Users can always create custom methods on their side.

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 10, 2023

Pull Request Test Coverage Report for Build 5229987164

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 78.586%

Totals Coverage Status
Change from base Build 4852412395: 0.03%
Covered Lines: 11564
Relevant Lines: 13962

💛 - Coveralls

@xoofx xoofx merged commit 1328529 into scriban:master Jun 11, 2023
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.

4 participants