-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to change access token from the Demo UI.
- Loading branch information
Showing
6 changed files
with
121 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
Demos/iosAppSwift/iosAppSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,47 @@ | ||
import Foundation | ||
|
||
extension String { | ||
var isValid: Bool { | ||
#"(^[a-f0-9]{32}$)"#.matches(in: self)?.count == 1 | ||
} | ||
} | ||
|
||
extension StringProtocol { | ||
|
||
/// Returns an array of `Substring`s by matching the given `String` using | ||
/// this string as a regular expression pattern. | ||
/// | ||
/// Returns `nil` if this string isn't a valid regex pattern, if no | ||
/// matches are found, an empty string is returned. | ||
func matches(in str: String) -> [Substring]? { | ||
let regex = try? NSRegularExpression(pattern: String(self)) | ||
let range = NSRange(str.startIndex..<str.endIndex, in: str) | ||
return regex?.matches(in: str, range: range).first?.groups(in: str) | ||
} | ||
} | ||
|
||
extension NSTextCheckingResult { | ||
|
||
/// Returns an array of `Substring`s by extracting from the given `String` | ||
/// the groups in this `NSTextCheckingResult` instance . | ||
func groups(in str: String) -> [Substring] { | ||
guard self.numberOfRanges > 1 else { return [] } | ||
|
||
var result = ContiguousArray<Substring>() | ||
result.reserveCapacity(self.numberOfRanges) | ||
|
||
for index in 1..<self.numberOfRanges { | ||
if let substr = range(at: index, in: str).map({ str[$0] }) { | ||
result.append(substr) | ||
} | ||
} | ||
|
||
return [Substring](result) | ||
} | ||
|
||
/// Returns the `Range` for the given group number that corresponds to | ||
/// the given `String`. | ||
func range(at index: Int, in string: String) -> Range<String.Index>? { | ||
Range(self.range(at: index), in: string) | ||
} | ||
} |
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