last day (14 days later) » 

06:02
10
Q: Reindent Java/C/C++/etc. code

tbodtWrite a program that adds or removes whitespace to format code nicely. Rules for what the code should look like when you're done: No line should contain more than one of { and }. A { should always be the last thing on a line. A } should always be the only thing on a line (besides whitespace tha...

Can you please add a few other examples, containing strings and comments that contain braces?
@ETHproductions The rules say both single and double quotes.
Whoops, missed that, sorry. That's what I get for rushing through the question :P
Do you care if we keep comments? The second example does not.
@ETHproductions whoops, fixing example
Add test case int test[] = {1, 2, 3};
06:02
@StephenS that one's not going to look right
@tbodt I know, I added it because of this: shouldn't the last semicolon go on its own line, since } can be the only char on a line? (for the expected output for that test case)
Can \\ appear in strings and if so how should it be treated? In particular, your current specification implies that the second " in "test\\" doesn't actually terminate the string.
@MartinEnder dammit...
Also, if /* */ can be nested (which I don't think they can in most C-family languages), you should include such a test case. You'll also want test cases with both types of comments in side strings or inside one another (in particular a line ending with // /* would be interesting).
what a can of worms...
@MartinEnder /**/ can be nested in C/C++
Rod
Rod
06:02
@Rod I don't think it's a dupe, that's a pop-con whose goal is "make the code look as pretty as possible", while this is "follow these prettifying rules in the shortest code possible".
tbodt they can not. if you have /*/**/*/ the final */ won't be commented.
@tuskiomi I WAS LIED TO
The indentation is how the programmer see the code, how to evidence the repetitions and the redundancy using spaces; it is not the work of the indentation program (the algorithm it is too much complex)
I do not agree on "•No line should contain more than one of { and }." I would say if the line length is not too much long it would be allowed (as for(i=0;i<n;++i){a[i]=i; b[i]=i+3;})...
@RosLuP This is a code-golf challenge, not a style manual :P
Can you please add a test-case with braces inside nested multiline comments (e.g. /* { /* { } */ } */)? I just realized mine failed on those cases.
06:02
Can you add a test case like this
@ConorO'Brien done
Is it OK to write an analogous pretty printer for/in a language that uses different tokens?
@Jasper no, but you could make your own challenge for such a language

last day (14 days later) »