esi-string
The esi-string
library provides basic string operations
Changes
Version | Date | Description | s:i Release |
---|---|---|---|
1.70.2 |
2020-12-08 |
TFS code synchronisation |
1.72 |
1.0.4 |
2020-10-03 |
Fix links and section titles in the docs |
- |
1.60.7 |
2019-11-23 |
CLEAN fix |
1.60 |
1.0.3 |
2018-08-26 |
STRING fix (no more "nil" return) |
1.40 |
1.0.2 |
2018-06-25 |
SPLIT fix |
1.36 |
1.0.1 |
2018-06-24 |
SPLIT reworked |
1.36 |
1.0.0 |
2018-06-03 |
First system:inmation inclusion |
1.34 |
0.1.2 |
2018-05-27 |
More data type tolerance in SPLIT |
- |
0.1.1 |
2018-05-23 |
Initial release |
- |
Available functions
All functions have to be called according to the ESI standard, using colons, e.g. STR:COMPNOCASE("a","A")
Documentation
CLEAN
CLEAN(str)
Trims a given string (removes leading and trailing spaces) and returns this string
.
COMPNOCASE
COMPNOCASE(str1, str2)
Returns true
if the given arguments str1
and str2
are equal (case-insensitive).
EMPTY
EMPTY(str)
Returns true
if the given argument is either an empty string or comparable (such as nil).
FINDNOCASE
FINDNOCASE(str, what)
Returns true
if the given argument what
was found in str
(case-insensitive).
INFO
This is a mandatory function for every ESI library. It returns the INFO table
for the library.
Usage
local STR=require('esi-string')
error(STR:STRING(STR:INFO()))
MAKESTRINGTABLE
MAKESTRINGTABLE(x)
Takes any argument and turns it into a string table
, which is returned. Any argument excludes nested tables.
NONEOF
NONEOF(x, …)
Tests a given string against a variable list of strings to compare with and returns true
if no match was found. The
comparison is case-insensitive.
ONEOF
ONEOF(x, …)
Tests a given string against a variable list of strings to compare with and returns true
if one match was found. The
comparison is case-insensitive.
SPLIT
SPLIT(str, separator)
Splits a string according to the given separator. The function considers quoted parts in the string, so that the quoted
parts are not split. The function returns a table of strings
.
STRING
STRING(par)
Returns the given argument par
as string
. If par
is a table, the table will be encoded in JSON. As such, the
function may return huge strings. Be careful.
Usage
local STR = require('esi-string')
local test = { a="A", b="B", c={a="A in c", b="B in c" } }
error(STR:STRING(test))
TOTABLE
TOTABLE(str)
Returns the given argument str
as table
, expecting valid JSON format. Nil
will be returned for invalid JSON. {}
will be returned for empty string.
ESCAPE
ESCAPE(x)
Escapes a lua string so that the lua function string.gsub works as expected. Useful when trying to gsub parts of a path for example.
Useage
local STR = require('esi-string')
local somepath = "/System/Core/Connector/Aspen.Infoplus21_DA.1/asd/asd"
b = a:gsub(STR:ESCAPE("/System/Core/Connector/Aspen.Infoplus21_DA.1"), "..")
--b is now ../asd/asd, i.e. the path relative to the datasource
LUATYPE
LUATYPE(x)
Tries to convert the given string to a number or a boolean. If not possible, returns the string originally passed.
Useage
local STR = require('esi-string')
local converted, typename = STR:LUATYPE("true") --type is either "number", "boolean", or "string"
if type(converted) == "boolean" and typename == "boolean" then
return true --is true
end
--converted is now true, type(converted) is boolean