diff --git a/Sources/ForTag.swift b/Sources/ForTag.swift index 284498f..e2969a7 100644 --- a/Sources/ForTag.swift +++ b/Sources/ForTag.swift @@ -23,7 +23,7 @@ class ForNode : NodeType { throw TemplateSyntaxError("'for' statements should use the syntax: `for in [where ]`.") } - let loopVariables = components[1].characters + let loopVariables = components[1] .split(separator: ",") .map(String.init) .map { $0.trim(character: " ") } diff --git a/Sources/Inheritence.swift b/Sources/Inheritence.swift index db2d67f..c276d10 100644 --- a/Sources/Inheritence.swift +++ b/Sources/Inheritence.swift @@ -64,7 +64,7 @@ class ExtendsNode : NodeType { throw TemplateSyntaxError("'extends' cannot appear more than once in the same template") } - let blockNodes = parsedNodes.flatMap { $0 as? BlockNode } + let blockNodes = parsedNodes.compactMap { $0 as? BlockNode } let nodes = blockNodes.reduce([String: BlockNode]()) { (accumulator, node) -> [String: BlockNode] in var dict = accumulator @@ -159,8 +159,8 @@ class BlockNode : NodeType { } // child node is a block node from child template that extends this node (has the same name) - func childContext(_ child: BlockNode, blockContext: BlockContext, context: Context) throws -> [String: Any?] { - var childContext: [String: Any?] = [BlockContext.contextKey: blockContext] + func childContext(_ child: BlockNode, blockContext: BlockContext, context: Context) throws -> [String: Any] { + var childContext: [String: Any] = [BlockContext.contextKey: blockContext] if let blockSuperNode = child.nodes.first(where: { if case .variable(let variable, _)? = $0.token, variable == "block.super" { return true } diff --git a/Sources/KeyPath.swift b/Sources/KeyPath.swift index 445ef29..7728dcf 100644 --- a/Sources/KeyPath.swift +++ b/Sources/KeyPath.swift @@ -24,7 +24,7 @@ final class KeyPath { subscriptLevel = 0 } - for c in variable.characters { + for c in variable { switch c { case "." where subscriptLevel == 0: try foundSeparator() diff --git a/Sources/Parser.swift b/Sources/Parser.swift index b36f160..817b5fd 100644 --- a/Sources/Parser.swift +++ b/Sources/Parser.swift @@ -108,7 +108,7 @@ public class TokenParser { let filtersWithDistance = allFilters .map({ (filterName: $0, distance: $0.levenshteinDistance(name)) }) // do not suggest filters which names are shorter than the distance - .filter({ $0.filterName.characters.count > $0.distance }) + .filter({ $0.filterName.count > $0.distance }) guard let minDistance = filtersWithDistance.min(by: { $0.distance < $1.distance })?.distance else { return [] } @@ -167,10 +167,10 @@ extension String { // initialize v0 (the previous row of distances) // this row is A[0][i]: edit distance for an empty s // the distance is just the number of characters to delete from t - last = [Int](0...target.characters.count) - current = [Int](repeating: 0, count: target.characters.count + 1) + last = [Int](0...target.count) + current = [Int](repeating: 0, count: target.count + 1) - for i in 0.. 0 { - if let precedingChar = components.last?.characters.last, specialCharacters.characters.contains(precedingChar) { + if let precedingChar = components.last?.last, specialCharacters.contains(precedingChar) { components[components.count-1] += word } else if specialCharacters.contains(word) { components[components.count-1] += word @@ -25,7 +25,7 @@ extension String { } } - for character in self.characters { + for character in self { if character == "'" { singleQuoteCount += 1 } else if character == "\"" { doubleQuoteCount += 1 } diff --git a/Sources/Variable.swift b/Sources/Variable.swift index 1da7439..7c24e8a 100644 --- a/Sources/Variable.swift +++ b/Sources/Variable.swift @@ -9,7 +9,7 @@ class FilterExpression : Resolvable { let variable: Variable init(token: String, parser: TokenParser) throws { - let bits = token.characters.split(separator: "|").map({ String($0).trim(character: " ") }) + let bits = token.split(separator: "|").map({ String($0).trim(character: " ") }) if bits.isEmpty { throw TemplateSyntaxError("Variable tags must include at least 1 argument") } @@ -60,7 +60,7 @@ public struct Variable : Equatable, Resolvable { if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) { // String literal - return String(variable[variable.characters.index(after: variable.startIndex) ..< variable.characters.index(before: variable.endIndex)]) + return String(variable[variable.index(after: variable.startIndex) ..< variable.index(before: variable.endIndex)]) } // Number literal diff --git a/Tests/StencilTests/ForNodeSpec.swift b/Tests/StencilTests/ForNodeSpec.swift index ddb7692..084dc51 100644 --- a/Tests/StencilTests/ForNodeSpec.swift +++ b/Tests/StencilTests/ForNodeSpec.swift @@ -189,7 +189,7 @@ func testForNode() { let template = Template(templateString: templateString) let result = try template.render(context) - let sortedResult = result.characters.split(separator: ",").map(String.init).sorted(by: <) + let sortedResult = result.split(separator: ",").map(String.init).sorted(by: <) try expect(sortedResult) == ["one: I", "two: II"] } @@ -202,7 +202,7 @@ func testForNode() { let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key"], nodes: nodes, emptyNodes: emptyNodes, where: nil) let result = try node.render(context) - let sortedResult = result.characters.split(separator: ",").map(String.init).sorted(by: <) + let sortedResult = result.split(separator: ",").map(String.init).sorted(by: <) try expect(sortedResult) == ["one", "two"] } @@ -218,7 +218,7 @@ func testForNode() { let result = try node.render(context) - let sortedResult = result.characters.split(separator: ",").map(String.init).sorted(by: <) + let sortedResult = result.split(separator: ",").map(String.init).sorted(by: <) try expect(sortedResult) == ["one=I", "two=II"] }