Difference between revisions of "Functions"

From Ketarin
(put functions and their description in a table)
Line 1: Line 1:
 
Sometimes you might need a variable value just slightly modified. For such cases, you can use a couple of functions on variables (feel free to suggest more). They are used like this: {variablename:function:argument1:argument2}  
 
Sometimes you might need a variable value just slightly modified. For such cases, you can use a couple of functions on variables (feel free to suggest more). They are used like this: {variablename:function:argument1:argument2}  
  
directory
+
== Overview ==
Extracts the directory name of an URL/file path
+
{| class="wikitable"
 
+
|-
empty
+
! Function
Have the variable return an empty string always
+
! Description
 
+
|-
ext
+
| directory
Extracts the file extension (without dot) of an URL/file path
+
| Extracts the directory name of an URL/file path
 
+
|-
filename
+
| empty
Returns the file name (with extension) from a file path
+
| Have the variable return an empty string always
 
+
|-
formatfilesize
+
| directory
Nicely formats a file size (given in bytes)
+
| Extracts the directory name of an URL/file path
 
+
|-
multireplace
+
| ext
Replaces multiple subjects within a string. Usage
+
| Extracts the file extension (without dot) of an URL/file path
 
+
|-
multireplacei
+
| filename
Replaces multiple subjects within a string (case insensitive). Usage
+
| Extracts the file name (with extension) from a file path
 
+
|-
regex
+
| formatfilesize
Returns the value which is matched by the regular expression (first argument). If groups exist, you can also select a group's value with the second argument. 0 is the whole match, 1 the first group, 2 the second group and so on.
+
| Nicely formats a file size (given in bytes)
 
+
|-
regexreplace
+
| multireplace
Replaces the content matched with the regular expression (first argument) with the second argument. The second argument may contain $n as references to groups of the regular expression.
+
| Replaces multiple subjects within a string. Usage
 
+
|-
replace
+
| multireplacei
Replaces all occurrences of argument1 with argument2
+
| Replaces multiple subjects within a string (case insensitive). Usage
 
+
|-
trim
+
| regex
Removes all whitespace at the start and end of a variable. If an argument is given, all characters of that string will be removed.
+
| Returns the value which is matched by the regular expression (first argument). If groups exist, you can also select a group's value with the second argument. 0 is the whole match, 1 the first group, 2 the second group and so on.
 
+
|-
trimstart
+
| regexreplace
Like trim, but only for the beginning of a word
+
| Replaces the content matched with the regular expression (first argument) with the second argument. The second argument may contain $n as references to groups of the regular expression.
 
+
|-
trimend
+
| replace
Like trim, but only for the end of a word
+
| Replaces all occurrences of argument1 with argument2
 
+
|-
toupper
+
| trim
Outputs only uppercase characters
+
| Removes all whitespace at the start and end of a variable. If an argument is given, all characters of that string will be removed.
 
+
|-
tolower
+
| trimstart
Outputs only lowercase characters
+
| Like trim, but only for the beginning of a word
 
+
|-
split
+
| trimend
Splits the variable content at each occurrence of the first argument and returns the part of the string with the number specified in the second argument (zero based)
+
| Like trim, but only for the end of a word
 
+
|-
startuppath
+
| toupper
Returns the startup path of the current Ketarin instance (without exe file)
+
| Outputs only uppercase characters
 +
|-
 +
| tolower
 +
| Outputs only lowercase characters
 +
|-
 +
| split
 +
| Splits the variable content at each occurrence of the first argument and returns the part of the string with the number specified in the second argument (zero based)
 +
|-
 +
| startuppath
 +
| Returns the startup path of the current Ketarin instance (without exe file)
 +
|}

Revision as of 18:11, 9 October 2010

Sometimes you might need a variable value just slightly modified. For such cases, you can use a couple of functions on variables (feel free to suggest more). They are used like this: {variablename:function:argument1:argument2}

Overview

Function Description
directory Extracts the directory name of an URL/file path
empty Have the variable return an empty string always
directory Extracts the directory name of an URL/file path
ext Extracts the file extension (without dot) of an URL/file path
filename Extracts the file name (with extension) from a file path
formatfilesize Nicely formats a file size (given in bytes)
multireplace Replaces multiple subjects within a string. Usage
multireplacei Replaces multiple subjects within a string (case insensitive). Usage
regex Returns the value which is matched by the regular expression (first argument). If groups exist, you can also select a group's value with the second argument. 0 is the whole match, 1 the first group, 2 the second group and so on.
regexreplace Replaces the content matched with the regular expression (first argument) with the second argument. The second argument may contain $n as references to groups of the regular expression.
replace Replaces all occurrences of argument1 with argument2
trim Removes all whitespace at the start and end of a variable. If an argument is given, all characters of that string will be removed.
trimstart Like trim, but only for the beginning of a word
trimend Like trim, but only for the end of a word
toupper Outputs only uppercase characters
tolower Outputs only lowercase characters
split Splits the variable content at each occurrence of the first argument and returns the part of the string with the number specified in the second argument (zero based)
startuppath Returns the startup path of the current Ketarin instance (without exe file)