final class · System

TimeText

final class TimeText

Text being written for a date or a length of time.

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

Inheritance

Base classes
Any TimeText

Properties

i32 Count { get; }
#

read-only

Methods

Add(u8 unit)
#
Text(str text)
#
Digits(i64 value, i32 width)
#

A non-negative number with at least width digits.

Offset(i64 ticks, i32 width, bool minutes, bool colon)
#

An offset from UTC in ticks: +hh:mm (colon false: +hhmm; minutes false: +hh, width 1: +h).

Last() : u8
#
Drop()
#
Made() : str
#

Private and internal members (3)

u8[] bytes
#

private

i32 count
#

private

Grow()
#

private

Inherited members (5)

Source

TimeText as Antril, decompiled from its Larva HIR.

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

into namespace System
{
	/// Text being written for a date or a length of time.
	final class TimeText
	{
		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++;
			}

			Text(str text)
			{
				loop (i32 i = 0..text.Length)
					Add(text[i]);
			}

			/// A non-negative number with at least `width` digits.
			Digits(i64 value, i32 width)
			{
				i32 n = 1;
				loop (i64 m = value; m >= 10; m = m / 10)
					n++;
				if (n < width)
					n = width;
				loop (count + n > bytes.Length)
					Grow();
				loop (i32 i = count + n - 1; i >= count; i--)
				{
					bytes[i] = (u8)(48 + value % 10);
					value = value / 10;
				}
				count += n;
			}

			/// An offset from UTC in ticks: `+hh:mm` (`colon` false: `+hhmm`; `minutes` false: `+hh`, `width` 1: `+h`).
			Offset(i64 ticks, i32 width, bool minutes, bool colon)
			{
				i64 all = ticks / 600000000;
				Add(all < 0 ? 45 : 43);
				if (all < 0)
					all = -all;
				Digits(all / 60, width);
				if (minutes)
				{
					if (colon)
						Add(58);
					Digits(all % 60, 2);
				}
			}

			Last() : u8 => count > 0 ? bytes[count - 1] : 0;

			Drop()
			{
				count--;
			}

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

			i32 Count
			{
				get => count;
			}
	}
}
Esc