final class · System
TimeText
final class TimeText
Text being written for a date or a length of time.
- Tipo
- final class
- Espacio de nombres
- System
- Ensamblado
- System.Core
- Acceso
- internal, final
- Archivo fuente
Time.ant
Herencia
- Clases base
-
AnyTimeText
Propiedades
Métodos
Text(str text)
#
A non-negative number with at least width digits.
An offset from UTC in ticks: +hh:mm (colon false: +hhmm; minutes false: +hh, width 1: +h).
Drop()
#
Made() : str
#
Miembros heredados (5)
GetTypemétodo de AnyUndescribedmétodo de AnyToStringmétodo de AnyHashmétodo de Anydestroymétodo de Any
Código fuente
TimeText en Antril, descompilado a partir de su Larva HIR.
// 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;
}
}
}