[Variable] Use Swift split over Foundation
This commit is contained in:
@@ -6,7 +6,7 @@ class FilterExpression : Resolvable {
|
|||||||
let variable: Variable
|
let variable: Variable
|
||||||
|
|
||||||
init(token: String, parser: TokenParser) throws {
|
init(token: String, parser: TokenParser) throws {
|
||||||
let bits = token.componentsSeparatedByString("|")
|
let bits = token.characters.split("|").map(String.init)
|
||||||
if bits.isEmpty {
|
if bits.isEmpty {
|
||||||
filters = []
|
filters = []
|
||||||
variable = Variable("")
|
variable = Variable("")
|
||||||
@@ -35,19 +35,19 @@ class FilterExpression : Resolvable {
|
|||||||
|
|
||||||
/// A structure used to represent a template variable, and to resolve it in a given context.
|
/// A structure used to represent a template variable, and to resolve it in a given context.
|
||||||
public struct Variable : Equatable, Resolvable {
|
public struct Variable : Equatable, Resolvable {
|
||||||
public let variable:String
|
public let variable: String
|
||||||
|
|
||||||
/// Create a variable with a string representing the variable
|
/// Create a variable with a string representing the variable
|
||||||
public init(_ variable:String) {
|
public init(_ variable: String) {
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
}
|
}
|
||||||
|
|
||||||
private func lookup() -> [String] {
|
private func lookup() -> [String] {
|
||||||
return variable.componentsSeparatedByString(".")
|
return variable.characters.split(".").map(String.init)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the variable in the given context
|
/// Resolve the variable in the given context
|
||||||
public func resolve(context:Context) throws -> Any? {
|
public func resolve(context: Context) throws -> Any? {
|
||||||
var current: Any? = context
|
var current: Any? = context
|
||||||
|
|
||||||
if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) {
|
if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) {
|
||||||
@@ -93,6 +93,6 @@ public struct Variable : Equatable, Resolvable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func ==(lhs:Variable, rhs:Variable) -> Bool {
|
public func ==(lhs: Variable, rhs: Variable) -> Bool {
|
||||||
return lhs.variable == rhs.variable
|
return lhs.variable == rhs.variable
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user