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