2 // Helper for Console to allow indirect access to `stdout` using NSLog
5 // Sebastien Pouliot <sebastien@xamarin.com>
7 // Copyright 2012-2013 Xamarin Inc. All rights reserved.
14 using System.Runtime.InteropServices;
19 public static partial class Console {
21 class NSLogWriter : TextWriter {
23 [DllImport ("__Internal", CharSet=CharSet.Unicode)]
24 extern static void monotouch_log (string s);
30 sb = new StringBuilder ();
33 public override System.Text.Encoding Encoding {
34 get { return System.Text.Encoding.UTF8; }
37 public override void Flush ()
40 monotouch_log (sb.ToString ());
47 // minimum to override - see http://msdn.microsoft.com/en-us/library/system.io.textwriter.aspx
48 public override void Write (char value)
57 // optimization (to avoid concatening chars)
58 public override void Write (string value)
62 if (value != null && value.Length >= CoreNewLine.Length && EndsWithNewLine (value))
69 bool EndsWithNewLine (string value)
71 for (int i = 0, v = value.Length - CoreNewLine.Length; i < CoreNewLine.Length; ++i, ++v) {
72 if (value [v] != CoreNewLine [i])
79 public override void WriteLine ()