Functions providing basic support for UTF-8 encodings
Prior to upgrading Hammerspoon's Lua interpreter to 5.3, UTF8 support was provided by including the then beta version of Lua 5.3's utf8 library as a Hammerspoon module. This is no longer necessary, but to maintain compatibility, the Lua utf8 library can still be accessed through 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.charhelp.lua.utf8.charpatternhelp.lua.utf8.codepointhelp.lua.utf8.codeshelp.lua.utf8.lenhelp.lua.utf8.offsetAdditional functions that are specific to Hammerspoon which provide expanded support for UTF8 are documented here.
| Signature | hs.utf8.registeredKeys[] |
|---|---|
| Type | Variable |
| Description | A collection of UTF-8 characters already converted from codepoint and available as convient key-value pairs. UTF-8 printable versions of common Apple and OS X special keys are predefined and others can be added with `hs.utf8.registerCodepoint(label, codepoint)` for your own use. |
| Notes | |
| Source | extensions/utf8/init.lua |
| Signature | hs.utf8.asciiOnly(string[, all]) -> string |
|---|---|
| Type | Function |
| Description | Returns the provided string with all non-printable ascii characters escaped, except Return, Linefeed, and Tab. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | extensions/utf8/init.lua |
| Signature | hs.utf8.codepointToUTF8(...) -> string |
|---|---|
| Type | Function |
| Description | Wrapper to `utf8.char(...)` which ensures that all codepoints return valid UTF8 characters. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | extensions/utf8/init.lua |
| Signature | hs.utf8.fixUTF8(inString[, replacementChar]) -> outString, posTable |
|---|---|
| Type | Function |
| Description | Replace invalid UTF8 character sequences in `inString` with `replacementChar` so it can be safely displayed in the console or other destination which requires valid UTF8 encoding. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | extensions/utf8/init.lua |
| Signature | hs.utf8.hexDump(inputString [, count]) -> string |
|---|---|
| Type | Function |
| Description | Returns a hex dump of the provided string. This is primarily useful for examining the exact makeup of binary data contained in a Lua String as individual bytes for debugging purposes. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | extensions/utf8/init.lua |
| Signature | hs.utf8.registerCodepoint(label, codepoint) -> string |
|---|---|
| Type | Function |
| Description | Registers a Unicode codepoint under the given label as a UTF-8 string of bytes which can be referenced by the label later in your code as `hs.utf8.registeredKeys[label]` for convenience and readability. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | extensions/utf8/init.lua |
| Signature | hs.utf8.registeredLabels(utf8char) -> string |
|---|---|
| Type | Function |
| Description | Returns the label name for a UTF8 character, as it is registered in `hs.utf8.registeredKeys[]`. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Source | extensions/utf8/init.lua |