static class · System.Runtime.InteropServices

CStrings

static class CStrings

Temporary C strings: what the compiler calls around an imported function that takes strings.

Tipo
static class
Espacio de nombres
System.Runtime.InteropServices
Ensamblado
System.Core
Acceso
internal, static, abstract
Archivo fuente
Interop.ant

Herencia

Clases base
Any CStrings

Métodos

unsafe extern("mem.alloc") Allocate(i64 bytes) : u8*
#

static

unsafe extern("mem.free") Release(u8* block)
#

static

unsafe Utf8(str text) : u8*
#

static

A null-terminated UTF-8 copy of text (Free gives it back).

unsafe Utf16(String<u16> text) : u16*
#

static

A null-terminated UTF-16 copy of text (Free16 gives it back).

unsafe Utf8Into(str text, u8* buffer, i32 capacity) : bool
#

static

text null-terminated into buffer (capacity units) when it fits: whether it did.

unsafe Utf16Into(String<u16> text, u16* buffer, i32 capacity) : bool
#

static

unsafe Free(u8* block)
#

static

unsafe Free16(u16* block)
#

static

unsafe Length8(u8* text) : i32
#

static

How many units come before the first 0.

unsafe Length16(u16* text) : i32
#

static

Miembros heredados (5)

Código fuente

CStrings en Antril, descompilado a partir de su Larva HIR.

System.Runtime.InteropServices.CStrings.ant
// System.Runtime.InteropServices.CStrings — System.Core (decompiled from Larva HIR)

import System;

into namespace System.Runtime.InteropServices
{
	/// Temporary C strings: what the compiler calls around an imported function that takes strings.
	static class CStrings
	{
		public:
			unsafe extern("mem.alloc") Allocate(i64 bytes) : u8*;

			unsafe extern("mem.free") Release(u8* block);

			/// A null-terminated UTF-8 copy of `text` (Free gives it back).
			unsafe Utf8(str text) : u8*
			{
				u8[] units = text.Units();
				i32 n = units.Length;
				u8* copy = Allocate((i64)n + 1);
				loop (i32 i = 0..n)
					*(copy + (i64)i) = units[i];
				return copy;
			}

			/// A null-terminated UTF-16 copy of `text` (Free16 gives it back).
			unsafe Utf16(String<u16> text) : u16*
			{
				u16[] units = text.Units();
				i32 n = units.Length;
				u16* copy = (u16*)Allocate(2 * ((i64)n + 1));
				loop (i32 i = 0..n)
					*(copy + (i64)i) = units[i];
				return copy;
			}

			/// `text` null-terminated into `buffer` (`capacity` units) when it fits: whether it did.
			unsafe Utf8Into(str text, u8* buffer, i32 capacity) : bool
			{
				u8[] units = text.Units();
				i32 n = units.Length;
				if (n >= capacity)
					return false;
				loop (i32 i = 0..n)
					*(buffer + (i64)i) = units[i];
				*(buffer + (i64)n) = 0;
				return true;
			}

			unsafe Utf16Into(String<u16> text, u16* buffer, i32 capacity) : bool
			{
				u16[] units = text.Units();
				i32 n = units.Length;
				if (n >= capacity)
					return false;
				loop (i32 i = 0..n)
					*(buffer + (i64)i) = units[i];
				*(buffer + (i64)n) = 0;
				return true;
			}

			unsafe Free(u8* block)
			{
				Release(block);
			}

			unsafe Free16(u16* block)
			{
				Release((u8*)block);
			}

			/// How many units come before the first 0.
			unsafe Length8(u8* text) : i32
			{
				i32 n = 0;
				loop (*(text + (i64)n) != 0)
					n++;
				return n;
			}

			unsafe Length16(u16* text) : i32
			{
				i32 n = 0;
				loop (*(text + (i64)n) != 0)
					n++;
				return n;
			}
	}
}
Esc