mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:27:35 +00:00
LibWeb: Conversion from number to bijective-base with alphabet.
This allows us to convert a number to a String given a bijective (zero-less) alphabet. So you count A,B,C,...,Y,Z,AA,AB,... This was surprisingly very tricky! This allows the ListItemMarker to be displayed with different (simple) alphabets in the future.
This commit is contained in:
parent
0983cd9243
commit
7dd0fb0086
1 changed files with 15 additions and 0 deletions
|
@ -21,6 +21,21 @@ ListItemMarkerBox::~ListItemMarkerBox()
|
|||
{
|
||||
}
|
||||
|
||||
static const String number_to_alphabet(unsigned int number, const String alphabet)
|
||||
{
|
||||
auto base = alphabet.length();
|
||||
StringBuilder output_string;
|
||||
while (number > base) {
|
||||
number--;
|
||||
auto remainder = number % base;
|
||||
number -= remainder;
|
||||
output_string.append(alphabet[remainder]);
|
||||
number /= base;
|
||||
};
|
||||
output_string.append(alphabet[number - 1]);
|
||||
return output_string.to_string().reverse();
|
||||
}
|
||||
|
||||
void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase)
|
||||
{
|
||||
if (phase != PaintPhase::Foreground)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue