Updates to swift 4

* Remove obsolete methods used in `hashValue` methods; normalizing all implementations.
* Fix warnings about redundant protocol conformance
* Removed “linux” definition of `NSTextCheckingResult.range(at:)` because Swift 4 defines it
* Updated project settings to Swift 4
This commit is contained in:
Kevin Wooten 2017-08-02 20:25:48 -07:00
parent fc36504cc3
commit 00ca92c422
9 changed files with 54 additions and 41 deletions

View File

@ -1288,9 +1288,10 @@ open class Element: Node {
}
override public var hashValue: Int {
var h = super.hashValue
h = Int.addWithOverflow(Int.multiplyWithOverflow(31, h).0, _tag.hashValue).0
return h
let prime = 31
var result = super.hashValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_tag.hashValue).partialValue
return result
}
}

View File

@ -771,8 +771,10 @@ open class Node: Equatable, Hashable {
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
public var hashValue: Int {
var result: Int = description.hashValue
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, baseUri != nil ? baseUri!.hashValue : 31).0
let prime = 31
var result = 1
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(description.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(baseUri?.hashValue ?? 31).partialValue
return result
}

View File

@ -399,31 +399,31 @@ public struct OrderedSetGenerator<T: Hashable>: IteratorProtocol {
extension OrderedSetGenerator where T: Comparable {}
public func +<T: Hashable, S: Sequence> (lhs: OrderedSet<T>, rhs: S) -> OrderedSet<T> where S.Iterator.Element == T {
public func +<T, S: Sequence> (lhs: OrderedSet<T>, rhs: S) -> OrderedSet<T> where S.Iterator.Element == T {
let joinedSet = lhs
joinedSet.append(contentsOf: rhs)
return joinedSet
}
public func +=<T: Hashable, S: Sequence> (lhs: inout OrderedSet<T>, rhs: S) where S.Iterator.Element == T {
public func +=<T, S: Sequence> (lhs: inout OrderedSet<T>, rhs: S) where S.Iterator.Element == T {
lhs.append(contentsOf: rhs)
}
public func -<T: Hashable, S: Sequence> (lhs: OrderedSet<T>, rhs: S) -> OrderedSet<T> where S.Iterator.Element == T {
public func -<T, S: Sequence> (lhs: OrderedSet<T>, rhs: S) -> OrderedSet<T> where S.Iterator.Element == T {
let purgedSet = lhs
purgedSet.remove(rhs)
return purgedSet
}
public func -=<T: Hashable, S: Sequence> (lhs: inout OrderedSet<T>, rhs: S) where S.Iterator.Element == T {
public func -=<T, S: Sequence> (lhs: inout OrderedSet<T>, rhs: S) where S.Iterator.Element == T {
lhs.remove(rhs)
}
extension OrderedSet: Equatable { }
public func ==<T: Hashable> (lhs: OrderedSet<T>, rhs: OrderedSet<T>) -> Bool {
public func ==<T> (lhs: OrderedSet<T>, rhs: OrderedSet<T>) -> Bool {
if lhs.count != rhs.count {
return false
}

View File

@ -8,14 +8,6 @@
import Foundation
#if !os(Linux)
extension NSTextCheckingResult {
func range(at idx: Int) -> NSRange {
return rangeAt(idx)
}
}
#endif
public struct Pattern {
public static let CASE_INSENSITIVE: Int = 0x02
let pattern: String

View File

@ -235,16 +235,18 @@ open class Tag: Hashable {
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
public var hashValue: Int {
var result: Int = _tagName.hashValue
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _isBlock ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _formatAsBlock ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _canContainBlock ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _canContainInline ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _empty ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _selfClosing ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _preserveWhitespace ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _formList ? 1 : 0).0
result = Int.addWithOverflow(Int.multiplyWithOverflow(31, result).0, _formSubmit ? 1 : 0).0
let prime = 31
var result = 1
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_tagName.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_isBlock.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_formatAsBlock.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_canContainBlock.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_canContainInline.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_empty.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_selfClosing.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_preserveWhitespace.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_formList.hashValue).partialValue
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(_formSubmit.hashValue).partialValue
return result
}

View File

@ -15,7 +15,7 @@ open class Token {
}
func tokenType() -> String {
return String(describing: type(of: self))
return String(describing: Swift.type(of: self))
}
/**
@ -32,7 +32,7 @@ open class Token {
}
open func toString()throws->String {
return String(describing: type(of: self))
return String(describing: Swift.type(of: self))
}
final class Doctype: Token {

View File

@ -642,7 +642,7 @@ extension TypedValue: Hashable {
public var hashValue: Int {
let prime = 31
var result = 1
result = Int.addWithOverflow(Int.multiplyWithOverflow(prime, result).0, value.hash).0
result = prime.multipliedReportingOverflow(by: result).partialValue.addingReportingOverflow(value.hash).partialValue
return result
}
}

View File

@ -331,7 +331,9 @@
8CE418231DAA54A900240B42 /* Tests */,
8CE418171DAA54A900240B42 /* Products */,
);
indentWidth = 4;
sourceTree = "<group>";
tabWidth = 4;
};
8CE418171DAA54A900240B42 /* Products */ = {
isa = PBXGroup;
@ -476,18 +478,18 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Nabil Chatbi";
TargetAttributes = {
8CE418151DAA54A900240B42 = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
8CE4181E1DAA54A900240B42 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 69CKJW5DBB;
LastSwiftMigration = 0820;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
};
@ -644,7 +646,9 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
@ -652,7 +656,11 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
@ -683,6 +691,8 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
@ -698,7 +708,9 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
@ -706,7 +718,11 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
@ -729,6 +745,8 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
@ -759,7 +777,6 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@ -785,7 +802,6 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_VERSION = 3.0;
};
name = Release;
};
@ -805,7 +821,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@ -824,7 +839,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.scinfu.SwiftSoupTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
};
name = Release;
};

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"