Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added regex sub rule for String.format #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2012
Merged

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