From bd1c24613b880c19ecf7ac8cda0f1a22c93bdb85 Mon Sep 17 00:00:00 2001 From: George Garside Date: Sat, 14 Oct 2023 21:23:11 +0100 Subject: [PATCH] Parse rules without spaces --- ContentView.swift | 8 ++++++-- Rule/Rule.swift | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ContentView.swift b/ContentView.swift index 37a0784..b580734 100644 --- a/ContentView.swift +++ b/ContentView.swift @@ -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 } } diff --git a/Rule/Rule.swift b/Rule/Rule.swift index 0418239..453ab98 100644 --- a/Rule/Rule.swift +++ b/Rule/Rule.swift @@ -9,8 +9,8 @@ struct Rule: Identifiable, Hashable { var maxLength: Int? var required = Set() var allowed = Set() - - 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) @@ -28,7 +28,7 @@ struct Rule: Identifiable, Hashable { case "unicode": self = .unicode default: - self = .other(description.reduce(into: Set()) { partialResult, character in + self = .other(description.dropFirst().dropLast().reduce(into: Set()) { partialResult, character in partialResult.insert(character) }) } @@ -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) }