mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 01:15:26 +00:00
Fixed newline and indentation behavior
Mono and .Net have a few minor differences in their StreamWriter implementations. Added workarounds to produce identical output on all platforms.
This commit is contained in:
parent
b7f2379f87
commit
add848f32d
|
@ -1,7 +1,30 @@
|
||||||
#region --- License ---
|
#region License
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
//
|
||||||
* See license.txt for license info
|
// The Open Toolkit Library License
|
||||||
*/
|
//
|
||||||
|
// Copyright (c) 2006 - 2013 Stefanos Apostolopoulos for the Open Toolkit Library
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
@ -39,39 +62,48 @@ namespace Bind
|
||||||
|
|
||||||
public override void Write(string value)
|
public override void Write(string value)
|
||||||
{
|
{
|
||||||
bool is_multiline = false;
|
var lines = splitLines.Split(value);
|
||||||
foreach (var line in splitLines.Split(value))
|
bool is_multiline = lines.Length > 1;
|
||||||
|
if (is_multiline)
|
||||||
{
|
{
|
||||||
base.Write(line);
|
// Write all internal lines
|
||||||
base.Write(System.Environment.NewLine);
|
for (int i = 0; i < lines.Length - 1; i++)
|
||||||
is_multiline = true;
|
{
|
||||||
|
var line = lines[i];
|
||||||
|
WriteIndentations();
|
||||||
|
base.Write(line);
|
||||||
|
base.Write(System.Environment.NewLine);
|
||||||
|
}
|
||||||
|
// Write the last line without appending a newline
|
||||||
|
WriteIndentations();
|
||||||
|
base.Write(lines[lines.Length - 1]);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (!is_multiline)
|
|
||||||
{
|
{
|
||||||
for (int i = indent_level; i > 0; i--)
|
WriteIndentations();
|
||||||
base.Write(" ");
|
|
||||||
base.Write(value);
|
base.Write(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteLine(string value)
|
public override void WriteLine(string value)
|
||||||
{
|
{
|
||||||
// Todo: it seems that spacing is not correct if this code
|
// The Mono implementation of WriteLine calls Write internally.
|
||||||
// is enabled on Linux/Mono. However, it works as it should on Windows/.Net.
|
// The .Net implementation does not.
|
||||||
// This could be related to line-ending differences, but I haven't been able to
|
// If running on Mono, we must avoid indenting in WriteLine
|
||||||
// find the cause yet.
|
// because then we'll indent twice (once in WriteLine and once in Write).
|
||||||
// This ugly workaround should work until the real cause is found.
|
// If running on .Net we must indent in both WriteLine and Write.
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
|
// Neat, no?
|
||||||
Environment.OSVersion.Platform == PlatformID.Win32NT ||
|
if (System.Type.GetType("Mono.Runtime") == null)
|
||||||
Environment.OSVersion.Platform == PlatformID.Win32S ||
|
|
||||||
Environment.OSVersion.Platform == PlatformID.WinCE)
|
|
||||||
{
|
{
|
||||||
for (int i = indent_level; i > 0; i--)
|
WriteIndentations();
|
||||||
base.Write(" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base.WriteLine(value);
|
base.WriteLine(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteIndentations()
|
||||||
|
{
|
||||||
|
for (int i = indent_level; i > 0; i--)
|
||||||
|
base.Write(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue