Internal.Console.Write uses unicode encoding for iOS (#78974)
authorMilos Kotlar <kotlarmilos@gmail.com>
Wed, 30 Nov 2022 12:53:26 +0000 (13:53 +0100)
committerGitHub <noreply@github.com>
Wed, 30 Nov 2022 12:53:26 +0000 (13:53 +0100)
* Internal.Console.Write uses UTF16 encoding for IsiOSLike

src/libraries/System.Private.CoreLib/src/Internal/Console.iOS.cs [new file with mode: 0644]
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Console.iOS.cs b/src/libraries/System.Private.CoreLib/src/Internal/Console.iOS.cs
new file mode 100644 (file)
index 0000000..84e0bbd
--- /dev/null
@@ -0,0 +1,29 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Text;
+
+namespace Internal
+{
+    public static partial class Console
+    {
+        public static unsafe void Write(string s)
+        {
+            fixed (char* ptr = s)
+            {
+                Interop.Sys.Log((byte*)ptr, s.Length * 2);
+            }
+        }
+        public static partial class Error
+        {
+            public static unsafe void Write(string s)
+            {
+                fixed (char* ptr = s)
+                {
+                    Interop.Sys.LogError((byte*)ptr, s.Length * 2);
+                }
+            }
+        }
+    }
+}
index 7dbc1cb..8a9f563 100644 (file)
     <Compile Include="$(CommonPath)System\IO\PathInternal.Unix.cs">
       <Link>Common\System\IO\PathInternal.Unix.cs</Link>
     </Compile>
-    <Compile Include="$(MSBuildThisFileDirectory)Internal\Console.Unix.cs" Condition="'$(TargetsAndroid)' != 'true'" />
+    <Compile Include="$(MSBuildThisFileDirectory)Internal\Console.Unix.cs" Condition="'$(TargetsAndroid)' != 'true' and '$(IsiOSLike)' != 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)Internal\Console.Android.cs" Condition="'$(TargetsAndroid)' == 'true'" />
+    <Compile Include="$(MSBuildThisFileDirectory)Internal\Console.iOS.cs" Condition="'$(IsiOSLike)' == 'true'" />
     <Compile Include="$(CommonPath)Interop\Android\Interop.Logcat.cs" Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true'">
       <Link>Common\Interop\Android\Interop.Logcat.cs</Link>
     </Compile>