Skip to content

Commit

Permalink
Parse rules without spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
grgar committed Oct 14, 2023
1 parent 74285a0 commit bd1c246
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ struct ContentView: View {
} detail: {
Text("")
.accessibilityHidden(true)
.navigationSplitViewColumnWidth(ideal: navigationCategory == .rules ? 320 : 0,
max: navigationCategory == .rules ? 480 : 0)
.navigationSplitViewColumnWidth(min: navigationCategory == .rules ? 320 : 0,
ideal: navigationCategory == .rules ? 320 : 0,
max: navigationCategory == .rules ? 480 : 0)
}
#if os(macOS)
.frame(minWidth: 320 + 320 + (navigationCategory == .rules ? 320 : 0))
#endif
}
}

Expand Down
10 changes: 5 additions & 5 deletions Rule/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct Rule: Identifiable, Hashable {
var maxLength: Int?
var required = Set<PasswordCharacter>()
var allowed = Set<PasswordCharacter>()
var sumLength: Int { (minLength ?? 0) + (maxLength ?? 0) }

var sumLength: Int { (self.minLength ?? 0) + (self.maxLength ?? 0) }

enum PasswordCharacter: LosslessStringConvertible, Hashable, CaseIterable, Comparable, Identifiable {
case lower, upper, digit, special, unicode, other(Set<Character>)
Expand All @@ -28,7 +28,7 @@ struct Rule: Identifiable, Hashable {
case "unicode":
self = .unicode
default:
self = .other(description.reduce(into: Set<Character>()) { partialResult, character in
self = .other(description.dropFirst().dropLast().reduce(into: Set<Character>()) { partialResult, character in
partialResult.insert(character)
})
}
Expand Down Expand Up @@ -96,13 +96,13 @@ extension Rule {
case "maxlength":
self.maxLength = Int(split[1].trimmingCharacters(in: .punctuationCharacters))
case "required":
for set in String(split[1]).split(separator: try! Regex(",(?: |$)")) {
for set in String(split[1]).split(separator: /, ?(?![^\[]*\])/) {
if let set = PasswordCharacter(String(set)) {
self.required.insert(set)
}
}
case "allowed":
for set in String(split[1]).split(separator: try! Regex(",(?: |$)")) {
for set in String(split[1]).split(separator: /, ?(?![^\[]*\])/) {
if let set = PasswordCharacter(String(set)) {
self.allowed.insert(set)
}
Expand Down

0 comments on commit bd1c246

Please sign in to comment.