-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Sources/ExtensionKit/FoundationExtensions/String/AttributedString+Attribute.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,15 @@ | ||
// | ||
// AttributedString+Attribute.swift | ||
// | ||
// | ||
// Created by MohammadReza Ansary on 12/20/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension NSMutableAttributedString { | ||
func attribute(_ key: NSAttributedString.Key, value: Any, range: NSRange) -> Self { | ||
addAttribute(key, value: value, range: range) | ||
return self | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Sources/ExtensionKit/FoundationExtensions/String/String+Attributed.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 @@ | ||
// | ||
// String+Attributed.swift | ||
// | ||
// | ||
// Created by MohammadReza Ansary on 12/20/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension String { | ||
var attributed: NSMutableAttributedString { | ||
NSMutableAttributedString(string: self) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Sources/ExtensionKit/FoundationExtensions/String/String+Distance.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,23 @@ | ||
// | ||
// String+Distance.swift | ||
// | ||
// | ||
// Created by MohammadReza Ansary on 12/20/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension StringProtocol { | ||
func distance(of element: Element) -> Int? { firstIndex(of: element)?.distance(in: self) } | ||
func distance<S: StringProtocol>(of string: S) -> Int? { range(of: string)?.lowerBound.distance(in: self) } | ||
} | ||
|
||
|
||
public extension Collection { | ||
func distance(to index: Index) -> Int { distance(from: startIndex, to: index) } | ||
} | ||
|
||
|
||
public extension String.Index { | ||
func distance<S: StringProtocol>(in string: S) -> Int { string.distance(to: self) } | ||
} |
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