mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-07 06:19:00 +00:00
bahaghari/lib: update hex subset to properly accept inputs with mixed letter cases
This commit is contained in:
parent
35873462f3
commit
999401f3ce
@ -27,10 +27,37 @@ let
|
||||
baseSet = self.generateBaseDigitType glyphList;
|
||||
in
|
||||
rec {
|
||||
/* Returns a convenient glyph set for creating your own conversion or
|
||||
hex-related functions.
|
||||
inherit (baseSet) glyphSet conversionTable;
|
||||
|
||||
/* Converts a hexadecimal digit string into its decimal equivalent.
|
||||
|
||||
Type: toDec :: String -> Number
|
||||
|
||||
Example:
|
||||
toDec "FF"
|
||||
=> 255
|
||||
|
||||
toDec "ff"
|
||||
=> 255
|
||||
*/
|
||||
inherit (baseSet) glyphSet conversionTable fromDec toDec;
|
||||
toDec = digit:
|
||||
let
|
||||
digit' = lib.toUpper digit;
|
||||
in
|
||||
baseSet.toDec digit';
|
||||
|
||||
/* Converts a decimal digit into its hexadecimal notation.
|
||||
|
||||
Type: fromDec :: Number -> String
|
||||
|
||||
Example:
|
||||
fromDec 255
|
||||
=> "FF"
|
||||
|
||||
fromDec 293454837
|
||||
=> "117DC3F5"
|
||||
*/
|
||||
fromDec = decimal: lib.toUpper (baseSet.fromDec decimal);
|
||||
|
||||
/* A variant of `lib.lists.range` function just with hexadecimal digits.
|
||||
|
||||
|
@ -41,6 +41,16 @@ lib.runTests {
|
||||
expected = 2565;
|
||||
};
|
||||
|
||||
testHexToDecLowercase = {
|
||||
expr = self.hex.toDec "0A0FfbA";
|
||||
expected = 10551226;
|
||||
};
|
||||
|
||||
testHexToDecLowercase2 = {
|
||||
expr = self.hex.toDec "0af";
|
||||
expected = 175;
|
||||
};
|
||||
|
||||
testCreateHexRange = {
|
||||
expr = self.hex.range 10 17;
|
||||
expected = [ "A" "B" "C" "D" "E" "F" "10" "11" ];
|
||||
@ -75,4 +85,9 @@ lib.runTests {
|
||||
expr = self.hex.pad (-5) "A42C";
|
||||
expected = "A42C";
|
||||
};
|
||||
|
||||
testHexPadWithMixedLetterCase = {
|
||||
expr = self.hex.pad 8 "AfB9";
|
||||
expected = "0000AfB9";
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user