hs.utf8
. The documentation for the utf8 library can be found at http://www.lua.org/manual/5.3/ or from the Hammerspoon console via the help command: help.lua.utf8
. This affects the following functions and variables:help.lua.utf8.char
help.lua.utf8.charpattern
help.lua.utf8.codepoint
help.lua.utf8.codes
help.lua.utf8.len
help.lua.utf8.offset
hs.utf8.registeredKeys[]
hs.utf8.registerCodepoint(label, codepoint)
for your own use.hs.utf8.registeredKeys
.hs.utf8.registeredLabels
, this can also invoked as a function, i.e. hs.utf8.registeredKeys["cmd"]
is equivalent to hs.utf8.registeredKeys("cmd")
hs.utf8.asciiOnly(string[, all]) -> string
utf8.charpattern
, which contains the regular expression for matching valid UTF8 encoded sequences, results in (null)
in the Hammerspoon console, but hs.utf8.asciiOnly(utf8.charpattern)
will display [\x00-\x7F\xC2-\xF4][\x80-\xBF]*
.hs.utf8.codepointToUTF8(...) -> string
utf8.char(...)
which ensures that all codepoints return valid UTF8 characters.hs.utf8.registeredKeys[]
hs.utf8.fixUTF8(inString[, replacementChar]) -> outString, posTable
inString
with replacementChar
so it can be safely displayed in the console or other destination which requires valid UTF8 encoding.inString
. If this parameter is not provided, the default UTF8 replacement character, U+FFFD, is used.inString
with all invalid UTF8 byte sequences replaced by the replacementChar
.outString
corresponding indicating where replacementChar
has been used.replacementChar
is a multi-byte character (like U+FFFD) or multi character string, then the string length of outString
will be longer than the string length of inString
. The character positions in posTable
will reflect these new positions in outString
.inString
, use something like the following:hs.utf8.hexDump(inputString [, count]) -> string
hs.utf8.hexDump(utf8.charpattern)
will return 00 : 5B 00 2D 7F C2 2D F4 5D 5B 80 2D BF 5D 2A : [.-..-.][.-.]*
hs.utf8.registerCodepoint(label, codepoint) -> string
hs.utf8.registeredKeys[label]
for convenience and readability.U+xxxx
format to register with the given label.hs.utf8.registeredKeys[label]
in your code. It looks good when invoked from the console, though ☺.hs.utf8.registeredLabels(utf8char) -> string
hs.utf8.registeredKeys[]
.hs.utf8.registeredKeys[]
hs.utf8.registeredKeys[]
, or nil, if utf8char is not a valid UTF8 character.hs.utf8.registeredKeys
, this can also be invoked as if it were an array: i.e. hs.utf8.registeredLabels(char)
is equivalent to hs.utf8.registeredLabels[char]