[🤖] Add ^ Postfix Operator for Suffix String Matching
#8
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.
Summary
This PR introduces the postfix
^operator to the StringContainsOperators library, enabling suffix stringmatching functionality. This complements the existing prefix
^operator and extends the library's capabilitiesfor expressive string search patterns.
Motivation
The StringContainsOperators library already provides elegant prefix matching via
^"value". However, there was noequivalent for suffix matching, requiring developers to fall back to native Swift's
hasSuffix()method, whichbreaks the fluent, composable pattern established by the library.
Before:
After:
What Changed
New Files
Sources/StringContainsOperators/SearchStrategies/SuffixSearchStrategy.swiftString.hasSuffix()Modified Files
1.
Sources/StringContainsOperators/StringContainsOperators.swiftpostfix operator ^declaration.suffix(StringPredicateInputKind)case toStringPredicateenumpostfix func ^(value: String) -> StringPredicatepostfix func ^(predicate: StringPredicate) -> StringPredicate2.
Sources/StringContainsOperators/SearchStrategyMaker.swift.suffixcase to the switch statementSuffixSearchStrategyfor suffix predicates3.
Tests/StringContainsOperatorsTests/StringContainsOperatorsTests.swifttestSuffixOperator()- Basic functionalitytestSuffixOperatorWithEmptyString()- Edge casestestSuffixOperatorCombinedWithOr()- OR combinationstestSuffixOperatorCombinedWithAnd()- AND combinationstestSuffixOperatorWithDiacriticInsensitivity()- Sensitivity behaviortestSuffixOperatorInComplexPredicate()- Complex predicatestestSuffixOperatorWithCombinedOperators()- Multi-operator combinationstestPrefixAndSuffixOperatorsTogether()- Prefix + suffix together4.
README.mdImplementation Details
Architecture
The implementation follows the library's established Strategy Pattern:
Operator: "Victor"^
↓
StringPredicate.suffix(.string("Victor"))
↓
SearchStrategyMaker.make() → SuffixSearchStrategy
↓
SuffixSearchStrategy.evaluate(string:)
↓
String.hasSuffix("Victor")
↓
Bool result
Combined with Other Operators
Mixed Prefix and Suffix
Compatibility
Breaking Changes
None - This is a purely additive change.
Migration Guide
No migration needed. The existing API remains unchanged. Users can start using the new suffix operator
immediately.
Future Enhancements
Potential future improvements could include:
Notes for Reviewers
^) used for both prefix and postfix is intentional and follows Swift's operator overloadingconventions
Checklist
Related Issues: None (this is a new feature)
PR Type: Feature Addition
Impact: Low (additive, no breaking changes)
Risk: Low (well-tested, follows existing patterns)