2009-02-22 11:43:35 +01:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2009-08-21 22:28:14 +02:00
|
|
|
|
using Bind.Structures;
|
|
|
|
|
using Enum=Bind.Structures.Enum;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
|
|
namespace Bind
|
|
|
|
|
{
|
|
|
|
|
class BindStreamWriter : StreamWriter
|
|
|
|
|
{
|
|
|
|
|
int indent_level = 0;
|
2009-08-21 22:28:14 +02:00
|
|
|
|
Regex splitLines = new Regex(Environment.NewLine, RegexOptions.Compiled);
|
2009-08-04 01:09:37 +02:00
|
|
|
|
//Regex splitLines = new Regex("(\r\n|\n\r|\n|\r)", RegexOptions.Compiled);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
|
|
public BindStreamWriter(string file)
|
|
|
|
|
: base(file)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Indent()
|
|
|
|
|
{
|
|
|
|
|
++indent_level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unindent()
|
|
|
|
|
{
|
|
|
|
|
if (indent_level > 0)
|
|
|
|
|
--indent_level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Write(string value)
|
|
|
|
|
{
|
|
|
|
|
for (int i = indent_level; i > 0; i--)
|
|
|
|
|
base.Write(" ");
|
|
|
|
|
|
|
|
|
|
base.Write(value);
|
|
|
|
|
}
|
2009-08-11 16:17:27 +02:00
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
|
public override void WriteLine(string value)
|
|
|
|
|
{
|
2009-08-11 16:17:27 +02:00
|
|
|
|
// Todo: it seems that spacing is not correct if this code
|
|
|
|
|
// is enabled on Linux/Mono. However, it works as it should on Windows/.Net.
|
|
|
|
|
// This could be related to line-ending differences, but I haven't been able to
|
|
|
|
|
// find the cause yet.
|
|
|
|
|
// This ugly workaround should work until the real cause is found.
|
|
|
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
|
|
|
|
|
Environment.OSVersion.Platform == PlatformID.Win32NT ||
|
|
|
|
|
Environment.OSVersion.Platform == PlatformID.Win32S ||
|
|
|
|
|
Environment.OSVersion.Platform == PlatformID.WinCE)
|
|
|
|
|
{
|
|
|
|
|
for (int i = indent_level; i > 0; i--)
|
|
|
|
|
base.Write(" ");
|
|
|
|
|
}
|
2009-08-12 10:33:49 +02:00
|
|
|
|
|
|
|
|
|
base.WriteLine(value);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
}
|
2009-08-11 16:17:27 +02:00
|
|
|
|
|
2009-08-21 22:28:14 +02:00
|
|
|
|
public void Write(Enum e)
|
2009-02-22 11:43:35 +01:00
|
|
|
|
{
|
|
|
|
|
foreach (string s in splitLines.Split(e.ToString()))
|
|
|
|
|
WriteLine(s.TrimEnd('\r', '\n'));
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-21 22:28:14 +02:00
|
|
|
|
public void Write(Function f)
|
2009-02-22 11:43:35 +01:00
|
|
|
|
{
|
|
|
|
|
foreach (string s in splitLines.Split(f.ToString()))
|
|
|
|
|
WriteLine(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|