Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Fixed format string parsing #29

Merged
merged 9 commits into from
May 22, 2017
2 changes: 1 addition & 1 deletion Sources/Parsers/StringsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public final class StringsFileParser {

do {
return try NSRegularExpression(
pattern: "(?<!%)%\(position)\(precision)(@|\(pattern_int)|\(pattern_float)|[csp])",
pattern: "(?:^|[^%]|(?<!%)(?:%%)+)%\(position)\(precision)(@|\(pattern_int)|\(pattern_float)|[csp])",
options: [.caseInsensitive]
)
} catch {
Expand Down
8 changes: 7 additions & 1 deletion Tests/SwiftGenKitTests/StringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ class StringsTests: XCTestCase {
XCTAssertEqual(placeholders, [.Unknown, .Int, .Object, .Float, .Char])
}

func testParseEscapePercentSign() {
func testParseEvenEscapePercentSign() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%%foo")
// Must NOT map to [.Float]
XCTAssertEqual(placeholders, [])
}

func testParseOddEscapePercentSign() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%%%foo")
// Should map to [.Float]
XCTAssertEqual(placeholders, [.Float])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so your branch was based on an older version of SwiftGenKit. This needs to be .float instead.

}

}