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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* Fixed color's hex value rounding error.
[Yusuke Onishi](https://github.com/yusuke024)
[#19](https://github.com/SwiftGen/SwiftGenKit/pull/19)
* Improved format string regex to handle escaped "%"s that precede a variable.
[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
9 changes: 7 additions & 2 deletions Tests/SwiftGenKitTests/StringParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ class StringParserTests: XCTestCase {
XCTAssertEqual(placeholders, [.unknown, .int, .object, .float, .char])
}

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

func testParseOddEscapePercentSign() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%%%foo")
// Should map to [.float]
XCTAssertEqual(placeholders, [.float])
}
}
1 change: 0 additions & 1 deletion Tests/SwiftGenKitTests/StringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import SwiftGenKit
*/

class StringsTests: XCTestCase {

func testEmpty() {
let parser = StringsFileParser()

Expand Down