final class · System

NumberText

final class NumberText

The text a format makes: bytes (ASCII), grown as needed, then one string of exactly them.

Tipo
final class
Espacio de nombres
System
Ensamblado
System.Core
Acceso
internal, final
Archivo fuente
Format.ant

Herencia

Clases base
Any NumberText

Métodos

Add(u8 unit)
#
Number(i32 value)
#

A non-negative number's digits.

Made() : str
#

Miembros privados e internos (3)

u8[] bytes
#

private

i32 count
#

private

Grow()
#

private

Miembros heredados (5)

Código fuente

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

System.NumberText.ant
// System.NumberText — System.Core (decompiled from Larva HIR)

into namespace System
{
	/// The text a format makes: bytes (ASCII), grown as needed, then one string of exactly them.
	final class NumberText
	{
		u8[] bytes;
		i32 count;

		[NoInline]
		Grow()
		{
			u8[] bigger = new u8[bytes.Length * 2];
			loop (i32 i = 0..count)
				bigger[i] = bytes[i];
			bytes = bigger;
		}

		public:
			Add(u8 unit)
			{
				if (count == bytes.Length)
					Grow();
				bytes[count] = unit;
				count++;
			}

			/// A non-negative number's digits.
			Number(i32 value)
			{
				i32 width = 1;
				loop (i32 m = value; m >= 10; m = m / 10)
					width++;
				loop (count + width > bytes.Length)
					Grow();
				loop (i32 i = width - 1; i >= 0; i--)
				{
					bytes[count + i] = (u8)(48 + value % 10);
					value = value / 10;
				}
				count += width;
			}

			Made() : str
			{
				u8[] exact = new u8[count];
				loop (i32 i = 0..count)
					exact[i] = bytes[i];
				return new str(exact);
			}
	}
}
Esc