forked from mirrors/nixpkgs
Merge pull request #273470 from adisbladis/lib-tohexstring-static-values
lib.toHexString: Statically compute hexDigits attrset
This commit is contained in:
commit
6d8c22272a
|
@ -520,22 +520,20 @@ in {
|
||||||
|
|
||||||
toHexString 250 => "FA"
|
toHexString 250 => "FA"
|
||||||
*/
|
*/
|
||||||
toHexString = i:
|
toHexString = let
|
||||||
let
|
hexDigits = {
|
||||||
toHexDigit = d:
|
"10" = "A";
|
||||||
if d < 10
|
"11" = "B";
|
||||||
then toString d
|
"12" = "C";
|
||||||
else
|
"13" = "D";
|
||||||
{
|
"14" = "E";
|
||||||
"10" = "A";
|
"15" = "F";
|
||||||
"11" = "B";
|
};
|
||||||
"12" = "C";
|
toHexDigit = d:
|
||||||
"13" = "D";
|
if d < 10
|
||||||
"14" = "E";
|
then toString d
|
||||||
"15" = "F";
|
else hexDigits.${toString d};
|
||||||
}.${toString d};
|
in i: lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
|
||||||
in
|
|
||||||
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:
|
||||||
|
|
Loading…
Reference in a new issue