Merge pull request #273470 from adisbladis/lib-tohexstring-static-values

lib.toHexString: Statically compute hexDigits attrset
This commit is contained in:
Silvan Mosberger
2023-12-11 17:46:23 +01:00
committed by GitHub

View File

@@ -520,22 +520,20 @@ in {
toHexString 250 => "FA" toHexString 250 => "FA"
*/ */
toHexString = i: toHexString = let
let hexDigits = {
toHexDigit = d:
if d < 10
then toString d
else
{
"10" = "A"; "10" = "A";
"11" = "B"; "11" = "B";
"12" = "C"; "12" = "C";
"13" = "D"; "13" = "D";
"14" = "E"; "14" = "E";
"15" = "F"; "15" = "F";
}.${toString d}; };
in toHexDigit = d:
lib.concatMapStrings toHexDigit (toBaseDigits 16 i); if d < 10
then toString d
else hexDigits.${toString d};
in i: lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
/* `toBaseDigits base i` converts the positive integer i to a list of its /* `toBaseDigits base i` converts the positive integer i to a list of its
digits in the given base. For example: digits in the given base. For example: