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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

### Bug Fixes

_None_
* Improved format string regex to handle escaped "%"s that precede a variable
Copy link
Member

Choose a reason for hiding this comment

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

Please use the same format as the other entries (with . and 2 spaces at the end of the description).

[Tamas Lustyik](https://github.com/lvsti)
[#29](https://github.com/SwiftGen/SwiftGenKit/pull/29)

### Breaking Changes

Expand Down
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.

}

}