Add support for Swift 3.0

This commit is contained in:
Kyle Fuller
2016-09-13 19:09:58 +01:00
parent f393efbd0b
commit feff3b18b1
41 changed files with 252 additions and 229 deletions

View File

@@ -2,7 +2,7 @@ import Foundation
/// Split a string by spaces leaving quoted phrases together
func smartSplit(value: String) -> [String] {
func smartSplit(_ value: String) -> [String] {
var word = ""
var separator: Character = " "
var components: [String] = []
@@ -37,40 +37,40 @@ func smartSplit(value: String) -> [String] {
public enum Token : Equatable {
/// A token representing a piece of text.
case Text(value: String)
case text(value: String)
/// A token representing a variable.
case Variable(value: String)
case variable(value: String)
/// A token representing a comment.
case Comment(value: String)
case comment(value: String)
/// A token representing a template block.
case Block(value: String)
case block(value: String)
/// Returns the underlying value as an array seperated by spaces
public func components() -> [String] {
switch self {
case .Block(let value):
case .block(let value):
return smartSplit(value)
case .Variable(let value):
case .variable(let value):
return smartSplit(value)
case .Text(let value):
case .text(let value):
return smartSplit(value)
case .Comment(let value):
case .comment(let value):
return smartSplit(value)
}
}
public var contents: String {
switch self {
case .Block(let value):
case .block(let value):
return value
case .Variable(let value):
case .variable(let value):
return value
case .Text(let value):
case .text(let value):
return value
case .Comment(let value):
case .comment(let value):
return value
}
}
@@ -79,13 +79,13 @@ public enum Token : Equatable {
public func == (lhs: Token, rhs: Token) -> Bool {
switch (lhs, rhs) {
case (.Text(let lhsValue), .Text(let rhsValue)):
case (.text(let lhsValue), .text(let rhsValue)):
return lhsValue == rhsValue
case (.Variable(let lhsValue), .Variable(let rhsValue)):
case (.variable(let lhsValue), .variable(let rhsValue)):
return lhsValue == rhsValue
case (.Block(let lhsValue), .Block(let rhsValue)):
case (.block(let lhsValue), .block(let rhsValue)):
return lhsValue == rhsValue
case (.Comment(let lhsValue), .Comment(let rhsValue)):
case (.comment(let lhsValue), .comment(let rhsValue)):
return lhsValue == rhsValue
default:
return false