mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-08 10:00:34 +00:00
[Bind] Add NoIndent option to BindStreamWriter
This commit is contained in:
parent
61791c91db
commit
570d08fff1
|
@ -35,6 +35,12 @@ using Enum=Bind.Structures.Enum;
|
||||||
|
|
||||||
namespace Bind
|
namespace Bind
|
||||||
{
|
{
|
||||||
|
enum WriteOptions
|
||||||
|
{
|
||||||
|
Default = 0,
|
||||||
|
NoIndent = 1
|
||||||
|
}
|
||||||
|
|
||||||
class BindStreamWriter : IDisposable
|
class BindStreamWriter : IDisposable
|
||||||
{
|
{
|
||||||
static readonly char[] SplitCharacters = new char[] { '\r', '\n' };
|
static readonly char[] SplitCharacters = new char[] { '\r', '\n' };
|
||||||
|
@ -60,7 +66,7 @@ namespace Bind
|
||||||
--indent_level;
|
--indent_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(string value)
|
public void Write(WriteOptions options, string value)
|
||||||
{
|
{
|
||||||
var lines = value.Split(SplitCharacters,
|
var lines = value.Split(SplitCharacters,
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
@ -71,24 +77,34 @@ namespace Bind
|
||||||
for (int i = 0; i < lines.Length - 1; i++)
|
for (int i = 0; i < lines.Length - 1; i++)
|
||||||
{
|
{
|
||||||
var line = lines[i];
|
var line = lines[i];
|
||||||
WriteIndentations();
|
WriteIndentations(options);
|
||||||
sw.Write(line);
|
sw.Write(line);
|
||||||
sw.Write(System.Environment.NewLine);
|
sw.Write(System.Environment.NewLine);
|
||||||
}
|
}
|
||||||
// Write the last line without appending a newline
|
// Write the last line without appending a newline
|
||||||
WriteIndentations();
|
WriteIndentations(options);
|
||||||
sw.Write(lines[lines.Length - 1]);
|
sw.Write(lines[lines.Length - 1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteIndentations();
|
WriteIndentations(options);
|
||||||
sw.Write(value);
|
sw.Write(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Write(WriteOptions options, string format, params object[] args)
|
||||||
|
{
|
||||||
|
Write(options, String.Format(format, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(string value)
|
||||||
|
{
|
||||||
|
Write(WriteOptions.Default, value);
|
||||||
|
}
|
||||||
|
|
||||||
public void Write(string format, params object[] args)
|
public void Write(string format, params object[] args)
|
||||||
{
|
{
|
||||||
Write(String.Format(format, args));
|
Write(WriteOptions.Default, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteLine()
|
public void WriteLine()
|
||||||
|
@ -96,15 +112,26 @@ namespace Bind
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WriteLine(WriteOptions options, string value)
|
||||||
|
{
|
||||||
|
Write(options, value);
|
||||||
|
WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteLine(WriteOptions options, string format, params object[] args)
|
||||||
|
{
|
||||||
|
WriteLine(options, String.Format(format, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void WriteLine(string value)
|
public void WriteLine(string value)
|
||||||
{
|
{
|
||||||
Write(value);
|
WriteLine(WriteOptions.Default, value);
|
||||||
WriteLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteLine(string format, params object[] args)
|
public void WriteLine(string format, params object[] args)
|
||||||
{
|
{
|
||||||
WriteLine(String.Format(format, args));
|
WriteLine(WriteOptions.Default, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Flush()
|
public void Flush()
|
||||||
|
@ -117,11 +144,14 @@ namespace Bind
|
||||||
sw.Close();
|
sw.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteIndentations()
|
void WriteIndentations(WriteOptions options)
|
||||||
|
{
|
||||||
|
if (options != WriteOptions.NoIndent)
|
||||||
{
|
{
|
||||||
for (int i = indent_level; i > 0; i--)
|
for (int i = indent_level; i > 0; i--)
|
||||||
sw.Write(" ");
|
sw.Write(" ");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue