mirror of https://github.com/mono/CppSharp.git
c-sharpdotnetmonobindingsbridgecclangcpluspluscppsharpglueinteropparserparsingpinvokeswigsyntax-treevisitorsxamarinxamarin-bindings
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
930 B
34 lines
930 B
using System; |
|
using System.Text; |
|
|
|
namespace CppSharp.Runtime |
|
{ |
|
public unsafe static class MarshalUtil |
|
{ |
|
public static string GetString(Encoding encoding, IntPtr str) |
|
{ |
|
if (str == IntPtr.Zero) |
|
return null; |
|
|
|
int byteCount = 0; |
|
|
|
if (encoding == Encoding.UTF32) |
|
{ |
|
var str32 = (int*)str; |
|
while (*(str32++) != 0) byteCount += sizeof(int); |
|
} |
|
else if (encoding == Encoding.Unicode || encoding == Encoding.BigEndianUnicode) |
|
{ |
|
var str16 = (short*)str; |
|
while (*(str16++) != 0) byteCount += sizeof(short); |
|
} |
|
else |
|
{ |
|
var str8 = (byte*)str; |
|
while (*(str8++) != 0) byteCount += sizeof(byte); |
|
} |
|
|
|
return encoding.GetString((byte*)str, byteCount); |
|
} |
|
} |
|
}
|
|
|