raydac / java-comment-preprocessor

preprocessor for computer languages with C-like comment format (C/C++/Java/Go)
Apache License 2.0
172 stars 27 forks source link

Add preserve-indent command line directive #15

Closed jamuir closed 7 years ago

jamuir commented 7 years ago

Use /PI to tell JCP to preserve line indentation when processing line-prefixes //$ and //$$. When /PI is specified, then "//$" gets replaced with three spaces, and "//$$" gets replaced with four spaces.

raydac commented 7 years ago

looks great, thank you very much, but it doesn't cover case isAllowWhitespace() = true ? if a user turns on the mode (through /ES) then he will get unexpected behaviour

jamuir commented 7 years ago

Good point.

I thought it was safe to ignore the "/ES" switch, but if you specify both "/ES" and "/PI" then "//$" won't get replaced with three spaces.

I think I know how to fix this. I will update the PR.

cheers.

jamuir commented 7 years ago

Another approach would be to not allow both "/ES" and "/PI" to be specified. If I cannot figure out a good way to implement "/ES" and "/PI" together, then I will use that as my Plan B :-)

jamuir commented 7 years ago

@raydac: I've updated the PR.

Now when /PI is specified, a dollar-sign prefix string s will be replaced with a string composed of s.length() spaces. E.g. when both /PI and /ES are set, then

"//   $$" is replaced with 7 spaces
"// $"    is replaced with 4 spaces
"//$$"    is replaced with 4 spaces
"//$"     is replaced with 3 spaces

and so on.