Skip to content

Commit

Permalink
Merge pull request #15 from rkukuh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rkukuh authored Apr 1, 2023
2 parents f26d5be + a0b325a commit b68e07e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand All @@ -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]"
Expand All @@ -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]"
Expand All @@ -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 Sources/SwiftStringHelper/StringContainsAllExtensions.swift
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) }
}
}
31 changes: 31 additions & 0 deletions Tests/SwiftStringHelperTests/StringContainsAllTests.swift
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")
}

}

0 comments on commit b68e07e

Please sign in to comment.