You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
StringContainsOperators is a Swift library for creating and evaluating complex string predicates using custom operators. This library provides an easy-to-use and flexible solution for matching strings against complex patterns.
5
+
# 🐞 StringContainsOperators
4
6
5
-
## How to Use
7
+
StringContainsOperators is a Swift library that simplifies searching for multiple strings within a given text. By using custom infix operators and predicates, you can create complex and flexible search patterns that make it easy to find if strings exist in your text.
6
8
7
-
The library provides three main components: custom operators, an enum type, and an extension to the String class.
9
+
## Usage
8
10
9
-
## Custom Operators
10
-
11
-
StringContainsOperators provides two custom operators: || and &&. These operators are used to create OR and AND predicates, respectively, between two strings or between a string and another predicate.
12
-
13
-
For example, you can create an OR predicate between two strings as follows:
14
-
15
-
```swift
16
-
let predicate ="hello"||"world"
17
-
```
18
-
This creates a predicate that matches any string that contains either "hello" or "world". Similarly, you can create an AND predicate between two strings like this:
11
+
Here's a quick example of how you can use StringContainsOperators:
19
12
20
13
```swift
21
-
let predicate ="hello"&&"world"
22
-
```
23
-
This creates a predicate that matches any string that contains both "hello" and "world".
14
+
importStringContainsOperators
24
15
25
-
## Enum Type
16
+
let text ="The quick brown fox jumps over the lazy dog."
26
17
27
-
The resulting predicate is represented by an enum type called StringPredicate. This enum type can be either a base predicate, an OR predicate, or an AND predicate.
18
+
// Check if text contains "quick" OR "jumps"
19
+
let result1 = text.contains("quick"||"jumps")
20
+
print(result1) // true
28
21
29
-
## Extension to String
22
+
// Check if text contains "fox" AND "dog"
23
+
let result2 = text.contains("fox"&&"dog")
24
+
print(result2) // true
30
25
31
-
The contains() function, which is an extension of the String class, is used to evaluate whether a given string satisfies a particular predicate. The function takes a StringPredicate as input and returns a boolean value indicating whether the predicate is true or false.
32
-
33
-
```swift
34
-
let result ="hello world".contains("hello"||"world")
35
-
print(result) // true
26
+
// Check if text contains "fox" AND ("jumps" OR "swift")
27
+
let result3 = text.contains("fox"&& ("jumps"||"swift"))
28
+
print(result3) // true
36
29
```
37
30
38
31
## How to Install
@@ -57,4 +50,4 @@ pod 'StringContainsOperators', '~> 1.0'
57
50
58
51
Contributions to StringContainsOperators are welcome! Before making a pull request, please open an issue to discuss your proposed changes. We follow the GitHub Flow for our development process.
59
52
60
-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
53
+
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
0 commit comments