MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / ToUtf8

Method ToUtf8

headers/openvr_api.cs:2194–2208  ·  view source on GitHub ↗
(string managedString)

Source from the content-addressed store, hash-verified

2192public class Utils
2193{
2194 public static IntPtr ToUtf8(string managedString)
2195 {
2196 if (managedString == null)
2197 {
2198 return IntPtr.Zero;
2199 }
2200
2201 int size = System.Text.Encoding.UTF8.GetByteCount(managedString) + 1;
2202 if (buffer.Length < size) buffer = new byte[size];
2203 int written = System.Text.Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0);
2204 buffer[written] = 0x00; // null terminate
2205 IntPtr nativeUtf8 = Marshal.AllocHGlobal(written+1);
2206 Marshal.Copy(buffer, 0, nativeUtf8, written+1);
2207 return nativeUtf8;
2208 }
2209 private static byte[] buffer = new byte[1024];
2210}
2211

Calls

no outgoing calls

Tested by

no test coverage detected