plover.misc
– Miscellaneous#
This module provides miscellaneous utility functions.
- plover.misc.popcount_8(v: int) int #
Returns the number of
1
bits 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_DIR
are fully qualified.If
path
is 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_DIR
are expressed relative to it.Relative paths such as those returned by this function are assumed to be relative to
CONFIG_DIR
.If
path
is 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
path
is an asset path, it is returned as is.
- plover.misc.boolean(value: any) bool #
Returns
value
converted to a Boolean value, or raisesValueError
if this is not possible.If
value
is a string, the values1
,yes
,true
andon
and their case variants are converted toTrue
, and0
,no
,false
andoff
and 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
.char
may have multiple characters.If each character in
char
has a Unicode codepoint betweenU+0000
andU+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+1F97A
followed byU+003F
) returns the list[55358, 56698, 63]
([D83E, DD7A, 003F]
in hexadecimal).