Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region --- License ---
2
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
3
 * See license.txt for license info
4
 */
5
#endregion
6
 
7
using System;
8
using System.IO;
9
using System.Text.RegularExpressions;
10
using Bind.Structures;
11
using Enum=Bind.Structures.Enum;
12
 
13
namespace Bind
14
{
15
    class BindStreamWriter : StreamWriter
16
    {
17
        int indent_level = 0;
18
        Regex splitLines = new Regex(Environment.NewLine, RegexOptions.Compiled);
19
        //Regex splitLines = new Regex("(\r\n|\n\r|\n|\r)", RegexOptions.Compiled);
20
 
21
        public BindStreamWriter(string file)
22
            : base(file)
23
        {
24
        }
25
 
26
        public void Indent()
27
        {
28
            ++indent_level;
29
        }
30
 
31
        public void Unindent()
32
        {
33
            if (indent_level > 0)
34
                --indent_level;
35
        }
36
 
37
        public override void Write(string value)
38
        {
39
            for (int i = indent_level; i > 0; i--)
40
                base.Write("    ");
41
 
42
            base.Write(value);
43
        }
44
 
45
        public override void WriteLine(string value)
46
        {
47
            // Todo: it seems that spacing is not correct if this code
48
            // is enabled on Linux/Mono. However, it works as it should on Windows/.Net.
49
            // This could be related to line-ending differences, but I haven't been able to
50
            // find the cause yet.
51
            // This ugly workaround should work until the real cause is found.
52
            if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
53
                Environment.OSVersion.Platform == PlatformID.Win32NT ||
54
                Environment.OSVersion.Platform == PlatformID.Win32S ||
55
                Environment.OSVersion.Platform == PlatformID.WinCE)
56
            {
57
                for (int i = indent_level; i > 0; i--)
58
                    base.Write("    ");
59
            }
60
 
61
            base.WriteLine(value);
62
        }
63
 
64
        public void Write(Enum e)
65
        {
66
            foreach (string s in splitLines.Split(e.ToString()))
67
                WriteLine(s.TrimEnd('\r', '\n'));
68
        }
69
 
70
        public void Write(Function f)
71
        {
72
            foreach (string s in splitLines.Split(f.ToString()))
73
                WriteLine(s);
74
        }
75
    }
76
}