Rev | Line | |
---|
[10100] | 1 | using System.Collections.Generic;
|
---|
| 2 | using System.Diagnostics;
|
---|
| 3 | using System.IO;
|
---|
| 4 | using System.Linq;
|
---|
| 5 | using System.Text;
|
---|
| 6 | using HeuristicLab.Grammars;
|
---|
| 7 | using Attribute = HeuristicLab.Grammars.Attribute;
|
---|
| 8 |
|
---|
| 9 | namespace CodeGenerator {
|
---|
| 10 | public class SourceBuilder {
|
---|
| 11 | private readonly StringBuilder sb;
|
---|
| 12 | private int indent;
|
---|
| 13 | public SourceBuilder() {
|
---|
| 14 | sb = new StringBuilder();
|
---|
| 15 | indent = 0;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public SourceBuilder BeginBlock() {
|
---|
| 19 | indent += 2;
|
---|
| 20 | return AppendLine();
|
---|
| 21 | }
|
---|
| 22 | public SourceBuilder EndBlock() {
|
---|
| 23 | indent -= 2;
|
---|
| 24 | return AppendLine();
|
---|
| 25 | }
|
---|
| 26 | public SourceBuilder Append(string str) {
|
---|
| 27 | sb.Append(' ', indent).Append(str);
|
---|
| 28 | return this;
|
---|
| 29 | }
|
---|
| 30 | public SourceBuilder AppendFormat(string fmtString, params object[] args) {
|
---|
| 31 | sb.Append(' ', indent).AppendFormat(fmtString, args);
|
---|
| 32 | return this;
|
---|
| 33 | }
|
---|
| 34 | public SourceBuilder AppendLine() {
|
---|
[10385] | 35 | sb.Append(' ', indent).AppendLine();
|
---|
[10100] | 36 | return this;
|
---|
| 37 | }
|
---|
| 38 | public SourceBuilder AppendLine(string str) {
|
---|
[10385] | 39 | sb.Append(' ', indent).AppendLine(str);
|
---|
[10100] | 40 | return this;
|
---|
| 41 | }
|
---|
| 42 | public SourceBuilder Replace(string oldValue, string newValue) {
|
---|
| 43 | sb.Replace(oldValue, newValue);
|
---|
| 44 | return this;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public override string ToString() {
|
---|
| 48 | return sb.ToString();
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.