Skip to content

Commit

Permalink
Revert Regex changes to hopefully fix GH Actions
Browse files Browse the repository at this point in the history
Signed-off-by: Henrik Panhans <[email protected]>
  • Loading branch information
henrik-dmg committed Mar 7, 2024
1 parent 017ab5b commit 052763b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Sources/SwiftFrameCore/Config/ConfigData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ struct ConfigData: Decodable, ConfigValidateable {
// MARK: - Processing

mutating func process() throws {
let regex: Regex<AnyRegexOutput>?
let regex: NSRegularExpression?
if let localesRegex, !localesRegex.isEmpty {
regex = try Regex(localesRegex)
regex = try NSRegularExpression(pattern: localesRegex)
} else {
regex = nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFrameCore/Config/DeviceData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct DeviceData: Decodable, ConfigValidateable {

// MARK: - Methods

func makeProcessedData(localesRegex: Regex<AnyRegexOutput>?) throws -> DeviceData {
func makeProcessedData(localesRegex: NSRegularExpression?) throws -> DeviceData {
guard let templateImage = ImageLoader.loadRepresentation(at: templateImagePath.absoluteURL) else {
throw NSError(description: "Error while loading template image at path \(templateImagePath.absoluteString)")
}
Expand Down
15 changes: 12 additions & 3 deletions Sources/SwiftFrameCore/Extensions/Collection+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import Foundation

extension [URL] {
extension Array where Element == URL {

func filterByFileOrFoldername(regex: Regex<AnyRegexOutput>?) throws -> Self {
func filterByFileOrFoldername(regex: NSRegularExpression?) throws -> Self {
guard let regex else {
return self
}
return self.filter { url in
let lastComponent = url.deletingPathExtension().lastPathComponent
return !lastComponent.matches(of: regex).isEmpty
return regex.matches(lastComponent)
}
}

}

extension NSRegularExpression {

func matches(_ string: String) -> Bool {
let range = NSRange(location: 0, length: (string as NSString).length)
return firstMatch(in: string, options: [], range: range) != nil
}

}
6 changes: 3 additions & 3 deletions Tests/SwiftFrameTests/RegexMatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RegexMatchTests: XCTestCase {
}

func testFranceFilteredOut() throws {
let regex = try Regex("^(?!fr$)\\w*$")
let regex = try NSRegularExpression(pattern: "^(?!fr$)\\w*$", options: .caseInsensitive)
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: regex)

guard ky_assertEqual(urls.count, 3) else {
Expand All @@ -31,7 +31,7 @@ class RegexMatchTests: XCTestCase {
}

func testFranceAndRussiaFilteredOut() throws {
let regex = try Regex("^(?!fr|ru$)\\w*$")
let regex = try NSRegularExpression(pattern: "^(?!fr|ru$)\\w*$", options: .caseInsensitive)
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: regex)

guard ky_assertEqual(urls.count, 2) else {
Expand All @@ -42,7 +42,7 @@ class RegexMatchTests: XCTestCase {
}

func testOnlyRussiaAndFrance() throws {
let regex = try Regex("ru|fr")
let regex = try NSRegularExpression(pattern: "ru|fr", options: .caseInsensitive)
let urls = try RegexMatchTests.urls.filterByFileOrFoldername(regex: regex)

guard ky_assertEqual(urls.count, 2) else {
Expand Down

0 comments on commit 052763b

Please sign in to comment.