Skip to content

Commit 5f08d4e

Browse files
author
Raymond McCrae
committed
Remove ErrorLevel enum since it is not required to be part of the public API
1 parent b83ce07 commit 5f08d4e

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

Sources/HTMLSAXParser/HTMLSAXParser+libxml2.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ internal extension HTMLSAXParser {
131131
private func handleParseResult(_ parseResult: Int32, _ handlerContext: HTMLSAXParser.HandlerContext) throws {
132132
// htmlParseDocument returns zero for success, therefore if non-zero we need to check the last error.
133133
if parseResult != 0 {
134-
guard let error = handlerContext.lastError(),
135-
let errorLevel = ErrorLevel(rawValue: Int(error.pointee.level.rawValue)) else {
136-
// If no last error was found or the error level has invalid value then just return.
134+
guard let error = handlerContext.lastError() else {
135+
// If no last error was found then just return.
137136
return
138137
}
139138

139+
let errorLevel = error.pointee.level
140140
switch errorLevel {
141-
case .fatal: // if fatal then throw a parsingFailure
141+
case XML_ERR_FATAL: // if fatal then throw a parsingFailure
142142
let message: String
143143
if let messageCString = error.pointee.message {
144144
message = String(cString: messageCString).trimmingCharacters(in: .whitespacesAndNewlines)
@@ -149,8 +149,8 @@ internal extension HTMLSAXParser {
149149

150150
let location = Location(line: Int(error.pointee.line), column: Int(error.pointee.int2))
151151

152-
throw Error.parsingFailure(level: errorLevel, location: location, message: message)
153-
case .none, .warning, .error: // All other levels of error will be considered success
152+
throw Error.parsingFailure(location: location, message: message)
153+
default: // All other levels of error will be considered success
154154
break
155155
}
156156
}

Sources/HTMLSAXParser/HTMLSAXParser.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,12 @@ open class HTMLSAXParser {
9898
case error(message: String)
9999
}
100100

101-
public enum ErrorLevel: Int {
102-
case none = 0
103-
case warning = 1
104-
case error = 2
105-
case fatal = 3
106-
}
107-
108101
public enum Error: Swift.Error {
109102
case unknown
110103
case unsupportedCharEncoding
111104
case stringEncodingConversion
112105
case emptyDocument
113-
case parsingFailure(level: ErrorLevel, location: Location, message: String)
106+
case parsingFailure(location: Location, message: String)
114107
}
115108

116109
public typealias EventHandler = (HTMLSAXParseContext, Event) -> Void
@@ -134,7 +127,7 @@ open class HTMLSAXParser {
134127

135128
- Parameter string: The string containing the HTML content.
136129
- Parameter handler: The event handler closure that will be called during parsing.
137-
- Throws: `HTMLParser.Error` if an error occured during parsing.
130+
- Throws: `HTMLParser.Error` if a fatal error occured during parsing.
138131
*/
139132
open func parse(string: String, handler: @escaping EventHandler) throws {
140133
guard let uft8Data = string.data(using: .utf8) else {
@@ -159,7 +152,7 @@ open class HTMLSAXParser {
159152
- Parameter encoding: The character encoding to interpret the data. If no encoding
160153
is given then the parser will attempt to detect the encoding.
161154
- Parameter handler: The event handler closure that will be called during parsing.
162-
- Throws: `HTMLParser.Error` if an error occured during parsing.
155+
- Throws: `HTMLParser.Error` if a fatal error occured during parsing.
163156
*/
164157
open func parse(data: Data, encoding: String.Encoding? = nil, handler: @escaping EventHandler) throws {
165158
let dataLength = data.count

0 commit comments

Comments
 (0)