-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFieldData.swift
53 lines (48 loc) · 1.59 KB
/
FieldData.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// FieldData.swift
//
//
// Created by chen on 2023/11/11.
//
import Foundation
extension FieldData {
#if canImport(CoreFoundation.CFString) && canImport(CoreFoundation.CFStringEncodingExt)
public static var big5Encoding: String.Encoding {
let _encoding = CFStringEncoding(CFStringEncodings.big5.rawValue)
let encoding = CFStringConvertEncodingToNSStringEncoding(_encoding)
return .init(rawValue: encoding)
}
#endif
}
/// The ^FD command defines the data string for a field.
/// The field data can be any printable character except those used as command prefixes (^ and ~).
///
/// # Field Data
///
/// In RFID printers, it can also be used to specify passwords to write to tags.
public struct FieldData: ZPLCommandConvertible {
/// Data to be printed (all printers), or a password to be written to a RFID tag (rfid printers)
///
/// Values: any data string up to 3072 bytes
///
/// Default: none—a string of characters must be entered
public var text: String
public var command: String {
"^FD\(text)"
}
/// Field Data.
/// - Parameters:
/// - text:
/// Data to be printed (all printers), or a password to be written to a RFID tag (rfid printers).
/// * Any data string up to 3072 bytes
public init(text: String) {
self.text = text
}
public init(text: String, encoding: String.Encoding, indicator: Character) {
self.text = text.data(using: encoding)?
.map {
String(format:"\(indicator)%02X", $0)
}
.joined() ?? ""
}
}