Skip to content

Added regex sub rule for String.format - #18

Merged
natural merged 1 commit into
natural:masterfrom
iuliux:master
May 3, 2012
Merged

Added regex sub rule for String.format#18
natural merged 1 commit into
natural:masterfrom
iuliux:master

Conversation

@iuliux

@iuliux iuliux commented May 3, 2012

Copy link
Copy Markdown
Contributor

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

natural commented May 3, 2012

Copy link
Copy Markdown
Owner

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

Naddiseo commented May 3, 2012

Copy link
Copy Markdown

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

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

@iuliux

iuliux commented May 4, 2012

Copy link
Copy Markdown
Contributor Author

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

@iuliux

iuliux commented May 4, 2012

Copy link
Copy Markdown
Contributor Author

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