Skip to content

Conversation

@iuliux
Copy link
Contributor

@iuliux iuliux commented May 3, 2012

Added a new output substitution regex rule to handle String.format.

Turns this:

String.format("(%d) %s", i, s);

into this:

"(%d) %s" % (i, s)

Does not handle the whole Java specs about Formatter, like %1$d

Test case added.

@natural
Copy link
Owner

natural commented May 3, 2012

I'm fine with this, but it's going to have to get rewritten as an AST transformation. We just got bit by a bug where the regex didn't replace .length() properly when used inside an expression, and this might have similar problems.

Also, Format.java should be Format0.java, but I'll fix that.

natural pushed a commit that referenced this pull request May 3, 2012
Added regex sub rule for String.format
@natural natural merged commit 859a0bd into natural:master May 3, 2012
@Naddiseo
Copy link

Naddiseo commented May 3, 2012

Does not handle the whole Java specs about Formatter, like %1$d

"{1:d}".format() does though

@iuliux
Copy link
Contributor Author

iuliux commented May 4, 2012

Great. I'm investigating this correspondence. Pretty hairy it seems.

@iuliux
Copy link
Contributor Author

iuliux commented May 4, 2012

Would be great if you guys could find some time to review commit 6a8ded2
It's intended to be a first iteration for this feature. It satisfies the Format0 test case (updated).
(Are implemented argument index and conversion id.)

(And please suggest a better place for the helper func. formatSyntaxTransf(match))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants