2024-08-27 05:03:35 +02:00
|
|
|
|
//
|
2024-09-10 05:54:42 +02:00
|
|
|
|
// SAXUtilities.swift
|
2024-08-27 05:03:35 +02:00
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 8/26/24.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import libxml2
|
|
|
|
|
|
2024-08-27 07:39:46 +02:00
|
|
|
|
public func SAXEqualTags(_ localName: XMLPointer, _ tag: ContiguousArray<Int8>) -> Bool {
|
2024-08-27 05:03:35 +02:00
|
|
|
|
|
2024-08-27 07:39:46 +02:00
|
|
|
|
return tag.withUnsafeBufferPointer { bufferPointer in
|
|
|
|
|
|
2024-08-27 08:02:22 +02:00
|
|
|
|
let tagCount = tag.count // includes 0 terminator
|
2024-08-27 07:39:46 +02:00
|
|
|
|
|
2024-08-27 08:02:22 +02:00
|
|
|
|
for i in 0..<tagCount - 1 {
|
2024-08-27 07:39:46 +02:00
|
|
|
|
|
|
|
|
|
let localNameCharacter = localName[i]
|
|
|
|
|
if localNameCharacter == 0 {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2024-08-27 05:03:35 +02:00
|
|
|
|
|
2024-08-27 07:39:46 +02:00
|
|
|
|
let tagCharacter = UInt8(tag[i])
|
|
|
|
|
if localNameCharacter != tagCharacter {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// localName might actually be longer — make sure it’s the same length as tag.
|
2024-08-27 08:02:22 +02:00
|
|
|
|
return localName[tagCount - 1] == 0
|
2024-08-27 07:39:46 +02:00
|
|
|
|
}
|
2024-08-27 05:03:35 +02:00
|
|
|
|
}
|
2024-09-14 19:59:55 +02:00
|
|
|
|
|
|
|
|
|
public extension String {
|
|
|
|
|
|
|
|
|
|
init?(xmlPointer: XMLPointer, count: Int? = nil) {
|
|
|
|
|
let d = Data(bytes: xmlPointer, count: count ?? strlen(xmlPointer))
|
|
|
|
|
self.init(data: d, encoding: .utf8)
|
|
|
|
|
}
|
|
|
|
|
}
|