-
-
Notifications
You must be signed in to change notification settings - Fork 2
Fluid Common API
The Common API provides a number of utility functions to enhance existing interfaces such as table
and string
. It also adds the file
interface.
The API can be loaded with the line:
require 'common'
str:escXML()
Escape str
for an XML attribute value or content.
str:cap()
Capitalise a string.
str:trim()
Trims whitespace from the left and right sides of a string.
str:rtrim()
Trims whitespace from the right side of a string.
str:split([Pattern])
Split a string using Pattern
to identify each valid word. If Pattern is not specified, it defaults to %s
.
str:startsWith(Cmp)
Returns true
if the string starts with Cmp
.
str:endsWith(Cmp)
Returns true
if the string ends with Cmp
.
table.sortByKeys(Table)
Sort all key values in Table
for processing as paired k,v
items. Intended for use in a for
loop as follows:
for k,v in table.sortByKeys(the_table) do
...
end
String = table.toXML(Table)
Parse the key-values of a table and produce an XML string.
math.round(Num, [DecimalPlaces])
Round floating point Num
to the nearest integer. If DecimalPlaces
is specified then the function will round to the place indicated. For example math.round(8.2468,2)
rounds to 8.25
.
content = file.readAll(Path)
Reads all content from Path
and returns it as a string. An exception will be thrown if failure occurs for any reason.
exists = file.isFolder(Path)
Returns true if the Path
string explicitly references a folder. No test is performed to confirm whether or not the path exists.
path, filename = file.splitPath(Path)
Splits the folder and filename out from a Path
string, returning them as distinct values. For instance parasol:a/b/file.txt
results in parasol:a/b/
and file.txt
.
path = file.sanitisePath(Path)
Removes repeated folder separators from a string. For instance volume:a/b///c\\f.txt
becomes volume:a/b/c\f.txt
.