guard let unichars = $0.baseAddress else { throw HTMLSpecialCharactersError.invalidEscapeSquence }
let length = $0.count
if let t = getUnescapeTable(length: $0.count) {
for i in 0..<t.count {
if memcmp(t[i].unescapingCodes, unichars, MemoryLayout<UniChar>.size * length) == 0 {
return t[i].code
}
}
}
throw HTMLSpecialCharactersError.invalidEscapeSquence
guard let unichars = $0.baseAddress else { throw HTMLSpecialCharactersError.invalidEscapeSquence }
let length = $0.count
do {
try getUnescapeTable(length: length)?.forEach({
if memcmp($0.unescapingCodes, unichars, MemoryLayout<UniChar>.size * length) == 0 {
throw HTMLSpecialCharactersError.notErrorMatchedUnicode(code: $0.code)
}
})
throw HTMLSpecialCharactersError.invalidEscapeSquence
} catch HTMLSpecialCharactersError.notErrorMatchedUnicode(let code) {
return code
}
let testCount = 1000
let escape1 = """
func testUnescapePerformanceUsingException() {
self.measure {
for _ in 0..<self.testCount {
_ = self.escape1.unescapeHTML_usingException
}
}
}
func testUnescapePerformance() {
self.measure {
for _ in 0..<self.testCount {
_ = self.escape1.unescapeHTML
}
}
}
let escape100 = ""&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"&&apos;<"&&apos;<Ÿˆ"
func testUnescapePerformanceUsingExceptionFor100() {
self.measure {
for _ in 0..<self.testCount {
_ = self.escape100.unescapeHTML_usingException
}
}
}
func testUnescapePerformanceFor100() {
self.measure {
for _ in 0..<self.testCount {
_ = self.escape100.unescapeHTML
}
}
}