feat: convenience init for string-based TblTableRef

This commit is contained in:
relikd
2025-11-27 17:42:50 +01:00
parent 9847ab76d9
commit 1a5d573a11

View File

@@ -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) }