Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix issues around Xcode 16, and rename to parse(...) from init(...) #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Sources/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ open class XMLDocument {

- returns: An `XMLDocument` with the contents of the specified XML string.
*/
public convenience init(string: String, encoding: String.Encoding = String.Encoding.utf8) throws {
public class func parse(string: String, encoding: String.Encoding = String.Encoding.utf8) throws -> Self {
guard let cChars = string.cString(using: encoding) else {
throw XMLError.invalidData
}
try self.init(cChars: cChars)
return try Self.parse(cChars: cChars)
}
@available(*, unavailable, renamed: "parse")
public convenience init(string: String, encoding: String.Encoding = String.Encoding.utf8) throws {
preconditionFailure()
}

/**
Expand All @@ -90,9 +94,14 @@ open class XMLDocument {

- returns: An `XMLDocument` with the contents of the specified XML string.
*/
public class func parse(data: Data) throws -> Self {
try data.withUnsafeBytes {
try Self(buffer: $0.bindMemory(to: Int8.self))
}
}
@available(*, unavailable, renamed: "parse")
public convenience init(data: Data) throws {
let buffer = data.withUnsafeBytes { $0.bindMemory(to: Int8.self) }
try self.init(buffer: buffer)
preconditionFailure()
}

/**
Expand All @@ -104,11 +113,14 @@ open class XMLDocument {

- returns: An `XMLDocument` with the contents of the specified XML string.
*/
public convenience init(cChars: [CChar]) throws {
let buffer = cChars.withUnsafeBufferPointer { buffer in
UnsafeBufferPointer(rebasing: buffer[0..<buffer.count])
public class func parse(cChars: [CChar]) throws -> Self {
return try cChars.withUnsafeBytes {
return try Self(buffer: $0.bindMemory(to: Int8.self))
}
try self.init(buffer: buffer)
}
@available(*, unavailable, renamed: "parse")
public convenience init(cChars: [CChar]) throws {
preconditionFailure()
}

/**
Expand All @@ -121,7 +133,7 @@ open class XMLDocument {
- returns: An `XMLDocument` with the contents of the specified XML string.
*/

public convenience init(buffer: UnsafeBufferPointer<Int8>) throws {
public convenience required init(buffer: UnsafeBufferPointer<Int8>) throws {
let options = Int32(XML_PARSE_NOWARNING.rawValue | XML_PARSE_NOERROR.rawValue | XML_PARSE_RECOVER.rawValue)
try self.init(buffer: buffer, options: options)
}
Expand Down