Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL/CodeGenerator/SourceBuilder.cs @ 16147

Last change on this file since 16147 was 10385, checked in by gkronber, 11 years ago

#2026 removed commented code and improved layout

File size: 1.3 KB
RevLine 
[10100]1using System.Collections.Generic;
2using System.Diagnostics;
3using System.IO;
4using System.Linq;
5using System.Text;
6using HeuristicLab.Grammars;
7using Attribute = HeuristicLab.Grammars.Attribute;
8
9namespace 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.