mirror of
https://github.com/rememberber/MooTool.git
synced 2026-12-01 03:18:19 +08:00
22 lines
584 B
Swift
22 lines
584 B
Swift
import Foundation
|
|
|
|
public enum QRCodePayloadError: Error, Equatable, Sendable {
|
|
case emptyPayload
|
|
}
|
|
|
|
public struct QRCodePayload: Equatable, Sendable {
|
|
public let text: String
|
|
public let byteCount: Int
|
|
}
|
|
|
|
public enum QRCodePayloadService {
|
|
public static func prepare(_ rawValue: String) throws -> QRCodePayload {
|
|
let text = rawValue.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !text.isEmpty else {
|
|
throw QRCodePayloadError.emptyPayload
|
|
}
|
|
|
|
return QRCodePayload(text: text, byteCount: Data(text.utf8).count)
|
|
}
|
|
}
|