From 5878c323a26d39ff7dd69217b86a28c2504e963d Mon Sep 17 00:00:00 2001 From: Ilya Puchka Date: Sun, 8 Oct 2017 01:53:41 +0200 Subject: [PATCH] fixed iterating over template lines on linux --- Sources/ForTag.swift | 2 +- Sources/Lexer.swift | 13 ++++++++----- Tests/StencilTests/EnvironmentSpec.swift | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/ForTag.swift b/Sources/ForTag.swift index 5eb181d..ae32479 100644 --- a/Sources/ForTag.swift +++ b/Sources/ForTag.swift @@ -87,7 +87,7 @@ class ForNode : NodeType { var values: [Any] if let dictionary = resolved as? [String: Any], !dictionary.isEmpty { - values = dictionary.map { ($0.key, $0.value) } + values = dictionary.map { ($0.key, $0.value) } as [(String, Any)] } else if let array = resolved as? [Any] { values = array } else if let range = resolved as? CountableClosedRange { diff --git a/Sources/Lexer.swift b/Sources/Lexer.swift index 51d8372..8d350e7 100644 --- a/Sources/Lexer.swift +++ b/Sources/Lexer.swift @@ -1,3 +1,5 @@ +import Foundation + struct Lexer { let templateString: String @@ -58,16 +60,17 @@ struct Lexer { var lineNumber: Int = 0 var offset = 0 var lineContent = "" - - templateString.enumerateLines { (line, stop) in + + for line in templateString.components(separatedBy: CharacterSet.newlines) { lineNumber += 1 lineContent = line - if let rangeOfLine = self.templateString.range(of: line), rangeOfLine.contains(lexeme.range.lowerBound) { - offset = self.templateString.distance(from: rangeOfLine.lowerBound, to: + if let rangeOfLine = templateString.range(of: line), rangeOfLine.contains(lexeme.range.lowerBound) { + offset = templateString.distance(from: rangeOfLine.lowerBound, to: lexeme.range.lowerBound) - stop = true + break } } + return (lineContent, lineNumber, offset) } diff --git a/Tests/StencilTests/EnvironmentSpec.swift b/Tests/StencilTests/EnvironmentSpec.swift index cebb73c..3b33a15 100644 --- a/Tests/StencilTests/EnvironmentSpec.swift +++ b/Tests/StencilTests/EnvironmentSpec.swift @@ -39,7 +39,6 @@ func testEnvironment() { error.lexeme = Token.block(value: token, at: template.templateString.range(of: token)!) let context = ErrorReporterContext(template: template) error = environment.errorReporter.contextAwareError(error, context: context) as! TemplateSyntaxError - print(error) return error }