feat: convenience init for string-based TblTableRef
This commit is contained in:
@@ -13,6 +13,19 @@ public struct TblTableRef: CustomStringConvertible {
|
||||
self.ident = ident
|
||||
}
|
||||
|
||||
/// Convenience constructor for string-based references.
|
||||
/// Must conform to format `"@PPTTEEEE"`.
|
||||
/// Throws an exception if string does not starts with `"@"` or cannot resolve hex-string into `UInt32`.
|
||||
public init(_ stringRef: String) throws {
|
||||
guard stringRef.hasPrefix("@") else {
|
||||
throw AXMLError("A table reference must start with @")
|
||||
}
|
||||
guard let idx = UInt32(stringRef[(stringRef.index(after: stringRef.startIndex))..<stringRef.endIndex], radix: 16) else {
|
||||
throw AXMLError("Invalid table reference format")
|
||||
}
|
||||
self.ident = idx
|
||||
}
|
||||
|
||||
/// `ident` as hex string
|
||||
public var asHex: String { ident.hex(8) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user