plover.misc – Miscellaneous¶
This module provides miscellaneous utility functions.
- plover.misc.popcount_8(v: int) int¶
Returns the number of
1bits in the 8-bit numberv.
- plover.misc.expand_path(path: str) str¶
Returns an expanded version of
path, in which paths relative to either the home directory~or the configuration directoryCONFIG_DIRare fully qualified.If
pathis an asset path, it is returned as is.
- plover.misc.shorten_path(path: str) str¶
Returns a shortened version of
path, in which paths within the home directory are abbreviated to contain~, and paths within the configuration directoryCONFIG_DIRare expressed relative to it.Relative paths such as those returned by this function are assumed to be relative to
CONFIG_DIR.If
pathis an asset path, it is returned as is.
- plover.misc.normalize_path(path: str) str¶
Returns a normalized version of
path, resolving the full path if it refers to a symbolic link, and normalizing the case where necessary.If
pathis an asset path, it is returned as is.
- plover.misc.boolean(value: any) bool¶
Returns
valueconverted to a Boolean value, or raisesValueErrorif this is not possible.If
valueis a string, the values1,yes,trueandonand their case variants are converted toTrue, and0,no,falseandoffand their case variants are converted toFalse. If it is not a string, the return value is resolved by casting tobool.
- plover.misc.to_surrogate_pair(char: str) List[int]¶
Returns a list of numbers corresponding to the UTF-16 encoding for the string
char.charmay have multiple characters.If each character in
charhas a Unicode codepoint betweenU+0000andU+FFFF, its corresponding element in the return value is the codepoint as a hexadecimal number; if it is aboveU+FFFF, it is converted to two elements in the list, the high and low bytes respectively.For example, the string
"🥺?"(U+1F97Afollowed byU+003F) returns the list[55358, 56698, 63]([D83E, DD7A, 003F]in hexadecimal).