39 lines
1.1 KiB
Swift
39 lines
1.1 KiB
Swift
|
|
// ===----------------------------------------------------------------------===
|
||
|
|
//
|
||
|
|
// This source file is part of the DiscogsService open source project
|
||
|
|
//
|
||
|
|
// Copyright (c) 2025 Röck+Cöde VoF. and the DiscogsService project authors
|
||
|
|
// Licensed under Apache license v2.0
|
||
|
|
//
|
||
|
|
// See LICENSE for license information
|
||
|
|
// See CONTRIBUTORS for the list of DiscogsService project authors
|
||
|
|
//
|
||
|
|
// SPDX-License-Identifier: Apache-2.0
|
||
|
|
//
|
||
|
|
// ===----------------------------------------------------------------------===
|
||
|
|
|
||
|
|
/// A validation rule type that checks whether an input is empty or not.
|
||
|
|
struct NotEmptyValidationRule: InputValidationRule {
|
||
|
|
|
||
|
|
// MARK: Functions
|
||
|
|
|
||
|
|
func validate(_ input: String?) throws -> Bool {
|
||
|
|
guard let input else {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
guard !input.isEmpty else {
|
||
|
|
throw InputValidationError.inputIsEmpty
|
||
|
|
}
|
||
|
|
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// MARK: - Constants
|
||
|
|
|
||
|
|
extension InputValidationRule where Self == NotEmptyValidationRule {
|
||
|
|
/// A validation rule that checks whether an input is empty or not.
|
||
|
|
static var notEmpty: Self { .init() }
|
||
|
|
}
|