[CODE]#ifndef ADJUST_H
#define ADJUST_H
#include <list>
#include "Analyst.h"
struct indentStyle
{
char ch;
int count;
indentstyle(char c, int n)
: ch(c), count(n) {}
};
class Adjust
{
indentStyle indent;
public:
std::list<SingleLine> code;
Adjust(char c=' ', int n=3):indent(c,n) {}
void setIndent(char c, int n) { indent.ch=c; indent.count=n; }
void run(const std::string &str)
{
code.clear();
Analyst ana(str, code);
ana.analyze();
ana.analyzeEx();
}
void output(string &out)
{
char ch = indent.ch;
int count = indent.count;
std::list<SingleLine>::iterator code_iter = code.begin();
while(iter!=code.end())
{
std::list<SymbolNode>::iterator sline_iter = code_iter->line.begin();
out += std::string((code_iter->level)*count, ch); //缩进
//symbol
while(sline_iter!=code_iter->line.end())
{
out += sline_iter->str;
sline_iter++;
}
if(iter->line.size()!=0 && iter->remark.size()!=0)
out += ' ';
//remark
sline_iter = iter->remark.begin();
while(sline_iter!=iter->remark.end())
{
out += sline_iter->str;
sline_iter++;
}
out += '\n';
iter++;
}
}
};
#endif
[/CODE]
加上这个可能简单点,可以这样
......
string source;
......
string result;
Adjust adj;
adj.run(source);
adj.output(result);
......