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
Merged

Fixed format string parsing #29

merged 9 commits into from
May 22, 2017

Conversation

lvsti
Copy link
Contributor

@lvsti lvsti commented Apr 30, 2017

The previous pattern would not match for "%%%foobar" (odd number of prefixing %'s) even though it is a valid format string.

Note that the new pattern has a slightly different behavior: the full match (i.e. matches.rangeAt(0)) now spans all preceding %'s of the placeholder, not just one (e.g. "%%%f" instead of just "%f"). As far as I see the full match is not used anywhere in the code, still, let me know if this is a problem and I can iterate on it.

…ly prefixed with an escaped %

The previous pattern would not match for "%%%foobar" even though it is a valid format string
Copy link
Member

@djbe djbe left a comment

Choose a reason for hiding this comment

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

Hi @lvsti,

I think I understand what you're getting at, our parser isn't seeing the %foobar in %%%foobar, right?

I tried your replacement, but from what I'm seeing, it matches too much? https://regex101.com/r/Vx7Xwo/1 Namely, it matches the following:

  • hello 1%ld --> 1%ld instead of %ld
  • hello %%%ld --> %%%ld instead of %ld

@djbe djbe added this to the 2.0.0 milestone May 8, 2017
@lvsti
Copy link
Contributor Author

lvsti commented May 13, 2017

nice catch! I simplified the regex and now it looks good for that particular case as well

Copy link
Member

@djbe djbe left a comment

Choose a reason for hiding this comment

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

Hi @lvsti,

Thank you for the updated commit. From some quick testing, the new regex seems to work correctly.

To finish up, could you please add a changelog entry crediting yourself (and mentioning this PR)? Please use the same format as the other entries (with . and 2 spaces at the end of the description).

@djbe djbe removed the status: WIP label May 14, 2017
CHANGELOG.md Outdated
@@ -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).

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.

@djbe djbe merged commit 26d23cf into SwiftGen:master May 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants