Skip to content

Commit

Permalink
Merge pull request #181 from tid-kijyun/fix/ci
Browse files Browse the repository at this point in the history
Fix/ci
  • Loading branch information
tid-kijyun authored Mar 4, 2018
2 parents 25990ae + afc484a commit 4618869
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
4.0-dev
4.0.3

11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ matrix:
include:
- os: osx
language: objective-c
osx_image: xcode9
osx_image: xcode9.2
script:
- set -o pipefail
- xcodebuild build-for-testing test-without-building -scheme Kanna -configuration Release ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -scheme Kanna -configuration Release -sdk iphonesimulator -destination "name=iPhone 6s" ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -scheme Kanna -configuration Release -sdk appletvsimulator -destination "name=Apple TV 1080p" ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -scheme Kanna -configuration Release -sdk iphonesimulator -destination "name=iPhone 7" ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -scheme Kanna -configuration Release -sdk appletvsimulator -destination "name=Apple TV" ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild -scheme Kanna -configuration Release -sdk watchsimulator -destination "name=Apple Watch - 38mm"
- os: osx
language: generic
osx_image: xcode9
osx_image: xcode9.2
script:
- swift build
- swift test
Expand All @@ -26,8 +26,11 @@ matrix:
before_install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift --version
- swift build
- swift test
env:
- SWIFT_VERSION=4.0.3

notifications:
email: false
Expand Down
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ let package = Package(
"Tests/KannaTests/Data"
]),
.testTarget(name: "KannaTests",
dependencies: ["Kanna"],
path: "Tests"
),
dependencies: ["Kanna"]
)
]
)
83 changes: 71 additions & 12 deletions Sources/Kanna/libxmlHTMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,67 @@ import SwiftClibxml2
import libxml2
#endif

extension String.Encoding {
var IANACharSetName: String? {
#if os(Linux)
switch self {
case .ascii:
return "us-ascii"
case .iso2022JP:
return "iso-2022-jp"
case .isoLatin1:
return "iso-8859-1"
case .isoLatin2:
return "iso-8859-2"
case .japaneseEUC:
return "euc-jp"
case .macOSRoman:
return "macintosh"
case .nextstep:
return "x-nextstep"
case .nonLossyASCII:
return nil
case .shiftJIS:
return "cp932"
case .symbol:
return "x-mac-symbol"
case .unicode:
return "utf-16"
case .utf16:
return "utf-16"
case .utf16BigEndian:
return "utf-16be"
case .utf32:
return "utf-32"
case .utf32BigEndian:
return "utf-32be"
case .utf32LittleEndian:
return "utf-32le"
case .utf8:
return "utf-8"
case .windowsCP1250:
return "windows-1250"
case .windowsCP1251:
return "windows-1251"
case .windowsCP1252:
return "windows-1252"
case .windowsCP1253:
return "windows-1253"
case .windowsCP1254:
return "windows-1254"
default:
return nil
}
#else
let cfenc = CFStringConvertNSStringEncodingToEncoding(self.rawValue)
guard let cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc) else {
return nil
}
return String(describing: cfencstr)
#endif
}
}

/*
libxmlHTMLDocument
*/
Expand Down Expand Up @@ -105,16 +166,14 @@ internal final class libxmlHTMLDocument: HTMLDocument {
guard html.lengthOfBytes(using: encoding) > 0 else {
throw ParseError.Empty
}

let cfenc : CFStringEncoding = CFStringConvertNSStringEncodingToEncoding(encoding.rawValue)

guard let cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc),
guard let charsetName = encoding.IANACharSetName,
let cur = html.cString(using: encoding) else {
throw ParseError.EncodingMismatch
}

let url : String = ""
docPtr = htmlReadDoc(UnsafeRawPointer(cur).assumingMemoryBound(to: xmlChar.self), url, String(describing: cfencstr), CInt(option))
docPtr = htmlReadDoc(UnsafeRawPointer(cur).assumingMemoryBound(to: xmlChar.self), url, charsetName, CInt(option))

guard let docPtr = docPtr else {
throw ParseError.EncodingMismatch
Expand Down Expand Up @@ -238,15 +297,15 @@ internal final class libxmlXMLDocument: XMLDocument {
if xml.isEmpty {
throw ParseError.Empty
}
let cfenc : CFStringEncoding = CFStringConvertNSStringEncodingToEncoding(encoding.rawValue)
let cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc)
if let cur = xml.cString(using: encoding) {
let url : String = ""
docPtr = xmlReadDoc(UnsafeRawPointer(cur).assumingMemoryBound(to: xmlChar.self), url, String(describing: cfencstr!), CInt(option))
rootNode = libxmlHTMLNode(document: self, docPtr: docPtr!)
} else {
throw ParseError.EncodingMismatch


guard let charsetName = encoding.IANACharSetName,
let cur = xml.cString(using: encoding) else {
throw ParseError.EncodingMismatch
}
let url : String = ""
docPtr = xmlReadDoc(UnsafeRawPointer(cur).assumingMemoryBound(to: xmlChar.self), url, charsetName, CInt(option))
rootNode = libxmlHTMLNode(document: self, docPtr: docPtr!)
}

deinit {
Expand Down

0 comments on commit 4618869

Please sign in to comment.