-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rkukuh/dev
Dev
- Loading branch information
Showing
3 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,14 @@ These following methods are available for working with and manipulating `String` | |
- [`after`](https://github.com/rkukuh/Swift-StringHelper#after) | ||
- [`before`](https://github.com/rkukuh/Swift-StringHelper#before) | ||
- [`between`](https://github.com/rkukuh/Swift-StringHelper#between) | ||
- [`camel case`](https://github.com/rkukuh/Swift-StringHelper#camel-case) | ||
- [`camelCase`](https://github.com/rkukuh/Swift-StringHelper#camelcased) | ||
- [`containsAll`](https://github.com/rkukuh/Swift-StringHelper#containsall) | ||
|
||
## Usage | ||
|
||
### `after` | ||
|
||
The `after` helper returns the remainder of a string after the first occurrence of a given value. | ||
The `after()` helper returns the remainder of a string after the first occurrence of a given value. | ||
|
||
```swift | ||
let originalString = "[email protected]" | ||
|
@@ -49,7 +50,7 @@ print(result) // apple.com | |
|
||
### `before` | ||
|
||
The `before` helper returns the portion of a string before the first occurrence of a given value. | ||
The `before()` helper returns the portion of a string before the first occurrence of a given value. | ||
|
||
```swift | ||
let originalString = "[email protected]" | ||
|
@@ -60,7 +61,7 @@ print(result) // john | |
|
||
### `between` | ||
|
||
The `before` helper returns the portion of a string between two values. | ||
The `between()` helper returns the portion of a string between two values. | ||
|
||
```swift | ||
let originalString = "[email protected]" | ||
|
@@ -69,13 +70,31 @@ let result = originalString.between("john@", and: ".com") | |
print(result) // Optional("apple") | ||
``` | ||
|
||
### `camel case` | ||
### `camelCase` | ||
|
||
The `camelCased` helper converts the given string to camelCaseLikeThis. | ||
The `camelCased()` helper converts the given string to camelCaseLikeThis. | ||
|
||
```swift | ||
var originalString = "Everyone CAN Code" | ||
var result = originalString.camelCased() | ||
|
||
print(result) // everyoneCanCode | ||
``` | ||
|
||
### `containsAll` | ||
|
||
The `containsAll()` helper determines if the given string contains all of the values in a given array. | ||
|
||
```swift | ||
let originalString = "[email protected]" | ||
let result = originalString.containsAll(["hello", "@", ".com"]) | ||
|
||
print(result) // true | ||
``` | ||
|
||
```swift | ||
let originalString = "[email protected]" | ||
let result = originalString.containsAll(["hello", "@", ".org"]) | ||
|
||
print(result) // false | ||
``` |
14 changes: 14 additions & 0 deletions
14
Sources/SwiftStringHelper/StringContainsAllExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by R. Kukuh on 01/04/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension String { | ||
func containsAll(_ substrings: [String]) -> Bool { | ||
return substrings.allSatisfy { self.contains($0) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// StringContainsAllTests.swift | ||
// | ||
// | ||
// Created by R. Kukuh on 01/04/23. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftStringHelper | ||
|
||
class StringContainsAllTests: XCTestCase { | ||
|
||
func testContainsAll() { | ||
let originalString = "[email protected]" | ||
let result = originalString.containsAll(["hello", "@", ".com"]) | ||
XCTAssertTrue(result, "The string should contain all specified substrings") | ||
} | ||
|
||
func testContainsAllWhenNotFound() { | ||
let originalString = "[email protected]" | ||
let result = originalString.containsAll(["hello", "#"]) | ||
XCTAssertFalse(result, "The string should not contain all specified substrings") | ||
} | ||
|
||
func testContainsAllWhenEmpty() { | ||
let originalString = "" | ||
let result = originalString.containsAll(["hello", "@"]) | ||
XCTAssertFalse(result, "An empty string should not contain any substrings") | ||
} | ||
|
||
} |