Module xw.utils

xw general purpose utils


Usage:

local utils = require 'xw.utils'

Type xw.utils

xw.utils.fileExist(file) Returns true if the file exist, false otherwise
xw.utils.formatDateForMime(time) return RFC 2822 formated date time
xw.utils.getFileSize(file) Returns a file size
xw.utils.getOs() return os = { Windows, Linux, MacOS }
xw.utils.getPathSeparator() return "\" or "/"
xw.utils.getScriptPath() return path of current script
xw.utils.joinTables(tab1, tab2) Produces a single table from a couple of tables merging content, second table will override first one so it is not indicated for arrays!!!!!
xw.utils.loadFile(file) Loads content of file
xw.utils.saveFile(file, content) Saves content to file
xw.utils.stricmp(s1, s2) Compare two strings in insensitive way
xw.utils.strjoin(delimiter, list) Similar to PHP implode method
xw.utils.strsplit(delimiter, text, plain) Similar to PHP explode method
xw.utils.strtrim(s) Cuts off trailing spaces
xw.utils.timeTable(date, time) Compose a timeTable to be used with os.date() or os.time()
xw.utils.urlDecode(str) decodes url encoding
xw.utils.urlEncode(str) encodes url encoding

Type xw.utils

Field(s)

xw.utils.fileExist(file)
Returns true if the file exist, false otherwise

Parameter

  • #string file : The complete file name

Return value

#boolean: 'true' if the file exist, 'false' in every other case --

xw.utils.formatDateForMime(time)
return RFC 2822 formated date time

Parameter

  • #number time :
    • current if not present

Return value

#string: string --

xw.utils.getFileSize(file)
Returns a file size

Parameter

  • #string file : The complete file name

Return value

#number: The actual size of the give file or '-1' if the file doen't exist or can't be accessed --

xw.utils.getOs()
return os = { Windows, Linux, MacOS }

Return value

#string: string --

xw.utils.getPathSeparator()
return "\" or "/"

Return value

#string: string --

xw.utils.getScriptPath()
return path of current script

Return value

#string: string --

xw.utils.joinTables(tab1, tab2)
Produces a single table from a couple of tables merging content, second table will override first one so it is not indicated for arrays!!!!!

Parameters

  • #table tab1 : The first table
  • #table tab2 : The second table

Return value

#table: The result of the join activity --

xw.utils.loadFile(file)
Loads content of file

Parameter

  • #string file : The complete file name

Return value

#string: file content

xw.utils.saveFile(file, content)
Saves content to file

Parameters

  • #string file :
     The complete file name
    
  • #string content : File content
xw.utils.stricmp(s1, s2)
Compare two strings in insensitive way

Parameters

  • #string s1 : First string to compare
  • #string s2 : Second string to compare

Return value

#number: The same result of string:gsub --

xw.utils.strjoin(delimiter, list)
Similar to PHP implode method

Parameters

  • #string delimiter : the delimiter that is used to join strings
  • #table list : The table of strings to join

Return value

#string: --

xw.utils.strsplit(delimiter, text, plain)
Similar to PHP explode method

Parameters

  • #string delimiter : The pattern to find to split string
  • #string text : The string to split
  • #boolean plain : Tells if the pattern search must be in plain mode (see string.find())

Return value

#table: The resulting splitted table of strings --

xw.utils.strtrim(s)
Cuts off trailing spaces

Parameter

  • #string s : The string to trim

Return value

#string: Trimmed string --

xw.utils.timeTable(date, time)
Compose a timeTable to be used with os.date() or os.time()

Parameters

  • #string date : The date format as YYYYMMDD or YYYY/MM/DD
  • #string time : The time format as HHMMSS or HH:MM:SS

Return value

#table:

A table contaning al date and time values splitted. No Daylight Saving Time is set

              If values are partially set (only year, year and month, only hour, hour and minutes) the 
              unset values have their default from the basis date that is 1980/01/01 00:00:00

xw.utils.urlDecode(str)
decodes url encoding

Parameter

  • #string str : string

Return value

#string: string --

xw.utils.urlEncode(str)
encodes url encoding

Parameter

  • #string str : string

Return value

#string: string --