mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-07 19:52:40 +01:00
Updated Text API (markdown)
parent
d080154dde
commit
4c0a2db8e4
62
Text-API.md
62
Text-API.md
@ -2,9 +2,7 @@ This library allows to work with text data in different ways: to serialize/deser
|
||||
|
||||
### text.**serialize**(*table* table[, *boolean* pretty, *int* recursionDepth, *string* indentator]): *string* result
|
||||
|
||||
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.
|
||||
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:
|
||||
|
||||
@ -49,4 +47,62 @@ table.deserialize("{ abc = 123 }")
|
||||
> {
|
||||
abc = 123
|
||||
}
|
||||
```
|
||||
|
||||
### text.**wrap**(*string* or *table* value, *int* wrapWidth): *table* result
|
||||
|
||||
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:
|
||||
|
||||
```lua
|
||||
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.
|
||||
```
|
||||
|
||||
### text.**limit**(*string* value, *int* width, *string* mode, *boolean* noDots ): *string* result
|
||||
|
||||
Limits a string by inserting the "…" symbol in the correct location and returning the result:
|
||||
|
||||
```lua
|
||||
text.limit("HelloBeautifulWorld", 10, "left")
|
||||
text.limit("HelloBeautifulWorld", 10, "center")
|
||||
text.limit("HelloBeautifulWorld", 10, "right")
|
||||
```
|
||||
|
||||
```
|
||||
…ifulWorld
|
||||
Hello…orld
|
||||
HelloBeau…
|
||||
```
|
||||
|
||||
### text.**brailleChar**(*var* a, *var* b, *var* c, *boolean* d, *var* e, *var* f, *var* g, *var* h): *string* result
|
||||
|
||||
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:
|
||||
|
||||
```lua
|
||||
text.brailleChar(
|
||||
1, 0,
|
||||
0, 1,
|
||||
0, 1,
|
||||
1, 0
|
||||
)
|
||||
```
|
||||
|
||||
```
|
||||
> ⡱
|
||||
```
|
||||
Loading…
x
Reference in New Issue
Block a user