Skip to content

Commit 1bae0a8

Browse files
committed
Fix FieldHexadecimal command: missing indicator
1 parent c5c5dc7 commit 1bae0a8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Sources/ZPLBuilder/Commands/FieldHexadecimal.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@
88
import Foundation
99

1010
public struct FieldHexadecimal: ZPLCommandConvertible {
11+
/// Hexadecimal indicator
12+
///
13+
/// Values: any character except current format and control prefix (^ and ~ by default)
14+
///
15+
/// Default: _ (underscore)
1116
public var indicator: Character
17+
/// Special character's hexadecimal value.
1218
public var code: UInt8
1319
public var command: String {
14-
String(format: "%02X", code)
20+
String(format: "\(indicator)%02X", code)
1521
}
1622

23+
/// Field Hexadecimal
24+
///
25+
/// - Parameters:
26+
/// - indicator: Hexadecimal indicator. Values: any character except current format and control prefix (^ and ~ by default).
27+
/// - code: Special character's hexadecimal value.
1728
public init(indicator: Character = "_", code: UInt8) {
1829
self.indicator = indicator
1930
self.code = code

Tests/ZPLBuilderTests/ZPLCommandTests.swift

+8
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ class ZPLCommandTests: XCTestCase {
2929
let cmd = BarcodeDefault(moduleWidth: 1, ratio: 2, height: 4)
3030
XCTAssertEqual(cmd.command, "^BY1,2.0,4")
3131
}
32+
33+
func test_field_hexadecimal() {
34+
let cmd1 = FieldHexadecimalIndicator(indicator: "\\")
35+
XCTAssertEqual(cmd1.command, "^FH\\")
36+
37+
let cmd2 = FieldHexadecimal(indicator: "\\", code: 0x7E)
38+
XCTAssertEqual(cmd2.command, "\\7E")
39+
}
3240
}

0 commit comments

Comments
 (0)