forked from mono/Embeddinator-4000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcewriter.cs
73 lines (61 loc) · 1.24 KB
/
sourcewriter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.IO;
using System.Text;
namespace Embeddinator.ObjC {
public class SourceWriter : TextWriter {
StringBuilder sb = new StringBuilder ();
bool newline = true;
public bool Enabled { get; set; } = true;
public int Indent { get; set; }
public override Encoding Encoding => Encoding.UTF8;
void ApplyTabs ()
{
if (newline) {
for (int i = 0; i < Indent; i++)
sb.Append ('\t');
newline = false;
}
}
// minimum to override - see http://msdn.microsoft.com/en-us/library/system.io.textwriter.aspx
public override void Write (char value)
{
if (!Enabled)
return;
ApplyTabs ();
sb.Append (value);
}
public override void WriteLine ()
{
if (!Enabled)
return;
sb.AppendLine ();
newline = true;
}
public override void WriteLine (string value)
{
if (!Enabled)
return;
ApplyTabs ();
sb.AppendLine (value);
newline = true;
}
public override void Write (string value)
{
if (!Enabled)
return;
ApplyTabs ();
sb.Append (value);
}
public void WriteLineUnindented (string value)
{
if (!Enabled)
return;
sb.AppendLine (value);
newline = true;
}
public override string ToString ()
{
return sb.ToString ();
}
}
}