final class · System

NumberText

final class NumberText

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

Kind
final class
Namespace
System
Assembly
System.Core
Access
internal, final
Source file
Format.ant

Inheritance

Base classes
Any NumberText

Methods

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

A non-negative number's digits.

Made() : str
#

Private and internal members (3)

u8[] bytes
#

private

i32 count
#

private

Grow()
#

private

Inherited members (5)

Source

NumberText as Antril, decompiled from its 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