b14a9fa816
This PR contains the work done to improve the documentation efforts in the package, aiming at improving the documentation of the source code as well as the OpenAPI specification document. In addition, a breaking bug has been fixed. Reviewed-on: #16 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
46 lines
1.5 KiB
Swift
46 lines
1.5 KiB
Swift
// ===----------------------------------------------------------------------===
|
|
//
|
|
// This source file is part of the DiscogsService open source project
|
|
//
|
|
// Copyright (c) 2026 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
|
|
//
|
|
// ===----------------------------------------------------------------------===
|
|
|
|
import Foundation
|
|
|
|
extension String {
|
|
|
|
// MARK: Functions
|
|
|
|
/// Checks whether a regular expression pattern fully matches a string or not.
|
|
/// - Parameter pattern: A regular expression pattern to match a string against.
|
|
/// - Returns: A flag that indicates whether a given pattern fully matches a string or not.
|
|
func fullyMatch(pattern: String) -> Bool {
|
|
do {
|
|
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 6.0, *) {
|
|
let securityInput = try Regex(pattern)
|
|
let matches = self.wholeMatch(of: securityInput)
|
|
|
|
return matches != nil
|
|
} else {
|
|
let securityInput = try NSRegularExpression(pattern: pattern)
|
|
let matches = securityInput.matches(
|
|
in: self,
|
|
range: .init(location: 0, length: count)
|
|
)
|
|
|
|
return !matches.isEmpty
|
|
}
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
}
|