IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
Utils.cs
Go to the documentation of this file.
1using System.Text;
2
4
5internal static unsafe class Utils
6{
7 internal static void ToFixedArray<T>(T[] src, T* dest) where T : unmanaged
8 {
9 if (src.Length == 0)
10 {
11 return;
12 }
13
14 for (var i = 0; i < src.Length; i++)
15 {
16 dest[i] = src[i];
17 }
18 }
19
20 internal static T[] FromFixedArray<T>(T* source, int length) where T : unmanaged
21 {
22 var result = new T[length];
23 for (var i = 0; i < length; i++)
24 {
25 result[i] = source[i];
26 }
27
28 return result;
29 }
30
31 internal static byte[] ToUtf8(string value)
32 {
33 var bytes = Encoding.UTF8.GetBytes(value);
34 var nullTerminated = new byte[bytes.Length + 1];
35 Array.Copy(bytes, nullTerminated, bytes.Length);
36 nullTerminated[bytes.Length] = 0;
37 return nullTerminated;
38 }
39
40 internal static string FromUtf8(byte[] value)
41 {
42 var len = Array.IndexOf(value, (byte) 0);
43 if (len < 0)
44 {
45 len = value.Length;
46 }
47
48 return Encoding.UTF8.GetString(value, 0, len);
49 }
50}
IDSImaging.Peak.ICV.Backend.Utils Utils