-
Notifications
You must be signed in to change notification settings - Fork 188
Text API
This library allows to work with text data in different ways: to serialize/deserialize tables, to wrap and limit strings, to obtain Braille font chars or to search data in UTF-8
format.
Contents |
---|
text.serialize |
text.deserialize |
text.wrap |
text.limit |
text.brailleChar |
text.unicodeFind |
Serializes given table to a string. If pretty
argument is passed then serialization result will be more human-readable, by default it's set to false
. Notice that pretty
argument performs several additional checks on the type of keys and table values, and also generates the line break after each value. Therefore, use it only if the readability of the result is in priority over performance.
The recursionDepth
argument is responsible to depth of sub-table serialization calls, by default it's set to infinity
. Finally, the indentator
argument represents a string which will be used for indentation in pretty
mode, by default it's set to " "
. Here is example of serialization:
local myTable = {
"Hello",
"world",
abc = 123,
def = "456",
ghi = {
jkl = true,
}
}
table.serialize(myTable)
table.serialize(myTable, true)
> {[1]="Hello",[2]="world",["abc"]=123,["def"]="456",["ghi"]={["jkl"]=true}}
> {
"Hello",
"world",
abc = 123,
def = "456",
ghi = {
jkl = true,
}
}
Deserializes string representation of Lua table and returns result. Returns table
result on success, nil
and reason
message otherwise:
table.deserialize("{ abc = 123 }")
> {
abc = 123
}
Wraps a string or table of strings by given width and returns wrapped result as a table. If the size of a single word exceeds the specified length, the word will be "cut" into its constituent parts. Newline \n characters are also supported:
local data = "Those days, the Third Age of Middle-earth, are now long past, and the shape of all lands has been changed; but the regions in which Hobbits then lived were doubtless the same as those in which they still linger: the North-West of the Old World, east of the Sea."
text.wrap(data, 24)
Those days, the Third
Age of Middle-earth,
are now long past, and
the shape of all lands
has been changed; but
the regions in which
Hobbits then lived were
doubtless the same as
those in which they
still linger: the
North-West of the Old
World, east of the Sea.
Limits a string by inserting the "…" symbol in the correct location and returning the result:
text.limit("HelloBeautifulWorld", 10, "left")
text.limit("HelloBeautifulWorld", 10, "center")
text.limit("HelloBeautifulWorld", 10, "right")
…ifulWorld
Hello…orld
HelloBeau…
Returns a braille char with sub-pixels set dependent of arguments. If argument is not nil
, then pixel will be enabled. Every 2 arguments is a horizontal row of 2 Braille pixels:
text.brailleChar(
1, 0,
0, 1,
0, 1,
1, 0
)
> ⡱
The method is equivalent to string.find(...), however it allows to work with unicode. Nice thing for a non-english speaking people!