The most common amounts of indention are 2 spaces, 4 spaces, and 8 spaces. It would be nice to let the user decide. You also have to account for different coding formats such as K&R or Allman, then consider indented brace formats. For example:
Code:
#include <iostream>
using namespace std;
int main ( void )
{ // Function opening brace, print and add 2 spaces
int i = 0, j = 4;
if ( i == 0 ) { // Conditional/loop beginning, add 2 spaces
cout<<"Fooby";
if ( j < 5 ) // Conditional/loop beginning, add 2 spaces
cout<<" is the best!";
// No opening brace, subtract 2 spaces after printing 1 line
} // Closing brace, subtract 2 spaces and print
cout<<endl;
return EXIT_SUCCESS;
} // Closing brace, subtract 2 spaces and print
Using both keywords and tokens to determine when to add or subtract spaces, and if a conditional or loop doesn't contain an opening brace then subtract the spaces after the next line. Opening braces you can set a flag after printing, but closing braces the flag would have to be set before printing or the closing brace would be indented incorrectly. How you set the flags is up to you though.
-Prelude