Opentk/Source/Bind/BindStreamWriter.cs

66 lines
1.5 KiB
C#
Raw Normal View History

#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
2007-08-01 11:27:57 +02:00
using System.Collections.Generic;
using System.Text;
using System.IO;
using Bind.Structures;
using System.Text.RegularExpressions;
2007-08-01 11:27:57 +02:00
namespace Bind
{
class BindStreamWriter : StreamWriter
{
int indent_level = 0;
Regex splitLines = new Regex(System.Environment.NewLine, RegexOptions.Compiled);
2007-08-01 11:27:57 +02:00
public BindStreamWriter(string file)
: base(file)
{
}
public void Indent()
{
++indent_level;
2007-08-01 11:27:57 +02:00
}
public void Unindent()
{
if (indent_level > 0)
--indent_level;
2007-08-01 11:27:57 +02:00
}
public override void Write(string value)
{
for (int i = indent_level; i > 0; i--)
base.Write(" ");
base.Write(value);
2007-08-01 11:27:57 +02:00
}
public override void WriteLine(string value)
{
for (int i = indent_level; i > 0; i--)
base.Write(" ");
base.WriteLine(value);
2007-08-01 11:27:57 +02:00
}
public void Write(Bind.Structures.Enum e)
{
foreach (string s in splitLines.Split(e.ToString()))
WriteLine(s.TrimEnd('\r', '\n'));
2007-08-01 11:27:57 +02:00
}
public void Write(Bind.Structures.Function f)
{
foreach (string s in splitLines.Split(f.ToString()))
WriteLine(s);
2007-08-01 11:27:57 +02:00
}
}
}