Functions wikifmt: Difference between revisions

From NEOSYS Dev Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 8: Line 8:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||varnum.<em>round</em>(ndecimals = 0)||<em>Returns:</em> A var containing an ASCII string with the number of decimal places requested.</p>
|var=||varnum.<em>round</em>(ndecimals = 0)||Returns: A var containing an ASCII string with the number of decimal places requested.
 
.5 always rounds away from zero.
.5 always rounds away from zero.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(0.295).round(2);  // "0.30"
let v1 = var(0.295).round(2);  // "0.30"
  // or
  // or
  let v2 = round(1.295, 2);      // "1.30"
  let v2 = round(1.295, 2);      // "1.30"
Line 20: Line 21:
Negative number of decimals rounds to the left of the decimal point
Negative number of decimals rounds to the left of the decimal point
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = round(123456.789,  0); // "123457"
let v1 = round(123456.789,  0); // "123457"
  let v2 = round(123456.789, -1); // "123460"
  let v2 = round(123456.789, -1); // "123460"
  let v3 = round(123456.789, -2); // "123500"</syntaxhighlight>
  let v3 = round(123456.789, -2); // "123500"</syntaxhighlight>
|-
|-
|var=||var().<em>chr</em>(num)||<em>Returns:</em> A string containing a single char (byte) given an integer 0-255.</p>
|var=||var().<em>chr</em>(num)||Returns: A string containing a single char (byte) given an integer 0-255.
 
0-127 -> ASCII, 128-255 -> invalid UTF-8 which cannot be written to the database or used in many exodus string operations
0-127 -> ASCII, 128-255 -> invalid UTF-8 which cannot be written to the database or used in many exodus string operations
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var().chr(0x61); // "a"
let v1 = var().chr(0x61); // "a"
  // or
  // or
  let v2 = chr(0x61);</syntaxhighlight>
  let v2 = chr(0x61);</syntaxhighlight>
|-
|-
|var=||var().<em>textchr</em>(num)||<em>Returns:</em> A string of a single unicode code point in utf8 encoding.</p>
|var=||var().<em>textchr</em>(num)||Returns: A string of a single unicode code point in utf8 encoding.
 
To get utf codepoints > 2^63 you must provide negative ints because var doesnt provide an implicit constructor to unsigned int due to getting ambigious conversions because int and unsigned int are parallel priority in c++ implicit conversions.
To get utf codepoints > 2^63 you must provide negative ints because var doesnt provide an implicit constructor to unsigned int due to getting ambigious conversions because int and unsigned int are parallel priority in c++ implicit conversions.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var().textchr(171416); // "𩶘" // or "\xF0A9B698"
let v1 = var().textchr(171416); // "𩶘" // or "\xF0A9B698"
  // or
  // or
  let v2 = textchr(171416);</syntaxhighlight>
  let v2 = textchr(171416);</syntaxhighlight>
|-
|-
|var=||var().<em>str</em>(num)||<em>Returns:</em> A string of repeating characters or strings
|var=||var().<em>str</em>(num)||Returns: A string of repeating characters or strings
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "ab"_var.str(3); // "ababab"
let v1 = "ab"_var.str(3); // "ababab"
  // or
  // or
  let v2 = str("ab", 3);</syntaxhighlight>
  let v2 = str("ab", 3);</syntaxhighlight>
|-
|-
|var=||varnum.<em>space</em>()||<em>Returns:</em> A string of space characters.
|var=||varnum.<em>space</em>()||Returns: A string of space characters.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(3).space(); // "␣␣␣"
let v1 = var(3).space(); // "␣␣␣"
  // or
  // or
  let v2 = space(3);</syntaxhighlight>
  let v2 = space(3);</syntaxhighlight>
|-
|-
|var=||varnum.<em>numberinwords</em>(languagename_or_locale_id = "")||<em>Returns:</em> A string representing a given number written in words instead of digits.</p>
|var=||varnum.<em>numberinwords</em>(languagename_or_locale_id = "")||Returns: A string representing a given number written in words instead of digits.
locale: Something like en_GB, ar_AE, el_CY, es_US, fr_FR etc.
 
<em>locale:</em> Something like en_GB, ar_AE, el_CY, es_US, fr_FR etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let softhyphen = "\xc2\xad";
let softhyphen = "\xc2\xad";
  let v1 = var(123.45).numberinwords("de_DE").replace(softhyphen, " "); // "ein␣hundert␣drei␣und␣zwanzig␣Komma␣vier␣fünf"</syntaxhighlight>
  let v1 = var(123.45).numberinwords("de_DE").replace(softhyphen, " "); // "ein␣hundert␣drei␣und␣zwanzig␣Komma␣vier␣fünf"</syntaxhighlight>
|}
|}
Line 61: Line 65:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||var().<em>seq</em>()||<em>Returns:</em> The character number of the first char.
|var=||var().<em>seq</em>()||Returns: The character number of the first char.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.seq(); // 0x61 // decimal 97
let v1 = "abc"_var.seq(); // 0x61 // decimal 97
  // or
  // or
  let v2 = seq("abc");</syntaxhighlight>
  let v2 = seq("abc");</syntaxhighlight>
|-
|-
|var=||var().<em>textseq</em>()||<em>Returns:</em> The Unicode character number of the first unicode code point.
|var=||var().<em>textseq</em>()||Returns: The Unicode character number of the first unicode code point.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "Γ"_var.textseq(); // 915 // U+0393: Greek Capital Letter Gamma (Unicode Character)
let v1 = "Γ"_var.textseq(); // 915 // U+0393: Greek Capital Letter Gamma (Unicode Character)
  // or
  // or
  let v2 = textseq("Γ");</syntaxhighlight>
  let v2 = textseq("Γ");</syntaxhighlight>
|-
|-
|var=||var().<em>len</em>()||<em>Returns:</em> The length of a string in number of chars
|var=||var().<em>len</em>()||Returns: The length of a string in number of chars
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.len(); // 3
let v1 = "abc"_var.len(); // 3
  // or
  // or
  let v2 = len("abc");</syntaxhighlight>
  let v2 = len("abc");</syntaxhighlight>
|-
|-
|if||var().<em>empty</em>()||<em>Returns:</em> true if the var is an empty string.</p>
|if||var().<em>empty</em>()||Returns: true if the var is an empty string.
This is a shorthand and more expressive way of writing 'if (var == "")' or 'if (var.len() == 0)' or 'if (not var.len())'</p>
 
This is a shorthand and more expressive way of writing 'if (var == "")' or 'if (var.len() == 0)' or 'if (not var.len())'
 
Note that 'if (var.empty())' is not the same as 'if (not var)' because 'if (var("0.0")' is defined as false because the string can be converted to a 0 which is always considered to be false. Compare thia with common scripting languages where 'if (var("0"))' is defined as true.
Note that 'if (var.empty())' is not the same as 'if (not var)' because 'if (var("0.0")' is defined as false because the string can be converted to a 0 which is always considered to be false. Compare thia with common scripting languages where 'if (var("0"))' is defined as true.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "0";
let v1 = "0";
  if (not v1.empty()) ... ok /// true
  if (not v1.empty()) ... ok /// true
  // or
  // or
  if (not empty(v1)) ... ok // true</syntaxhighlight>
  if (not empty(v1)) ... ok // true</syntaxhighlight>
|-
|-
|var=||var().<em>textwidth</em>()||<em>Returns:</em> The number of output columns.</p>
|var=||var().<em>textwidth</em>()||Returns: The number of output columns.
Allows multi column unicode and reduces combining characters etc. like e followed by grave accent</p>
 
Allows multi column unicode and reduces combining characters etc. like e followed by grave accent
 
Possibly does not properly calculate combining sequences of graphemes e.g. face followed by colour
Possibly does not properly calculate combining sequences of graphemes e.g. face followed by colour
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "🤡x🤡"_var.textwidth(); // 5
let v1 = "🤡x🤡"_var.textwidth(); // 5
  // or
  // or
  let v2 = textwidth("🤡x🤡");</syntaxhighlight>
  let v2 = textwidth("🤡x🤡");</syntaxhighlight>
|-
|-
|var=||var().<em>textlen</em>()||<em>Returns:</em> The number of Unicode code points
|var=||var().<em>textlen</em>()||Returns: The number of Unicode code points
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "Γιάννης"_var.textlen(); // 7
let v1 = "Γιάννης"_var.textlen(); // 7
  // or
  // or
  let v2 = textlen("Γιάννης");</syntaxhighlight>
  let v2 = textlen("Γιάννης");</syntaxhighlight>
|-
|-
|var=||var().<em>fcount</em>(sepstr)||<em>Returns:</em> The count of the number of fields separated by a given sepstr.</p>
|var=||var().<em>fcount</em>(sepstr)||Returns: The count of the number of fields separated by a given sepstr.
 
It is the same as var.count(sepstr) + 1 except that it returns 0 for an empty string.
It is the same as var.count(sepstr) + 1 except that it returns 0 for an empty string.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "aa**cc"_var.fcount("*"); // 3
let v1 = "aa**cc"_var.fcount("*"); // 3
  // or
  // or
  let v2 = fcount("aa**cc", "*");</syntaxhighlight>
  let v2 = fcount("aa**cc", "*");</syntaxhighlight>
|-
|-
|var=||var().<em>count</em>(sepstr)||<em>Returns:</em> The count of the number of sepstr found.
|var=||var().<em>count</em>(sepstr)||Returns: The count of the number of sepstr found.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "aa**cc"_var.count("*"); // 2
let v1 = "aa**cc"_var.count("*"); // 2
  // or
  // or
  let v2 = count("aa**cc", "*");</syntaxhighlight>
  let v2 = count("aa**cc", "*");</syntaxhighlight>
|-
|-
|if||var().<em>starts</em>(prefix)||<em>Returns:</em> True if starts with prefix
|if||var().<em>starts</em>(prefix)||Returns: True if starts with prefix
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if ("abc"_var.starts("ab")) ... true
if ("abc"_var.starts("ab")) ... true
  // or
  // or
  if (starts("abc", "ab")) ... true</syntaxhighlight>
  if (starts("abc", "ab")) ... true</syntaxhighlight>
|-
|-
|if||var().<em>ends</em>(suffix)||<em>Returns:</em> True if ends with suffix
|if||var().<em>ends</em>(suffix)||Returns: True if ends with suffix
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if ("abc"_var.ends("bc")) ... true
if ("abc"_var.ends("bc")) ... true
  // or
  // or
  if (ends("abc", "bc")) ... true</syntaxhighlight>
  if (ends("abc", "bc")) ... true</syntaxhighlight>
|-
|-
|if||var().<em>contains</em>(substr)||<em>Returns:</em> True if starts, ends or contains substr
|if||var().<em>contains</em>(substr)||Returns: True if starts, ends or contains substr
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if ("abcd"_var.contains("bc")) ... true
if ("abcd"_var.contains("bc")) ... true
  // or
  // or
  if (contains("abcd", "bc")) ... true</syntaxhighlight>
  if (contains("abcd", "bc")) ... true</syntaxhighlight>
|-
|-
|var=||var().<em>index</em>(substr, startchar1 = 1)||<em>Returns:</em> The index (1 based position) of a given substr on or after a given starting char number if present</p>
|var=||var().<em>index</em>(substr, startchar1 = 1)||Returns: The index (1 based position) of a given substr on or after a given starting char number if present
 
<em>Returns:</em> 0 if not present.
<em>Returns:</em> 0 if not present.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.index("bc"); // 2
let v1 = "abcd"_var.index("bc"); // 2
  // or
  // or
  let v2 = index("abcd", "bc");</syntaxhighlight>
  let v2 = index("abcd", "bc");</syntaxhighlight>
|-
|-
|var=||var().<em>indexn</em>(substr, occurrence)||<em>Returns:</em> The index (1 based position) of the nth occurrence of a given substr if present</p>
|var=||var().<em>indexn</em>(substr, occurrence)||Returns: The index (1 based position) of the nth occurrence of a given substr if present
 
<em>Returns:</em> 0 if not present.
<em>Returns:</em> 0 if not present.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcabc"_var.index("bc", 2); // 2
let v1 = "abcabc"_var.index("bc", 2); // 2
  // or
  // or
  let v2 = index("abcabc", "bc", 2);</syntaxhighlight>
  let v2 = index("abcabc", "bc", 2);</syntaxhighlight>
|-
|-
|var=||var().<em>indexr</em>(substr, startchar1 = -1)||Reverse substr search.</p>
|var=||var().<em>indexr</em>(substr, startchar1 = -1)||Reverse substr search.
<em>Returns:</em> The index (1 based position) of the substr on or before a given starting char number if present</p>
 
<em>Returns:</em> The index (1 based position) of the substr on or before a given starting char number if present
 
startchar1 defaults to -1 meaning start searching from the last char (towards the first char).
startchar1 defaults to -1 meaning start searching from the last char (towards the first char).
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcabc"_var.indexr("bc"); // 5
let v1 = "abcabc"_var.indexr("bc"); // 5
  // or
  // or
  let v2 = indexr("abcabc", "bc");</syntaxhighlight>
  let v2 = indexr("abcabc", "bc");</syntaxhighlight>
|-
|-
|var=||var().<em>match</em>(regex_str, regex_options = "")||<em>Returns:</em> All results of regex matching</p>
|var=||var().<em>match</em>(regex_str, regex_options = "")||Returns: All results of regex matching
 
Multiple matches are returned separated by FMs. Groups are in VMs.
Multiple matches are returned separated by FMs. Groups are in VMs.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc1abc2"_var.match("BC(\\d)", "i"); // "bc1]1^bc2]2"_var
let v1 = "abc1abc2"_var.match("BC(\\d)", "i"); // "bc1]1^bc2]2"_var
  // or
  // or
  let v2 = match("abc1abc2", "BC(\\d)", "i");</syntaxhighlight>
  let v2 = match("abc1abc2", "BC(\\d)", "i");</syntaxhighlight>
regex_options:</p>
<em>regex_options:</em>
</p>
 
l - Literal (any regex chars are treated as normal chars)</p>
 
</p>
 
i - Case insensitive</p>
l - Literal (any regex chars are treated as normal chars)
</p>
 
p - ECMAScript/Perl (the default)</p>
 
b - Basic POSIX (same as sed)</p>
 
e - Extended POSIX</p>
i - Case insensitive
a - awk</p>
 
g - grep</p>
 
eg - egrep or grep -E</p>
 
</p>
p - ECMAScript/Perl (the default)
char ranges like a-z are locale sensitive if ECMAScript</p>
 
</p>
b - Basic POSIX (same as sed)
m - Multiline. Default in boost (and therefore exodus)</p>
 
s - Single line. Default in std::regex</p>
e - Extended POSIX
</p>
 
f - First only. Only for replace() (not match() or search())</p>
a - awk
</p>
 
w - Wildcard glob style (e.g. *.cfg) not regex style. Only for match() and search(). Not replace().
g - grep
|-
 
|var=||var().<em>match</em>(regex)||Ditto
eg - egrep or grep -E
|-
 
|var=||var().<em>search</em>(regex_str, io startchar1, regex_options = "")||Search for first match of a regular expression starting at startchar1</p>
 
Updates startchar1 ready to search for the next match</p>
 
regex_options as for match()
char ranges like a-z are locale sensitive if ECMAScript
<syntaxhighlight lang="c++">
 
var startchar1 = 1;
 
let v1 = "abc1abc2"_var.search("BC(\\d)", startchar1, "i"); // "bc1]1"_var // startchar1 -> 5 /// Ready for the next search
 
// or
m - Multiline. Default in boost (and therefore exodus)
startchar1 = 1;
 
let v2 = search("abc1abc2", "BC(\\d)", startchar1, "i");</syntaxhighlight>
s - Single line. Default in std::regex
 
 
 
f - First only. Only for replace() (not match() or search())
 
 
 
w - Wildcard glob style (e.g. *.cfg) not regex style. Only for match() and search(). Not replace().
|-
|-
|var=||var().<em>search</em>(regex_str)||Ditto starting from first char
|var=||var().<em>match</em>(regex)||Ditto
|-
|-
|var=||var().<em>search</em>(regex, io startchar1)||Ditto given a rex
|var=||var().<em>search</em>(regex_str, io startchar1, regex_options = "")||Search for first match of a regular expression starting at startchar1
 
Updates startchar1 ready to search for the next match
 
regex_options as for match()
<syntaxhighlight lang="c++">
var startchar1 = 1;
let v1 = "abc1abc2"_var.search("BC(\\d)", startchar1, "i"); // "bc1]1"_var // startchar1 -> 5 /// Ready for the next search
// or
startchar1 = 1;
let v2 = search("abc1abc2", "BC(\\d)", startchar1, "i");</syntaxhighlight>
|-
|var=||var().<em>search</em>(regex_str)||Ditto starting from first char
|-
|var=||var().<em>search</em>(regex, io startchar1)||Ditto given a rex
|-
|-
|var=||var().<em>search</em>(regex)||Ditto starting from first char.
|var=||var().<em>search</em>(regex)||Ditto starting from first char.
|-
|-
|var=||var().<em>hash</em>(std::uint64_t modulus = 0)||Hash by default returns a 64 bit signed integer as a var.</p>
|var=||var().<em>hash</em>(std::uint64_t modulus = 0)||Hash by default returns a 64 bit signed integer as a var.
If a modulus is provided then the result is limited to [0, modulus)</p>
 
If a modulus is provided then the result is limited to [0, modulus)
 
MurmurHash3 is used.
MurmurHash3 is used.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.hash(); assert(v1 == var(6'715'211'243'465'481'821));
let v1 = "abc"_var.hash(); assert(v1 == var(6'715'211'243'465'481'821));
  // or
  // or
  let v2 = hash("abc");</syntaxhighlight>
  let v2 = hash("abc");</syntaxhighlight>
Line 216: Line 254:
|var=||var().<em>ucase</em>()||To upper case
|var=||var().<em>ucase</em>()||To upper case
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"
let v1 = "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"
  // or
  // or
  let v2 = ucase("Γιάννης");</syntaxhighlight>
  let v2 = ucase("Γιάννης");</syntaxhighlight>
Line 222: Line 260:
|var=||var().<em>lcase</em>()||To lower case
|var=||var().<em>lcase</em>()||To lower case
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"
let v1 = "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"
  // or
  // or
  let v2 = lcase("ΓΙΆΝΝΗΣ");</syntaxhighlight>
  let v2 = lcase("ΓΙΆΝΝΗΣ");</syntaxhighlight>
Line 228: Line 266:
|var=||var().<em>tcase</em>()||To title case. The first letter of each word is capitalised.
|var=||var().<em>tcase</em>()||To title case. The first letter of each word is capitalised.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "γιάννης παππάς"_var.tcase(); // "Γιάννης Παππάς"
let v1 = "γιάννης παππάς"_var.tcase(); // "Γιάννης Παππάς"
  // or
  // or
  let v2 = tcase("γιάννης παππάς");</syntaxhighlight>
  let v2 = tcase("γιάννης παππάς");</syntaxhighlight>
|-
|-
|var=||var().<em>fcase</em>()||To folded case to enable standardised indexing and searching,</p>
|var=||var().<em>fcase</em>()||To folded case to enable standardised indexing and searching,
</p>
 
Case folding is a process of converting a text to case independent representation.</p>
 
https://www.w3.org/International/wiki/Case_folding</p>
 
Accents can be significant. As in French cote, coté, côte and côté.</p>
Case folding is a process of converting a text to case independent representation.
 
https://www.w3.org/International/wiki/Case_folding
 
Accents can be significant. As in French cote, coté, côte and côté.
 
Case folding is not locale-dependent.
Case folding is not locale-dependent.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "Grüßen"_var.fcase(); // "grüssen"
let v1 = "Grüßen"_var.fcase(); // "grüssen"
  // or
  // or
  let v2 = tcase("Grüßen");</syntaxhighlight>
  let v2 = tcase("Grüßen");</syntaxhighlight>
|-
|-
|var=||var().<em>normalize</em>()||Normalises unicode code points sequences to their standardised NFC form making them binary comparable.</p>
|var=||var().<em>normalize</em>()||Normalises unicode code points sequences to their standardised NFC form making them binary comparable.
</p>
 
Unicode normalization is the process of converting strings to a standard form, suitable for text processing and comparison, and is an important part of Unicode text processing.</p>
 
For example, character "é" can be represented by a single code point "\u00E9" (Latin Small Letter E with Acute) or a combination of the character "e" and the combining acute accent "\u0301".</p>
 
Unicode normalization is the process of converting strings to a standard form, suitable for text processing and comparison, and is an important part of Unicode text processing.
 
For example, character "é" can be represented by a single code point "\u00E9" (Latin Small Letter E with Acute) or a combination of the character "e" and the combining acute accent "\u0301".
 
Normalization is not locale-dependent.
Normalization is not locale-dependent.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "cafe\u0301"_var.normalize(); // "café"
let v1 = "cafe\u0301"_var.normalize(); // "café"
  // or
  // or
  let v2 = normalize("cafe\u0301");</syntaxhighlight>
  let v2 = normalize("cafe\u0301");</syntaxhighlight>
|-
|-
|var=||var().<em>invert</em>()||Simple reversible disguising of text</p>
|var=||var().<em>invert</em>()||Simple reversible disguising of text
invert(invert()) returns to the original text.</p>
 
invert(invert()) returns to the original text.
 
Flips bit 8 of unicode code points. Note that ASCII bytes become multibyte UTF-8 so string sizes change.
Flips bit 8 of unicode code points. Note that ASCII bytes become multibyte UTF-8 so string sizes change.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.invert(); // "\xC2" "\x9E" "\xC2" "\x9D" "\xC2" "\x9C"
let v1 = "abc"_var.invert(); // "\xC2" "\x9E" "\xC2" "\x9D" "\xC2" "\x9C"
  // or
  // or
  let v2 = invert("abc");</syntaxhighlight>
  let v2 = invert("abc");</syntaxhighlight>
Line 263: Line 312:
|var=||var().<em>lower</em>()||Convert all FM to VM, VM to SM etc.
|var=||var().<em>lower</em>()||Convert all FM to VM, VM to SM etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a1^b2^c3"_var.lower(); // "a1]b2]c3"_var
let v1 = "a1^b2^c3"_var.lower(); // "a1]b2]c3"_var
  // or
  // or
  let v2 = lower("a1^b2^c3"_var);</syntaxhighlight>
  let v2 = lower("a1^b2^c3"_var);</syntaxhighlight>
Line 269: Line 318:
|var=||var().<em>raise</em>()||Convert all VM to FM, SM to VM etc.
|var=||var().<em>raise</em>()||Convert all VM to FM, SM to VM etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a1]b2]c3"_var.raise(); // "a1^b2^c3"_var
let v1 = "a1]b2]c3"_var.raise(); // "a1^b2^c3"_var
  // or
  // or
  let v2 = "a1]b2]c3"_var;</syntaxhighlight>
  let v2 = "a1]b2]c3"_var;</syntaxhighlight>
Line 275: Line 324:
|var=||var().<em>crop</em>()||Remove any redundant FM, VM etc. characters (Trailing FM; VM before FM etc.)
|var=||var().<em>crop</em>()||Remove any redundant FM, VM etc. characters (Trailing FM; VM before FM etc.)
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a1^b2]]^c3^^"_var.crop(); // "a1^b2^c3"_var
let v1 = "a1^b2]]^c3^^"_var.crop(); // "a1^b2^c3"_var
  // or
  // or
  let v2 = crop("a1^b2]]^c3^^"_var);</syntaxhighlight>
  let v2 = crop("a1^b2]]^c3^^"_var);</syntaxhighlight>
Line 281: Line 330:
|var=||var().<em>quote</em>()||Wrap in double quotes
|var=||var().<em>quote</em>()||Wrap in double quotes
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.quote(); // "\"abc\""
let v1 = "abc"_var.quote(); // "\"abc\""
  // or
  // or
  let v2 = quote("abc");</syntaxhighlight>
  let v2 = quote("abc");</syntaxhighlight>
Line 287: Line 336:
|var=||var().<em>squote</em>()||Wrap in single quotes
|var=||var().<em>squote</em>()||Wrap in single quotes
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.squote(); // "'abc'"
let v1 = "abc"_var.squote(); // "'abc'"
  // or
  // or
  let v2 = squote("abc");</syntaxhighlight>
  let v2 = squote("abc");</syntaxhighlight>
Line 293: Line 342:
|var=||var().<em>unquote</em>()||Remove one pair of double or single quotes
|var=||var().<em>unquote</em>()||Remove one pair of double or single quotes
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "'abc'"_var.unquote(); // "abc"
let v1 = "'abc'"_var.unquote(); // "abc"
  // or
  // or
  let v2 = unquote("'abc'");</syntaxhighlight>
  let v2 = unquote("'abc'");</syntaxhighlight>
Line 299: Line 348:
|var=||var().<em>trim</em>(trimchars = " ")||Remove leading, trailing and excessive inner bytes
|var=||var().<em>trim</em>(trimchars = " ")||Remove leading, trailing and excessive inner bytes
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trim(); // "a1␣b2␣c3"
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trim(); // "a1␣b2␣c3"
  // or
  // or
  let v2 = trim("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
  let v2 = trim("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
Line 305: Line 354:
|var=||var().<em>trimfirst</em>(trimchars = " ")||Ditto leading
|var=||var().<em>trimfirst</em>(trimchars = " ")||Ditto leading
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimfirst(); // "a1␣␣b2␣c3␣␣"
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimfirst(); // "a1␣␣b2␣c3␣␣"
  // or
  // or
  let v2 = trimfirst("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
  let v2 = trimfirst("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
Line 311: Line 360:
|var=||var().<em>trimlast</em>(trimchars = " ")||Ditto trailing
|var=||var().<em>trimlast</em>(trimchars = " ")||Ditto trailing
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimlast(); // "␣␣a1␣␣b2␣c3"
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimlast(); // "␣␣a1␣␣b2␣c3"
  // or
  // or
  let v2 = trimlast("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
  let v2 = trimlast("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
Line 317: Line 366:
|var=||var().<em>trimboth</em>(trimchars = " ")||Ditto leading, trailing but not inner
|var=||var().<em>trimboth</em>(trimchars = " ")||Ditto leading, trailing but not inner
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimboth(); // "a1␣␣b2␣c3"
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimboth(); // "a1␣␣b2␣c3"
  // or
  // or
  let v2 = trimboth("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
  let v2 = trimboth("␣␣a1␣␣b2␣c3␣␣");</syntaxhighlight>
Line 323: Line 372:
|var=||var().<em>first</em>()||Extract first char or "" if empty
|var=||var().<em>first</em>()||Extract first char or "" if empty
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.first(); // "a"
let v1 = "abc"_var.first(); // "a"
  // or
  // or
  let v2 = first("abc");</syntaxhighlight>
  let v2 = first("abc");</syntaxhighlight>
Line 329: Line 378:
|var=||var().<em>last</em>()||Extract last char or "" if empty
|var=||var().<em>last</em>()||Extract last char or "" if empty
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.last(); // "c"
let v1 = "abc"_var.last(); // "c"
  // or
  // or
  let v2 = last("abc");</syntaxhighlight>
  let v2 = last("abc");</syntaxhighlight>
Line 335: Line 384:
|var=||var().<em>first</em>(std::size_t length)||Extract up to length leading chars
|var=||var().<em>first</em>(std::size_t length)||Extract up to length leading chars
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.first(2); // "ab"
let v1 = "abc"_var.first(2); // "ab"
  // or
  // or
  let v2 = first("abc", 2);</syntaxhighlight>
  let v2 = first("abc", 2);</syntaxhighlight>
Line 341: Line 390:
|var=||var().<em>last</em>(std::size_t length)||Extract up to length trailing chars
|var=||var().<em>last</em>(std::size_t length)||Extract up to length trailing chars
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.last(2); // "bc"
let v1 = "abc"_var.last(2); // "bc"
  // or
  // or
  let v2 = last("abc", 2);</syntaxhighlight>
  let v2 = last("abc", 2);</syntaxhighlight>
Line 347: Line 396:
|var=||var().<em>cut</em>(length)||Remove length leading chars
|var=||var().<em>cut</em>(length)||Remove length leading chars
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.cut(2); // "cd"
let v1 = "abcd"_var.cut(2); // "cd"
  // or
  // or
  let v2 = cut("abcd", 2);</syntaxhighlight>
  let v2 = cut("abcd", 2);</syntaxhighlight>
Line 353: Line 402:
|var=||var().<em>paste</em>(pos1, length, insertstr)||Insert text at char position overwriting length chars
|var=||var().<em>paste</em>(pos1, length, insertstr)||Insert text at char position overwriting length chars
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.paste(2, 2, "XYZ"); // "aXYZd"
let v1 = "abcd"_var.paste(2, 2, "XYZ"); // "aXYZd"
  // or
  // or
  let v2 = paste("abcd", 2, 2, "XYZ");</syntaxhighlight>
  let v2 = paste("abcd", 2, 2, "XYZ");</syntaxhighlight>
Line 359: Line 408:
|var=||var().<em>paste</em>(pos1, insertstr)||Insert text at char position without overwriting any following characters
|var=||var().<em>paste</em>(pos1, insertstr)||Insert text at char position without overwriting any following characters
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.paste(2, "XYZ"); // "aXYZbcd"
let v1 = "abcd"_var.paste(2, "XYZ"); // "aXYZbcd"
  // or
  // or
  let v2 = paste("abcd", 2, "XYZ");</syntaxhighlight>
  let v2 = paste("abcd", 2, "XYZ");</syntaxhighlight>
Line 365: Line 414:
|var=||var().<em>prefix</em>(insertstr)||Insert text at the beginning
|var=||var().<em>prefix</em>(insertstr)||Insert text at the beginning
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.prefix("XYZ"); // "XYZabc"
let v1 = "abc"_var.prefix("XYZ"); // "XYZabc"
  // or
  // or
  let v2 = prefix("abc", "XYZ");</syntaxhighlight>
  let v2 = prefix("abc", "XYZ");</syntaxhighlight>
Line 371: Line 420:
|var=||var().<em>append</em>(appendable, ...)||Append text at the end
|var=||var().<em>append</em>(appendable, ...)||Append text at the end
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.append(" is ", 10, " ok", '.'); // "abc is 10 ok."
let v1 = "abc"_var.append(" is ", 10, " ok", '.'); // "abc is 10 ok."
  // or
  // or
  let v2 = append("abc", " is ", 10, " ok", '.');</syntaxhighlight>
  let v2 = append("abc", " is ", 10, " ok", '.');</syntaxhighlight>
Line 377: Line 426:
|var=||var().<em>pop</em>()||Remove one trailing char
|var=||var().<em>pop</em>()||Remove one trailing char
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc"_var.pop(); // "ab"
let v1 = "abc"_var.pop(); // "ab"
  // or
  // or
  let v2 = pop("abc");</syntaxhighlight>
  let v2 = pop("abc");</syntaxhighlight>
Line 383: Line 432:
|var=||var().<em>field</em>(strx, fieldnx = 1, nfieldsx = 1)||Extract one or more consecutive fields given a delimiter char or substr.
|var=||var().<em>field</em>(strx, fieldnx = 1, nfieldsx = 1)||Extract one or more consecutive fields given a delimiter char or substr.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "aa*bb*cc"_var.field("*", 2); // "bb"
let v1 = "aa*bb*cc"_var.field("*", 2); // "bb"
  // or
  // or
  let v2 = field("aa*bb*cc", "*", 2);</syntaxhighlight>
  let v2 = field("aa*bb*cc", "*", 2);</syntaxhighlight>
|-
|-
|var=||var().<em>field2</em>(separator, fieldno, nfields = 1)||field2 is a version that treats fieldn -1 as the last field, -2 the penultimate field etc. -</p>
|var=||var().<em>field2</em>(separator, fieldno, nfields = 1)||field2 is a version that treats fieldn -1 as the last field, -2 the penultimate field etc. -
TODO Should probably make field() do this (since -1 is basically an erroneous call) and remove field2</p>
 
TODO Should probably make field() do this (since -1 is basically an erroneous call) and remove field2
 
Same as var.field() but negative fieldnos work backwards from the last field.
Same as var.field() but negative fieldnos work backwards from the last field.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "aa*bb*cc"_var.field2("*", -1); // "cc"
let v1 = "aa*bb*cc"_var.field2("*", -1); // "cc"
  // or
  // or
  let v2 = field2("aa*bb*cc", "*", -1);</syntaxhighlight>
  let v2 = field2("aa*bb*cc", "*", -1);</syntaxhighlight>
Line 397: Line 448:
|var=||var().<em>fieldstore</em>(separator, fieldno, nfields, replacement)||fieldstore() replaces n fields of subfield(s) in a string.
|var=||var().<em>fieldstore</em>(separator, fieldno, nfields, replacement)||fieldstore() replaces n fields of subfield(s) in a string.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "aa*bb*cc*dd"_var.fieldstore("*", 2, 3, "X*Y"); // "aa*X*Y*"
let v1 = "aa*bb*cc*dd"_var.fieldstore("*", 2, 3, "X*Y"); // "aa*X*Y*"
  // or
  // or
  let v2 = fieldstore("aa*bb*cc*dd", "*", 2, 3, "X*Y");</syntaxhighlight>
  let v2 = fieldstore("aa*bb*cc*dd", "*", 2, 3, "X*Y");</syntaxhighlight>
If nfields is 0 then insert fields before fieldno
If nfields is 0 then insert fields before fieldno
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, 0, "X*Y"); // "a1*X*Y*b2*c3*d4"
let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, 0, "X*Y"); // "a1*X*Y*b2*c3*d4"
  // or
  // or
  let v2 = fieldstore("a1*b2*c3*d4", "*", 2, 0, "X*Y");</syntaxhighlight>
  let v2 = fieldstore("a1*b2*c3*d4", "*", 2, 0, "X*Y");</syntaxhighlight>
If nfields is negative then delete abs(n) fields before inserting.
If nfields is negative then delete abs(n) fields before inserting.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, -3, "X*Y"); // "a1*X*Y"
let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, -3, "X*Y"); // "a1*X*Y"
  // or
  // or
  let v2 = fieldstore("a1*b2*c3*d4", "*", 2, -3, "X*Y");</syntaxhighlight>
  let v2 = fieldstore("a1*b2*c3*d4", "*", 2, -3, "X*Y");</syntaxhighlight>
Line 413: Line 464:
|var=||var().<em>substr</em>(pos1, length)||substr version 1. Extract length chars starting at pos1
|var=||var().<em>substr</em>(pos1, length)||substr version 1. Extract length chars starting at pos1
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.substr(2, 2); // "bc"
let v1 = "abcd"_var.substr(2, 2); // "bc"
  // or
  // or
  let v2 = substr("abcd", 2, 2);</syntaxhighlight>
  let v2 = substr("abcd", 2, 2);</syntaxhighlight>
If length is negative then work backwards and return chars reversed
If length is negative then work backwards and return chars reversed
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.substr(3, -2); // "cb"
let v1 = "abcd"_var.substr(3, -2); // "cb"
  // or
  // or
  let v2 = substr("abcd", 3, -2);</syntaxhighlight>
  let v2 = substr("abcd", 3, -2);</syntaxhighlight>
Line 426: Line 477:
|var=||var().<em>substr</em>(pos1)||substr version 2. Extract all chars from pos1 up to the end
|var=||var().<em>substr</em>(pos1)||substr version 2. Extract all chars from pos1 up to the end
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcd"_var.substr(2); // "bcd"
let v1 = "abcd"_var.substr(2); // "bcd"
  // or
  // or
  let v2 = substr("abcd", 2);</syntaxhighlight>
  let v2 = substr("abcd", 2);</syntaxhighlight>
Line 432: Line 483:
|var=||var().<em>b</em>(pos1)||Same as substr version 2.
|var=||var().<em>b</em>(pos1)||Same as substr version 2.
|-
|-
|var=||var().<em>substr</em>(pos1, delimiterchars, io pos2)||substr version 3.</p>
|var=||var().<em>substr</em>(pos1, delimiterchars, io pos2)||substr version 3.
Extract a substr starting from pos1 up to any one of some given delimiter chars</p>
 
Also returns in pos2 the pos of the following delimiter or one past the end of the string if not found.</p>
Extract a substr starting from pos1 up to any one of some given delimiter chars
 
Also returns in pos2 the pos of the following delimiter or one past the end of the string if not found.
 
Add 1 to pos2 start the next search if continuing.
Add 1 to pos2 start the next search if continuing.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var pos1a = 4, pos2a;
var pos1a = 4, pos2a;
  let v1 = "aa,bb,cc"_var.substr(pos1a, ",", pos2a); // "bb" // pos2a -> 6
  let v1 = "aa,bb,cc"_var.substr(pos1a, ",", pos2a); // "bb" // pos2a -> 6
  // or
  // or
Line 445: Line 499:
|var=||var().<em>b</em>(pos1, delimiterchars, io pos2)||Alias of substr version 3.
|var=||var().<em>b</em>(pos1, delimiterchars, io pos2)||Alias of substr version 3.
|-
|-
|var=||var().<em>substr2</em>(io pos1, out delimiterno)||substr version 4.</p>
|var=||var().<em>substr2</em>(io pos1, out delimiterno)||substr version 4.
<em>Returns:</em> A substr from a given pos1  up to the next RM/FM/VM/SM/TM/ST delimiter char.</p>
 
<em>Returns:</em> A substr from a given pos1  up to the next RM/FM/VM/SM/TM/ST delimiter char.
 
Also returns the next index/offset and the delimiter no. found (1-6) or 0 if not found.
Also returns the next index/offset and the delimiter no. found (1-6) or 0 if not found.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var pos1a = 4, delim1;
var pos1a = 4, delim1;
  let v1 = "aa^bb^cc"_var.substr2(pos1a, delim1); // "bb" // pos1a -> 7 // delim1 -> 2
  let v1 = "aa^bb^cc"_var.substr2(pos1a, delim1); // "bb" // pos1a -> 7 // delim1 -> 2
  // or
  // or
Line 459: Line 515:
|var=||var().<em>convert</em>(fromchars, tochars)||Convert chars to other chars one for one or delete where tochars is shorter.
|var=||var().<em>convert</em>(fromchars, tochars)||Convert chars to other chars one for one or delete where tochars is shorter.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abcde"_var.convert("aZd", "XY"); // "Xbce" // a is replaced and d is removed
let v1 = "abcde"_var.convert("aZd", "XY"); // "Xbce" // a is replaced and d is removed
  // or
  // or
  let v2 = convert("abcde", "aZd", "XY");</syntaxhighlight>
  let v2 = convert("abcde", "aZd", "XY");</syntaxhighlight>
Line 465: Line 521:
|var=||var().<em>textconvert</em>(fromchars, tochars)||Ditto for Unicode code points.
|var=||var().<em>textconvert</em>(fromchars, tochars)||Ditto for Unicode code points.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a🤡b😀c🌍d"_var.textconvert("🤡😀", "👋"); // "a👋bc🌍d"
let v1 = "a🤡b😀c🌍d"_var.textconvert("🤡😀", "👋"); // "a👋bc🌍d"
  // or
  // or
  let v2 = textconvert("a🤡b😀c🌍d", "🤡😀", "👋");</syntaxhighlight>
  let v2 = textconvert("a🤡b😀c🌍d", "🤡😀", "👋");</syntaxhighlight>
Line 471: Line 527:
|var=||var().<em>replace</em>(fromstr, tostr)||Replace all occurrences of a substr with another. Case sensitive
|var=||var().<em>replace</em>(fromstr, tostr)||Replace all occurrences of a substr with another. Case sensitive
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "Abc.Abc"_var.replace("bc", "X"); // "AX.AX"
let v1 = "Abc.Abc"_var.replace("bc", "X"); // "AX.AX"
  // or
  // or
  let v2 = replace("Abc Abc", "bc", "X");</syntaxhighlight>
  let v2 = replace("Abc Abc", "bc", "X");</syntaxhighlight>
|-
|-
|var=||var().<em>replace</em>(regex, tostr)||Replace substring(s) using a regular expression.</p>
|var=||var().<em>replace</em>(regex, tostr)||Replace substring(s) using a regular expression.
 
Use $0, $1, $2 in tostr to refer to groups defined in the regex.
Use $0, $1, $2 in tostr to refer to groups defined in the regex.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "A a B b"_var.replace("[A-Z]"_rex, "'$0'"); // "'A' a 'B' b"
let v1 = "A a B b"_var.replace("[A-Z]"_rex, "'$0'"); // "'A' a 'B' b"
  // or
  // or
  let v2 = replace("A a B b", "[A-Z]"_rex, "'$0'");</syntaxhighlight>
  let v2 = replace("A a B b", "[A-Z]"_rex, "'$0'");</syntaxhighlight>
Line 484: Line 541:
|var=||var().<em>unique</em>()||Remove duplicate fields in an FM or VM etc. separated list
|var=||var().<em>unique</em>()||Remove duplicate fields in an FM or VM etc. separated list
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "a1^b2^a1^c2"_var.unique(); // "a1^b2^c2"_var
let v1 = "a1^b2^a1^c2"_var.unique(); // "a1^b2^c2"_var
  // or
  // or
  let v2 = unique("a1^b2^a1^c2"_var);</syntaxhighlight>
  let v2 = unique("a1^b2^a1^c2"_var);</syntaxhighlight>
|-
|-
|var=||var().<em>sort</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in ascending order</p>
|var=||var().<em>sort</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in ascending order
Numerical:
 
<em>Numerical:</em>
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "20^10^2^1^1.1"_var.sort(); // "1^1.1^2^10^20"_var
let v1 = "20^10^2^1^1.1"_var.sort(); // "1^1.1^2^10^20"_var
  // or
  // or
  let v2 = sort("20^10^2^1^1.1"_var);</syntaxhighlight>
  let v2 = sort("20^10^2^1^1.1"_var);</syntaxhighlight>
Alphabetical:
<em>Alphabetical:</em>
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "b1^a1^c20^c10^c2^c1^b2"_var.sort(); // "a1^b1^b2^c1^c10^c2^c20"_var
let v1 = "b1^a1^c20^c10^c2^c1^b2"_var.sort(); // "a1^b1^b2^c1^c10^c2^c20"_var
  // or
  // or
  let v2 = sort("b1^a1^c20^c10^c2^c1^b2"_var);</syntaxhighlight>
  let v2 = sort("b1^a1^c20^c10^c2^c1^b2"_var);</syntaxhighlight>
Line 502: Line 560:
|var=||var().<em>reverse</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in descending order
|var=||var().<em>reverse</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in descending order
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "20^10^2^1^1.1"_var.reverse(); // "1.1^1^2^10^20"_var
let v1 = "20^10^2^1^1.1"_var.reverse(); // "1.1^1^2^10^20"_var
  // or
  // or
  let v2 = reverse("20^10^2^1^1.1"_var);</syntaxhighlight>
  let v2 = reverse("20^10^2^1^1.1"_var);</syntaxhighlight>
Line 508: Line 566:
|var=||var().<em>shuffle</em>(sepchar = FM)||Randomise the order of fields in an FM, VM separated list
|var=||var().<em>shuffle</em>(sepchar = FM)||Randomise the order of fields in an FM, VM separated list
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "20^10^2^1^1.1"_var.shuffle(); /// e.g. "2^1^20^1.1^10" (random order depending on initrand())
let v1 = "20^10^2^1^1.1"_var.shuffle(); /// e.g. "2^1^20^1.1^10" (random order depending on initrand())
  // or
  // or
  let v2 = shuffle("20^10^2^1^1.1"_var);</syntaxhighlight>
  let v2 = shuffle("20^10^2^1^1.1"_var);</syntaxhighlight>
Line 514: Line 572:
|var=||var().<em>parse</em>(char sepchar = ' ')||Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes &bsol;" &bsol;'
|var=||var().<em>parse</em>(char sepchar = ' ')||Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes &bsol;" &bsol;'
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "abc,\"def,\"123\" fgh\",12.34"_var.parse(','); // "abc^\"def,\"123\" fgh\"^12.34"_var
let v1 = "abc,\"def,\"123\" fgh\",12.34"_var.parse(','); // "abc^\"def,\"123\" fgh\"^12.34"_var
  // or
  // or
  let v2 = parse("abc,\"def,\"123\" fgh\",12.34", ',');</syntaxhighlight>
  let v2 = parse("abc,\"def,\"123\" fgh\",12.34", ',');</syntaxhighlight>
Line 523: Line 581:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|cmd||var().<em>ucaser</em>()||Upper case</p>
|cmd||var().<em>ucaser</em>()||Upper case
 
All string mutators follow the same pattern as ucaser.<br>See the non-mutating functions for details.
All string mutators follow the same pattern as ucaser.<br>See the non-mutating functions for details.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "abc";
var v1 = "abc";
  v1.ucaser(); // "ABC"
  v1.ucaser(); // "ABC"
  // or
  // or
Line 610: Line 669:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||var.<em>oconv</em>(convstr)||Converts internal data to output external display format according to a given conversion code or pattern</p>
|var=||var.<em>oconv</em>(convstr)||Converts internal data to output external display format according to a given conversion code or pattern
If the internal data is invalid and cannot be converted then most conversions return the ORIGINAL data unconverted</p>
 
Throws a runtime error VarNotImplemented if convstr is invalid</p>
If the internal data is invalid and cannot be converted then most conversions return the ORIGINAL data unconverted
 
Throws a runtime error VarNotImplemented if convstr is invalid
 
See [[#ICONV/OCONV PATTERNS]]
See [[#ICONV/OCONV PATTERNS]]
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(30123).oconv("D/E"); // "21/06/2050"
let v1 = var(30123).oconv("D/E"); // "21/06/2050"
  // or
  // or
  let v2 = oconv(30123, "D/E");</syntaxhighlight>
  let v2 = oconv(30123, "D/E");</syntaxhighlight>
|-
|-
|var=||var.<em>iconv</em>(convstr)||Converts external data to internal format according to a given conversion code or pattern</p>
|var=||var.<em>iconv</em>(convstr)||Converts external data to internal format according to a given conversion code or pattern
If the external data is invalid and cannot be converted then most conversions return the EMPTY STRING ""</p>
 
Throws a runtime error VarNotImplemented if convstr is invalid</p>
If the external data is invalid and cannot be converted then most conversions return the EMPTY STRING ""
 
Throws a runtime error VarNotImplemented if convstr is invalid
 
See [[#ICONV/OCONV PATTERNS]]
See [[#ICONV/OCONV PATTERNS]]
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "21 JUN 2050"_var.iconv("D/E"); // 30123
let v1 = "21 JUN 2050"_var.iconv("D/E"); // 30123
  // or
  // or
  let v2 = iconv("21 JUN 2050", "D/E");</syntaxhighlight>
  let v2 = iconv("21 JUN 2050", "D/E");</syntaxhighlight>
|-
|-
|var=||var.<em>format</em>(fmt_str, args, ...)||Classic format function in printf style</p>
|var=||var.<em>format</em>(fmt_str, args, ...)||Classic format function in printf style
vars can be formatted either with C++ format codes e.g. {:_>8.2f}</p>
 
vars can be formatted either with C++ format codes e.g. {:_>8.2f}
 
or with exodus oconv codes e.g. {::MD20P|R(_)#8} as in the below example.
or with exodus oconv codes e.g. {::MD20P|R(_)#8} as in the below example.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(12.345).format("'{:_>8.2f}'"); // "'___12.35'"
let v1 = var(12.345).format("'{:_>8.2f}'"); // "'___12.35'"
  let v2 = var(12.345).format("'{::MD20P|R(_)#8}'");
  let v2 = var(12.345).format("'{::MD20P|R(_)#8}'");
  // or
  // or
Line 638: Line 705:
  var v4 = format("'{::MD20P|R(_)#8}'", var(12.345));</syntaxhighlight>
  var v4 = format("'{::MD20P|R(_)#8}'", var(12.345));</syntaxhighlight>
|-
|-
|var=||var.<em>from_codepage</em>(codepage)||Converts from codepage encoded text to UTF-8 encoded text</p>
|var=||var.<em>from_codepage</em>(codepage)||Converts from codepage encoded text to UTF-8 encoded text
e.g. Codepage "CP1124" (Ukrainian).</p>
 
e.g. Codepage "CP1124" (Ukrainian).
 
Use Linux command "iconv -l" for complete list of code pages and encodings.
Use Linux command "iconv -l" for complete list of code pages and encodings.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "\xa4"_var.from_codepage("CP1124"); // "Є"
let v1 = "\xa4"_var.from_codepage("CP1124"); // "Є"
  // or
  // or
  let v2 = from_codepage("\xa4", "CP1124");
  let v2 = from_codepage("\xa4", "CP1124");
Line 649: Line 718:
|var=||var.<em>to_codepage</em>(codepage)||Converts to codepage encoded text from UTF-8 encoded text
|var=||var.<em>to_codepage</em>(codepage)||Converts to codepage encoded text from UTF-8 encoded text
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "Є"_var.to_codepage("CP1124").oconv("HEX"); // "A4"
let v1 = "Є"_var.to_codepage("CP1124").oconv("HEX"); // "A4"
  // or
  // or
  let v2 = to_codepage("Є", "CP1124").oconv("HEX");</syntaxhighlight>
  let v2 = to_codepage("Є", "CP1124").oconv("HEX");</syntaxhighlight>
Line 658: Line 727:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||var.<em>f</em>(fieldno, valueno = 0, subvalueno = 0)||f() is a highly abbreviated alias for the PICK OS field/value/subvalue extract() function.</p>
|var=||var.<em>f</em>(fieldno, valueno = 0, subvalueno = 0)||f() is a highly abbreviated alias for the PICK OS field/value/subvalue extract() function.
"f()" can be thought of as "field" although the function can extract values and subvalues as well.</p>
 
The convenient PICK OS angle bracket syntax for field extraction (e.g. xxx<20>) is not available in C++.</p>
"f()" can be thought of as "field" although the function can extract values and subvalues as well.
 
The convenient PICK OS angle bracket syntax for field extraction (e.g. xxx<20>) is not available in C++.
 
The abbreviated exodus field extraction function (e.g. xxx.f(20)) is provided instead since field access is extremely heavily used in source code.
The abbreviated exodus field extraction function (e.g. xxx.f(20)) is provided instead since field access is extremely heavily used in source code.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
  let v2 = v1.f(2, 2); // "f2v2"</syntaxhighlight>
  let v2 = v1.f(2, 2); // "f2v2"</syntaxhighlight>
|-
|-
|var=||var.<em>extract</em>(fieldno, valueno = 0, subvalueno = 0)||Extract a specific field, value or subvalue from a dynamic array.
|var=||var.<em>extract</em>(fieldno, valueno = 0, subvalueno = 0)||Extract a specific field, value or subvalue from a dynamic array.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
  let v2 = v1.extract(2, 2); // "f2v2"
  let v2 = v1.extract(2, 2); // "f2v2"
  //
  //
Line 686: Line 758:
|var=||var.<em>insert</em>(fieldno, insertion)||Ditto for a specific field
|var=||var.<em>insert</em>(fieldno, insertion)||Ditto for a specific field
|-
|-
|var=||var.<em>remove</em>(fieldno, valueno = 0, subvalueno = 0)||Same as var.remover() function but returns a new string instead of updating a variable in place.</p>
|var=||var.<em>remove</em>(fieldno, valueno = 0, subvalueno = 0)||Same as var.remover() function but returns a new string instead of updating a variable in place.
 
"remove" was called "delete" in Pick OS.
"remove" was called "delete" in Pick OS.
|}
|}
Line 696: Line 769:
|var=||var.<em>sum</em>()||Sum up multiple values into one higher level
|var=||var.<em>sum</em>()||Sum up multiple values into one higher level
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "1]2]3^4]5]6"_var.sum(); // "6^15"_var
let v1 = "1]2]3^4]5]6"_var.sum(); // "6^15"_var
  // or
  // or
  let v2 = sum("1]2]3^4]5]6"_var);</syntaxhighlight>
  let v2 = sum("1]2]3^4]5]6"_var);</syntaxhighlight>
Line 702: Line 775:
|var=||var.<em>sumall</em>()||Sum up all levels into a single figure
|var=||var.<em>sumall</em>()||Sum up all levels into a single figure
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "1]2]3^4]5]6"_var.sumall(); // 21
let v1 = "1]2]3^4]5]6"_var.sumall(); // 21
  // or
  // or
  let v2 = sumall("1]2]3^4]5]6"_var);</syntaxhighlight>
  let v2 = sumall("1]2]3^4]5]6"_var);</syntaxhighlight>
Line 708: Line 781:
|var=||var.<em>sum</em>(sepchar)||Ditto allowing commas etc.
|var=||var.<em>sum</em>(sepchar)||Ditto allowing commas etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "10,20,30"_var.sum(","); // 60
let v1 = "10,20,30"_var.sum(","); // 60
  // or
  // or
  let v2 = sum("10,20,30", ",");</syntaxhighlight>
  let v2 = sum("10,20,30", ",");</syntaxhighlight>
Line 714: Line 787:
|var=||var.<em>mv</em>(opcode, var2)||Binary ops (+, -, *, /) in parallel on multiple values
|var=||var.<em>mv</em>(opcode, var2)||Binary ops (+, -, *, /) in parallel on multiple values
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = "10]20]30"_var.mv("+","2]3]4"_var); // "12]23]34"_var</syntaxhighlight>
let v1 = "10]20]30"_var.mv("+","2]3]4"_var); // "12]23]34"_var</syntaxhighlight>
|}
|}
===== Dynamic Array Mutators Standalone Commands =====
===== Dynamic Array Mutators Standalone Commands =====
Line 723: Line 796:
|cmd||var.<em>r</em>(fieldno, replacement)||Replaces a specific field in a dynamic array
|cmd||var.<em>r</em>(fieldno, replacement)||Replaces a specific field in a dynamic array
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.r(2, "X"); // "f1^X^f3"_var</syntaxhighlight>
  v1.r(2, "X"); // "f1^X^f3"_var</syntaxhighlight>
|-
|-
|cmd||var.<em>r</em>(fieldno, valueno, replacement)||Ditto for specific value in a specific field.
|cmd||var.<em>r</em>(fieldno, valueno, replacement)||Ditto for specific value in a specific field.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.r(2, 2, "X"); // "f1^v1]X^f3"_var</syntaxhighlight>
  v1.r(2, 2, "X"); // "f1^v1]X^f3"_var</syntaxhighlight>
|-
|-
|cmd||var.<em>r</em>(fieldno, valueno, subvalueno, replacement)||Ditto for a specific subvalue in a specific value of a specific field
|cmd||var.<em>r</em>(fieldno, valueno, subvalueno, replacement)||Ditto for a specific subvalue in a specific value of a specific field
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.r(2, 2, 2, "X"); // "f1^v1]v2}X}s3^f3"_var</syntaxhighlight>
  v1.r(2, 2, 2, "X"); // "f1^v1]v2}X}s3^f3"_var</syntaxhighlight>
|-
|-
|cmd||var.<em>inserter</em>(fieldno, insertion)||Insert a specific field in a dynamic array, moving all other fields up.
|cmd||var.<em>inserter</em>(fieldno, insertion)||Insert a specific field in a dynamic array, moving all other fields up.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.inserter(2, "X"); // "f1^X^v1]v2}s2}s3^f3"_var
  v1.inserter(2, "X"); // "f1^X^v1]v2}s2}s3^f3"_var
  // or
  // or
Line 745: Line 818:
|cmd||var.<em>inserter</em>(fieldno, valueno, insertion)||Ditto for a specific value in a specific field, moving all other values up.
|cmd||var.<em>inserter</em>(fieldno, valueno, insertion)||Ditto for a specific value in a specific field, moving all other values up.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.inserter(2, 2, "X"); // "f1^v1]X]v2}s2}s3^f3"_var
  v1.inserter(2, 2, "X"); // "f1^v1]X]v2}s2}s3^f3"_var
  // or
  // or
Line 752: Line 825:
|cmd||var.<em>inserter</em>(fieldno, valueno, subvalueno, insertion)||Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
|cmd||var.<em>inserter</em>(fieldno, valueno, subvalueno, insertion)||Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.inserter(2, 2, 2, "X"); // "f1^v1]v2}X}s2}s3^f3"_var
  v1.inserter(2, 2, 2, "X"); // "f1^v1]v2}X}s2}s3^f3"_var
  // or
  // or
Line 759: Line 832:
|cmd||var.<em>remover</em>(fieldno, valueno = 0, subvalueno = 0)||Remove a specific field (or value, or subvalue) from a dynamic array, moving all other fields (or values, or subvalues)  down.
|cmd||var.<em>remover</em>(fieldno, valueno = 0, subvalueno = 0)||Remove a specific field (or value, or subvalue) from a dynamic array, moving all other fields (or values, or subvalues)  down.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
var v1 = "f1^v1]v2}s2}s3^f3"_var;
  v1.remover(2, 2); // "f1^v1^f3"_var
  v1.remover(2, 2); // "f1^v1^f3"_var
  // or
  // or
Line 769: Line 842:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||var.<em>locate</em>(target)||locate() with only the target substr argument provided searches unordered values separated by any of the field mark chars.</p>
|var=||var.<em>locate</em>(target)||locate() with only the target substr argument provided searches unordered values separated by any of the field mark chars.
 
<em>Returns:</em> The field, value, subvalue etc. number if found or 0 if not.
<em>Returns:</em> The field, value, subvalue etc. number if found or 0 if not.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if ("UK^US^UA"_var.locate("US")) ... ok // 2
if ("UK^US^UA"_var.locate("US")) ... ok // 2
  // or
  // or
  if (locate("US", "UK^US^UA"_var)) ... ok</syntaxhighlight>
  if (locate("US", "UK^US^UA"_var)) ... ok</syntaxhighlight>
|-
|-
|if||var.<em>locate</em>(target, out valueno)||locate() with only the target substr provided and setting returned searches unordered values separated by any type of field mark chars.</p>
|if||var.<em>locate</em>(target, out valueno)||locate() with only the target substr provided and setting returned searches unordered values separated by any type of field mark chars.
<em>Returns:</em> True if found</p>
 
Setting: Field, value, subvalue etc. number if found or the max number + 1 if not. Suitable for additiom of new values
<em>Returns:</em> True if found
 
<em>Setting:</em> Field, value, subvalue etc. number if found or the max number + 1 if not. Suitable for additiom of new values
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var setting;
var setting;
  if ("UK]US]UA"_var.locate("US", setting)) ... ok // setting -> 2
  if ("UK]US]UA"_var.locate("US", setting)) ... ok // setting -> 2
  // or
  // or
  if (locate("US", "UK]US]UA"_var, setting)) ... ok</syntaxhighlight>
  if (locate("US", "UK]US]UA"_var, setting)) ... ok</syntaxhighlight>
|-
|-
|if||var.<em>locate</em>(target, out setting, fieldno, valueno = 0)||locate() the target in unordered fields if fieldno is 0, or values if a fieldno is specified, or subvalues if the valueno argument is provided.</p>
|if||var.<em>locate</em>(target, out setting, fieldno, valueno = 0)||locate() the target in unordered fields if fieldno is 0, or values if a fieldno is specified, or subvalues if the valueno argument is provided.
<em>Returns:</em> True if found and with the field, value or subvalue number in setting.</p>
 
<em>Returns:</em> True if found and with the field, value or subvalue number in setting.
 
<em>Returns:</em> False if not found and with the max field, value or subvalue number found + 1 in setting. Suitable for replacement of new fields, values or subvalues.
<em>Returns:</em> False if not found and with the max field, value or subvalue number found + 1 in setting. Suitable for replacement of new fields, values or subvalues.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var setting;
var setting;
  if ("f1^f2v1]f2v2]s1}s2}s3}s4^f3^f4"_var.locate("s4", setting, 2, 3)) ... ok // setting -> 4 // returns true</syntaxhighlight>
  if ("f1^f2v1]f2v2]s1}s2}s3}s4^f3^f4"_var.locate("s4", setting, 2, 3)) ... ok // setting -> 4 // returns true</syntaxhighlight>
|-
|-
|if||var.<em>locateby</em>(ordercode, target, out valueno)||locateby() without fieldno or valueno arguments searches ordered values separated by VM chars.</p>
|if||var.<em>locateby</em>(ordercode, target, out valueno)||locateby() without fieldno or valueno arguments searches ordered values separated by VM chars.
The order code can be AL, DL, AR, DR meaning Ascending Left, Descending Right, Ascending Right, Ascending Left.</p>
 
Left is used to indicate alphabetic order where 10 < 2.</p>
The order code can be AL, DL, AR, DR meaning Ascending Left, Descending Right, Ascending Right, Ascending Left.
Right is used to indicate numeric order where 10 > 2.</p>
 
Data must be in the correct order for searching to work properly.</p>
Left is used to indicate alphabetic order where 10 < 2.
<em>Returns:</em> True if found.</p>
 
Right is used to indicate numeric order where 10 > 2.
 
Data must be in the correct order for searching to work properly.
 
<em>Returns:</em> True if found.
 
In case the target is not exactly found then the correct value no for inserting the target is returned in setting.
In case the target is not exactly found then the correct value no for inserting the target is returned in setting.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var valueno; if ("aaa]bbb]ccc"_var.locateby("AL", "bb", valueno)) ... // valueno -> 2 // returns false and valueno = where it could be correctly inserted.</syntaxhighlight>
var valueno; if ("aaa]bbb]ccc"_var.locateby("AL", "bb", valueno)) ... // valueno -> 2 // returns false and valueno = where it could be correctly inserted.</syntaxhighlight>
|-
|-
|if||var.<em>locateby</em>(ordercode, target, out setting, fieldno, valueno = 0)||locateby() ordered as above but in fields if fieldno is 0, or values in a specific fieldno, or subvalues in a specific valueno.
|if||var.<em>locateby</em>(ordercode, target, out setting, fieldno, valueno = 0)||locateby() ordered as above but in fields if fieldno is 0, or values in a specific fieldno, or subvalues in a specific valueno.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var setting;
var setting;
  if ("f1^f2^aaa]bbb]ccc^f4"_var.locateby("AL", "bb", setting, 3)) ... // setting -> 2 // return false and where it could be correctly inserted.</syntaxhighlight>
  if ("f1^f2^aaa]bbb]ccc^f4"_var.locateby("AL", "bb", setting, 3)) ... // setting -> 2 // return false and where it could be correctly inserted.</syntaxhighlight>
|-
|-
|if||var.<em>locateusing</em>(usingchar, target)||locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
|if||var.<em>locateusing</em>(usingchar, target)||locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if ("AB,EF,CD"_var.locateusing(",", "EF")) ... ok</syntaxhighlight>
if ("AB,EF,CD"_var.locateusing(",", "EF")) ... ok</syntaxhighlight>
|-
|-
|if||var.<em>locateusing</em>(usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)||locate() the target in a specific field, value or subvalue using a specified delimiter and unordered data</p>
|if||var.<em>locateusing</em>(usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)||locate() the target in a specific field, value or subvalue using a specified delimiter and unordered data
<em>Returns:</em> True If found and returns in setting the number of the delimited field found.</p>
 
<em>Returns:</em> False if not found and returns in setting the maximum number of delimited fields + 1 if not found.</p>
<em>Returns:</em> True If found and returns in setting the number of the delimited field found.
 
<em>Returns:</em> False if not found and returns in setting the maximum number of delimited fields + 1 if not found.
 
This is similar to the main locate command but the delimiter char can be specified e.g. a comma or TM etc.
This is similar to the main locate command but the delimiter char can be specified e.g. a comma or TM etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var setting;
var setting;
  if ("f1^f2^f3c1,f3c2,f3c3^f4"_var.locateusing(",", "f3c2", setting, 3)) ... ok // setting -> 2 // returns true</syntaxhighlight>
  if ("f1^f2^f3c1,f3c2,f3c3^f4"_var.locateusing(",", "f3c2", setting, 3)) ... ok // setting -> 2 // returns true</syntaxhighlight>
|-
|-
|if||var.<em>locatebyusing</em>(ordercode, usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)||locatebyusing() supports all the above features in a single function.</p>
|if||var.<em>locatebyusing</em>(ordercode, usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)||locatebyusing() supports all the above features in a single function.
 
<em>Returns:</em> True if found.
<em>Returns:</em> True if found.
|}
|}
Line 827: Line 915:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|if||conn.<em>connect</em>(conninfo = "")||For all db operations, the operative var can either be a db connection created with dbconnect() or be any var and a default connection will be established on the fly.</p>
|if||conn.<em>connect</em>(conninfo = "")||For all db operations, the operative var can either be a db connection created with dbconnect() or be any var and a default connection will be established on the fly.
The db connection string (conninfo) parameters are merged from the following places in descending priority.</p>
 
1. Provided in connect()'s conninfo argument. See 4. for the complete list of parameters.</p>
The db connection string (conninfo) parameters are merged from the following places in descending priority.
2. Any environment variables EXO_HOST EXO_PORT EXO_USER EXO_DATA EXO_PASS EXO_TIME</p>
 
3. Any parameters found in a configuration file at ~/.config/exodus/exodus.cfg</p>
1. Provided in connect()'s conninfo argument. See 4. for the complete list of parameters.
4. The default conninfo is "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10"</p>
 
2. Any environment variables EXO_HOST EXO_PORT EXO_USER EXO_DATA EXO_PASS EXO_TIME
 
3. Any parameters found in a configuration file at ~/.config/exodus/exodus.cfg
 
4. The default conninfo is "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10"
 
Setting environment variable EXO_DBTRACE=1 will cause tracing of db interface including SQL commands.
Setting environment variable EXO_DBTRACE=1 will cause tracing of db interface including SQL commands.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let conninfo = "dbname=exodus user=exodus password=somesillysecret";
let conninfo = "dbname=exodus user=exodus password=somesillysecret";
  if (not conn.connect(conninfo)) ...;
  if (not conn.connect(conninfo)) ...;
  // or
  // or
Line 842: Line 936:
  if (not connect("exodus")) ...</syntaxhighlight>
  if (not connect("exodus")) ...</syntaxhighlight>
|-
|-
|if||conn.<em>attach</em>(filenames)||Attach (connect) specific files by name to specific connections.</p>
|if||conn.<em>attach</em>(filenames)||Attach (connect) specific files by name to specific connections.
It is not necessary to attach files before opening them. Attach is meant to control the defaults.</p>
 
For the remainder of the session, opening the db file by name without specifying a connection will automatically use the specified connection applies during the attach command.</p>
It is not necessary to attach files before opening them. Attach is meant to control the defaults.
If conn is not specified then filename will be attached to the default connection.</p>
 
For the remainder of the session, opening the db file by name without specifying a connection will automatically use the specified connection applies during the attach command.
 
If conn is not specified then filename will be attached to the default connection.
 
Multiple file names must be separated by FM
Multiple file names must be separated by FM
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let filenames = "definitions^dict.definitions"_var, conn = "exodus";
let filenames = "definitions^dict.definitions"_var, conn = "exodus";
  if (conn.attach(filenames)) ... ok
  if (conn.attach(filenames)) ... ok
  // or
  // or
Line 857: Line 955:
|if||conn.<em>begintrans</em>()||Begin a db transaction.
|if||conn.<em>begintrans</em>()||Begin a db transaction.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if (not conn.begintrans()) ...
if (not conn.begintrans()) ...
  // or
  // or
  if (not begintrans()) ...</syntaxhighlight>
  if (not begintrans()) ...</syntaxhighlight>
Line 863: Line 961:
|if||conn.<em>statustrans</em>()||Check if a db transaction is in progress.
|if||conn.<em>statustrans</em>()||Check if a db transaction is in progress.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if (conn.statustrans()) ... ok
if (conn.statustrans()) ... ok
  // or
  // or
  if (statustrans()) ... ok</syntaxhighlight>
  if (statustrans()) ... ok</syntaxhighlight>
Line 869: Line 967:
|if||conn.<em>rollbacktrans</em>()||Rollback a db transaction.
|if||conn.<em>rollbacktrans</em>()||Rollback a db transaction.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if (conn.rollbacktrans()) ... ok
if (conn.rollbacktrans()) ... ok
  // or
  // or
  if (rollbacktrans()) ... ok</syntaxhighlight>
  if (rollbacktrans()) ... ok</syntaxhighlight>
|-
|-
|if||conn.<em>committrans</em>()||Commit a db transaction.</p>
|if||conn.<em>committrans</em>()||Commit a db transaction.
 
<em>Returns:</em> True if successfully committed or if there was no transaction in progress, otherwise false.
<em>Returns:</em> True if successfully committed or if there was no transaction in progress, otherwise false.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if (conn.committrans()) ... ok
if (conn.committrans()) ... ok
  // or
  // or
  if (committrans()) ... ok</syntaxhighlight>
  if (committrans()) ... ok</syntaxhighlight>
|-
|-
|if||conn.<em>sqlexec</em>(sqlcmd)||Execute an sql command.</p>
|if||conn.<em>sqlexec</em>(sqlcmd)||Execute an sql command.
 
<em>Returns:</em> True if there was no sql error otherwise lasterror() returns a detailed error message.
<em>Returns:</em> True if there was no sql error otherwise lasterror() returns a detailed error message.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if (conn.sqlexec("vacuum")) ... ok
if (conn.sqlexec("vacuum")) ... ok
  // or
  // or
  if (sqlexec("vacuum")) ... ok</syntaxhighlight>
  if (sqlexec("vacuum")) ... ok</syntaxhighlight>
|-
|-
|if||conn.<em>sqlexec</em>(sqlcmd, io response)||Execute an SQL command and capture the response.</p>
|if||conn.<em>sqlexec</em>(sqlcmd, io response)||Execute an SQL command and capture the response.
<em>Returns:</em> True if there was no sql error otherwise response contains a detailed error message.</p>
 
response: Any rows and columns returned are separated by RM and FM respectively. The first row is the column names.</p>
<em>Returns:</em> True if there was no sql error otherwise response contains a detailed error message.
Recommended: Don't use sql directly unless you must to manage or configure a database.
 
<em>response:</em> Any rows and columns returned are separated by RM and FM respectively. The first row is the column names.
 
<em>Recommended:</em> Don't use sql directly unless you must to manage or configure a database.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let sqlcmd = "select 'xxx' as col1, 'yyy' as col2";
let sqlcmd = "select 'xxx' as col1, 'yyy' as col2";
  var response;
  var response;
  if (conn.sqlexec(sqlcmd, response)) ... ok // response -> "col1^col2\x1fxxx^yyy"_var /// \x1f is the Record Mark (RM) character. The backtick character is used here by gendoc to deliminate source code.
  if (conn.sqlexec(sqlcmd, response)) ... ok // response -> "col1^col2\x1fxxx^yyy"_var /// \x1f is the Record Mark (RM) character. The backtick character is used here by gendoc to deliminate source code.
Line 900: Line 1,003:
|cmd||conn.<em>disconnect</em>()||Closes db connection and frees process resources both locally and in the database server.
|cmd||conn.<em>disconnect</em>()||Closes db connection and frees process resources both locally and in the database server.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
conn.disconnect();
conn.disconnect();
  // or
  // or
  disconnect();</syntaxhighlight>
  disconnect();</syntaxhighlight>
|-
|-
|cmd||conn.<em>disconnectall</em>()||Closes all connections and frees process resources both locally and in the database server(s).</p>
|cmd||conn.<em>disconnectall</em>()||Closes all connections and frees process resources both locally and in the database server(s).
 
All connections are closed automatically when a process terminates.
All connections are closed automatically when a process terminates.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
conn.disconnectall();
conn.disconnectall();
  // or
  // or
  disconnectall();</syntaxhighlight>
  disconnectall();</syntaxhighlight>
|-
|-
|var=||conn.<em>lasterror</em>()||<em>Returns:</em> The last os or db error message.
|var=||conn.<em>lasterror</em>()||Returns: The last os or db error message.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = var().lasterror();
var v1 = var().lasterror();
  // or
  // or
  var v2 = lasterror();</syntaxhighlight>
  var v2 = lasterror();</syntaxhighlight>
|-
|-
|var=||conn.<em>loglasterror</em>(source = "")||Log the last os or db error message.</p>
|var=||conn.<em>loglasterror</em>(source = "")||Log the last os or db error message.
Output: to stdlog</p>
 
<em>Output:</em> to stdlog
 
Prefixes the output with source if provided.
Prefixes the output with source if provided.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var().loglasterror("main:");
var().loglasterror("main:");
  // or
  // or
  loglasterror("main:");</syntaxhighlight>
  loglasterror("main:");</syntaxhighlight>
Line 930: Line 1,036:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|if||conn.<em>dbcreate</em>(new_dbname, old_dbname = "")||Create a named database on a particular connection.</p>
|if||conn.<em>dbcreate</em>(new_dbname, old_dbname = "")||Create a named database on a particular connection.
The target database cannot already exist.</p>
 
The target database cannot already exist.
 
Optionally copies an existing database from the same connection and which cannot have any current connections.
Optionally copies an existing database from the same connection and which cannot have any current connections.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "exodus";
var conn = "exodus";
  if (not dbdelete("xo_gendoc_testdb")) {}; // Cleanup first
  if (not dbdelete("xo_gendoc_testdb")) {}; // Cleanup first
  if (conn.dbcreate("xo_gendoc_testdb")) ... ok
  if (conn.dbcreate("xo_gendoc_testdb")) ... ok
Line 940: Line 1,048:
  if (dbcreate("xo_gendoc_testdb")) ...</syntaxhighlight>
  if (dbcreate("xo_gendoc_testdb")) ...</syntaxhighlight>
|-
|-
|if||conn.<em>dbcopy</em>(from_dbname, to_dbname)||Create a named database as a copy of an existing database.</p>
|if||conn.<em>dbcopy</em>(from_dbname, to_dbname)||Create a named database as a copy of an existing database.
The target database cannot already exist.</p>
 
The target database cannot already exist.
 
The source database must exist on the same connection and cannot have any current connections.
The source database must exist on the same connection and cannot have any current connections.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "exodus";
var conn = "exodus";
  if (not dbdelete("xo_gendoc_testdb2")) {}; // Cleanup first
  if (not dbdelete("xo_gendoc_testdb2")) {}; // Cleanup first
  if (conn.dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ... ok
  if (conn.dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ... ok
Line 950: Line 1,060:
  if (dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ...</syntaxhighlight>
  if (dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ...</syntaxhighlight>
|-
|-
|var=||conn.<em>dblist</em>()||<em>Returns:</em> A list of available databases on a particular connection.
|var=||conn.<em>dblist</em>()||Returns: A list of available databases on a particular connection.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = conn.dblist();
let v1 = conn.dblist();
  // or
  // or
  let v2 = dblist();</syntaxhighlight>
  let v2 = dblist();</syntaxhighlight>
|-
|-
|if||conn.<em>dbdelete</em>(dbname)||Delete (drop) a named database.</p>
|if||conn.<em>dbdelete</em>(dbname)||Delete (drop) a named database.
 
The target database must exist and cannot have any current connections.
The target database must exist and cannot have any current connections.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "exodus";
var conn = "exodus";
  if (conn.dbdelete("xo_gendoc_testdb2")) ... ok
  if (conn.dbdelete("xo_gendoc_testdb2")) ... ok
  // or
  // or
Line 966: Line 1,077:
|if||conn.<em>createfile</em>(filename)||Create a named db file.
|if||conn.<em>createfile</em>(filename)||Create a named db file.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let filename = "xo_gendoc_temp", conn = "exodus";
let filename = "xo_gendoc_temp", conn = "exodus";
  if (conn.createfile(filename)) ... ok
  if (conn.createfile(filename)) ... ok
  // or
  // or
Line 973: Line 1,084:
|if||conn.<em>renamefile</em>(filename, newfilename)||Rename a db file.
|if||conn.<em>renamefile</em>(filename, newfilename)||Rename a db file.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let conn = "exodus", filename = "xo_gendoc_temp", new_filename = "xo_gendoc_temp2";
let conn = "exodus", filename = "xo_gendoc_temp", new_filename = "xo_gendoc_temp2";
  if (conn.renamefile(filename, new_filename)) ... ok
  if (conn.renamefile(filename, new_filename)) ... ok
  // or
  // or
  if (renamefile(filename, new_filename)) ...</syntaxhighlight>
  if (renamefile(filename, new_filename)) ...</syntaxhighlight>
|-
|-
|var=||conn.<em>listfiles</em>()||<em>Returns:</em> A list of all files in a database
|var=||conn.<em>listfiles</em>()||Returns: A list of all files in a database
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "exodus";
var conn = "exodus";
  if (not conn.listfiles()) ...
  if (not conn.listfiles()) ...
  // or
  // or
Line 987: Line 1,098:
|if||conn.<em>clearfile</em>(filename)||Delete all records in a db file
|if||conn.<em>clearfile</em>(filename)||Delete all records in a db file
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let conn = "exodus", filename = "xo_gendoc_temp2";
let conn = "exodus", filename = "xo_gendoc_temp2";
  if (not conn.clearfile(filename)) ...
  if (not conn.clearfile(filename)) ...
  // or
  // or
Line 994: Line 1,105:
|if||conn.<em>deletefile</em>(filename)||Delete a db file
|if||conn.<em>deletefile</em>(filename)||Delete a db file
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let conn = "exodus", filename = "xo_gendoc_temp2";
let conn = "exodus", filename = "xo_gendoc_temp2";
  if (conn.deletefile(filename)) ... ok
  if (conn.deletefile(filename)) ... ok
  // or
  // or
  if (deletefile(filename)) ...</syntaxhighlight>
  if (deletefile(filename)) ...</syntaxhighlight>
|-
|-
|var=||conn_or_file.<em>reccount</em>(filename = "")||<em>Returns:</em> The approx. number of records in a db file
|var=||conn_or_file.<em>reccount</em>(filename = "")||Returns: The approx. number of records in a db file
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let conn = "exodus", filename = "xo_clients";
let conn = "exodus", filename = "xo_clients";
  var nrecs1 = conn.reccount(filename);
  var nrecs1 = conn.reccount(filename);
  // or
  // or
  var nrecs2 = reccount(filename);</syntaxhighlight>
  var nrecs2 = reccount(filename);</syntaxhighlight>
|-
|-
|if||conn_or_file.<em>flushindex</em>(filename = "")||Calls db maintenance function (vacuum)</p>
|if||conn_or_file.<em>flushindex</em>(filename = "")||Calls db maintenance function (vacuum)
 
This doesnt actually flush any indexes but does make sure that reccount() function is reasonably accurate.
This doesnt actually flush any indexes but does make sure that reccount() function is reasonably accurate.
|}
|}
Line 1,016: Line 1,128:
|if||file.<em>open</em>(dbfilename, connection = "")||Opens a db file to a var which can be used in subsequent functions to work on the specified file and database connection.
|if||file.<em>open</em>(dbfilename, connection = "")||Opens a db file to a var which can be used in subsequent functions to work on the specified file and database connection.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var file, filename = "definitions";
var file, filename = "definitions";
  if (not file.open(filename)) ...
  if (not file.open(filename)) ...
  // or
  // or
  if (not open(filename to file)) ...</syntaxhighlight>
  if (not open(filename to file)) ...</syntaxhighlight>
|-
|-
|cmd||file.<em>close</em>()||Closes db file var</p>
|cmd||file.<em>close</em>()||Closes db file var
 
Does nothing currently since database file vars consume no resources
Does nothing currently since database file vars consume no resources
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var file = "definitions";
var file = "definitions";
  file.close();
  file.close();
  // or
  // or
  close(file);</syntaxhighlight>
  close(file);</syntaxhighlight>
|-
|-
|if||file.<em>createindex</em>(fieldname, dictfile = "")||Creates a secondary index for a given db file and field name.</p>
|if||file.<em>createindex</em>(fieldname, dictfile = "")||Creates a secondary index for a given db file and field name.
The fieldname must exist in a dictionary file. The default dictionary is "dict." ^ filename.</p>
 
<em>Returns:</em> False if the index cannot be created for any reason.</p>
The fieldname must exist in a dictionary file. The default dictionary is "dict." ^ filename.
* Index already exists</p>
 
* File does not exist</p>
<em>Returns:</em> False if the index cannot be created for any reason.
* The dictionary file does not have a record with a key of the given field name.</p>
 
* The dictionary file does not exist. Default is "dict." ^ filename.</p>
* Index already exists
 
* File does not exist
 
* The dictionary file does not have a record with a key of the given field name.
 
* The dictionary file does not exist. Default is "dict." ^ filename.
 
* The dictionary field defines a calculated field that uses an exodus function. Using a psql function is OK.
* The dictionary field defines a calculated field that uses an exodus function. Using a psql function is OK.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var filename = "definitions", fieldname = "DATE_TIME";
var filename = "definitions", fieldname = "DATE_TIME";
  if (not deleteindex("definitions", "DATE_TIME")) {}; // Cleanup first
  if (not deleteindex("definitions", "DATE_TIME")) {}; // Cleanup first
  if (filename.createindex(fieldname)) ... ok
  if (filename.createindex(fieldname)) ... ok
Line 1,044: Line 1,164:
  if (createindex(filename, fieldname)) ...</syntaxhighlight>
  if (createindex(filename, fieldname)) ...</syntaxhighlight>
|-
|-
|var=||file|conn.<em>listindex</em>(file_or_filename = "", fieldname = "")||Lists secondary indexes in a database or for a db file</p>
|var=||file|conn.<em>listindex</em>(file_or_filename = "", fieldname = "")||Lists secondary indexes in a database or for a db file
 
<em>Returns:</em> False if the db file or fieldname are given and do not exist
<em>Returns:</em> False if the db file or fieldname are given and do not exist
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "exodus";
var conn = "exodus";
  if (conn.listindex()) ... ok // includes "xo_clients__date_time"
  if (conn.listindex()) ... ok // includes "xo_clients__date_time"
  // or
  // or
  if (listindex()) ... ok</syntaxhighlight>
  if (listindex()) ... ok</syntaxhighlight>
|-
|-
|if||file.<em>deleteindex</em>(fieldname)||Deletes a secondary index for a db file and field name.</p>
|if||file.<em>deleteindex</em>(fieldname)||Deletes a secondary index for a db file and field name.
<em>Returns:</em> False if the index cannot be deleted for any reason</p>
 
* File does not exist</p>
<em>Returns:</em> False if the index cannot be deleted for any reason
 
* File does not exist
 
* Index does not already exists
* Index does not already exists
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var file = "definitions", fieldname = "DATE_TIME";
var file = "definitions", fieldname = "DATE_TIME";
  if (file.deleteindex(fieldname)) ... ok
  if (file.deleteindex(fieldname)) ... ok
  // or
  // or
  if (deleteindex(file, fieldname)) ...</syntaxhighlight>
  if (deleteindex(file, fieldname)) ...</syntaxhighlight>
|-
|-
|var=||file.<em>lock</em>(key)||Places a metaphorical db lock on a particular record given a db file and key.</p>
|var=||file.<em>lock</em>(key)||Places a metaphorical db lock on a particular record given a db file and key.
This is a advisory lock, not a physical lock, since it makes no restriction on the access or modification of data by other connections.</p>
 
Neither the db file nor the record key need to actually exist since a lock is just a hash of the db file name and key combined.</p>
This is a advisory lock, not a physical lock, since it makes no restriction on the access or modification of data by other connections.
If another connection attempts to place an identical lock on the same database it will be denied.</p>
 
Locks can be removed by unlock() or unlockall() or will be automatically removed at the end of a transaction or when the connection is closed.</p>
Neither the db file nor the record key need to actually exist since a lock is just a hash of the db file name and key combined.
If the same process attempts to place an identical lock more than once it may be denied (if not in a transaction) or succeed but be ignored (if in a transaction).</p>
 
Locks can be used to avoid processing a transaction simultaneously with another connection only to have one of them fail due to mutually updating the same records.</p>
If another connection attempts to place an identical lock on the same database it will be denied.
<em>Returns:</em>:</p>
 
* 0: Failure: Another connection has already placed the same lock.</p>
Locks can be removed by unlock() or unlockall() or will be automatically removed at the end of a transaction or when the connection is closed.
* "" Failure: The lock has already been placed.</p>
 
* 1: Success: A new lock has been placed.</p>
If the same process attempts to place an identical lock more than once it may be denied (if not in a transaction) or succeed but be ignored (if in a transaction).
* 2: Success: The lock has already been placed and the connection is in a transaction.
 
<syntaxhighlight lang="c++">
Locks can be used to avoid processing a transaction simultaneously with another connection only to have one of them fail due to mutually updating the same records.
var file = "xo_clients", key = "1000";
 
  if (file.lock(key)) ... ok
Returns::
  // or
 
  if (lock(file, key)) ...</syntaxhighlight>
* 0: Failure: Another connection has already placed the same lock.
 
* "" Failure: The lock has already been placed.
 
* 1: Success: A new lock has been placed.
 
* 2: Success: The lock has already been placed and the connection is in a transaction.
<syntaxhighlight lang="c++">
var file = "xo_clients", key = "1000";
  if (file.lock(key)) ... ok
  // or
  if (lock(file, key)) ...</syntaxhighlight>
|-
|-
|if||file.<em>unlock</em>(key)||Removes a db lock placed by the lock function.</p>
|if||file.<em>unlock</em>(key)||Removes a db lock placed by the lock function.
Only locks placed on the specified connection can be removed.</p>
 
Locks cannot be removed while a connection is in a transaction.</p>
Only locks placed on the specified connection can be removed.
 
Locks cannot be removed while a connection is in a transaction.
 
<em>Returns:</em> False if the lock is not present in a connection.
<em>Returns:</em> False if the lock is not present in a connection.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var file = "xo_clients", key = "1000";
var file = "xo_clients", key = "1000";
  if (file.unlock(key)) ... ok
  if (file.unlock(key)) ... ok
  // or
  // or
  if (unlock(file, key)) ...</syntaxhighlight>
  if (unlock(file, key)) ...</syntaxhighlight>
|-
|-
|if||file.<em>unlockall</em>()||Removes all db locks placed by the lock function in the specified connection.</p>
|if||file.<em>unlockall</em>()||Removes all db locks placed by the lock function in the specified connection.
 
Locks cannot be removed while in a transaction.
Locks cannot be removed while in a transaction.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "exodus";
var conn = "exodus";
  if (not conn.unlockall()) ...
  if (not conn.unlockall()) ...
  // or
  // or
  if (not unlockall(conn)) ...</syntaxhighlight>
  if (not unlockall(conn)) ...</syntaxhighlight>
|-
|-
|cmd||rec.<em>write</em>(file, key)||Writes a record into a db file given a unique primary key.</p>
|cmd||rec.<em>write</em>(file, key)||Writes a record into a db file given a unique primary key.
Either inserts a new record or updates an existing record.</p>
 
It always succeeds so no result code is returned.</p>
Either inserts a new record or updates an existing record.
 
It always succeeds so no result code is returned.
 
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
  let file = "xo_clients", key = "GD001";
  let file = "xo_clients", key = "GD001";
  if (not deleterecord("xo_clients", "GD001")) {}; // Cleanup first
  if (not deleterecord("xo_clients", "GD001")) {}; // Cleanup first
Line 1,110: Line 1,252:
  write(rec on file, key);</syntaxhighlight>
  write(rec on file, key);</syntaxhighlight>
|-
|-
|if||rec.<em>read</em>(file, key)||Reads a record from a db file for a given key.</p>
|if||rec.<em>read</em>(file, key)||Reads a record from a db file for a given key.
 
<em>Returns:</em> False if the key doesnt exist
<em>Returns:</em> False if the key doesnt exist
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var rec;
var rec;
  let file = "xo_clients", key = "GD001";
  let file = "xo_clients", key = "GD001";
  if (not rec.read(file, key)) ... // rec -> "Client GD^G^20855^30000^1001.00^20855.76539"_var
  if (not rec.read(file, key)) ... // rec -> "Client GD^G^20855^30000^1001.00^20855.76539"_var
Line 1,119: Line 1,262:
  if (not read(rec from file, key)) ...</syntaxhighlight>
  if (not read(rec from file, key)) ...</syntaxhighlight>
|-
|-
|if||file.<em>deleterecord</em>(key)||Deletes a record from a db file given a key.</p>
|if||file.<em>deleterecord</em>(key)||Deletes a record from a db file given a key.
<em>Returns:</em> False if the key doesnt exist</p>
 
<em>Returns:</em> False if the key doesnt exist
 
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let file = "xo_clients", key = "GD001";
let file = "xo_clients", key = "GD001";
  if (file.deleterecord(key)) ... ok
  if (file.deleterecord(key)) ... ok
  // or
  // or
if (deleterecord(file, key)) ...</syntaxhighlight>
if (deleterecord(file, key)) ...</syntaxhighlight>
|-
|-
|if||rec.<em>insertrecord</em>(file, key)||Inserts a new record in a db file.</p>
|if||rec.<em>insertrecord</em>(file, key)||Inserts a new record in a db file.
<em>Returns:</em> False if the key already exists</p>
 
<em>Returns:</em> False if the key already exists
 
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
  let file = "xo_clients", key = "GD001";
  let file = "xo_clients", key = "GD001";
  if (rec.insertrecord(file, key)) ... ok
  if (rec.insertrecord(file, key)) ... ok
Line 1,138: Line 1,285:
  if (insertrecord(rec on file, key)) ...</syntaxhighlight>
  if (insertrecord(rec on file, key)) ...</syntaxhighlight>
|-
|-
|if||rec.<em>updaterecord</em>(file, key)||Updates an existing record in a db file.</p>
|if||rec.<em>updaterecord</em>(file, key)||Updates an existing record in a db file.
<em>Returns:</em> False if the key doesnt already exist</p>
 
<em>Returns:</em> False if the key doesnt already exist
 
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
  let file = "xo_clients", key = "GD001";
  let file = "xo_clients", key = "GD001";
  if (not rec.updaterecord(file, key)) ...
  if (not rec.updaterecord(file, key)) ...
Line 1,150: Line 1,299:
|if||rec.<em>readf</em>(file, key, fieldno)||"Read field" Same as read() but only returns a specific field from the record
|if||rec.<em>readf</em>(file, key, fieldno)||"Read field" Same as read() but only returns a specific field from the record
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var field, file = "xo_clients", key = "GD001", fieldno = 2;
var field, file = "xo_clients", key = "GD001", fieldno = 2;
  if (not field.readf(file, key, fieldno)) ... // field -> "G"
  if (not field.readf(file, key, fieldno)) ... // field -> "G"
  // or
  // or
Line 1,157: Line 1,306:
|cmd||rec.<em>writef</em>(file, key, fieldno)||"write field" Same as write() but only writes to a specific field in the record
|cmd||rec.<em>writef</em>(file, key, fieldno)||"write field" Same as write() but only writes to a specific field in the record
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var field = "f3", file = "definitions", key = "1000", fieldno = 3;
var field = "f3", file = "definitions", key = "1000", fieldno = 3;
  field.writef(file, key, fieldno);
  field.writef(file, key, fieldno);
  // or
  // or
  writef(field on file, key, fieldno);</syntaxhighlight>
  writef(field on file, key, fieldno);</syntaxhighlight>
|-
|-
|cmd||rec.<em>writec</em>(file, key)||"Write cache" Writes a record and key into a memory cached "db file".</p>
|cmd||rec.<em>writec</em>(file, key)||"Write cache" Writes a record and key into a memory cached "db file".
The actual database file is NOT updated.</p>
 
writec() either updates an existing cache record if the key already exists or otherwise inserts a new record into the cache.</p>
The actual database file is NOT updated.
It always succeeds so no result code is returned.</p>
 
writec() either updates an existing cache record if the key already exists or otherwise inserts a new record into the cache.
 
It always succeeds so no result code is returned.
 
Neither the db file nor the record key need to actually exist in the actual db.
Neither the db file nor the record key need to actually exist in the actual db.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let rec = "Client XD^X^20855^30000^1001.00^20855.76539"_var;
let rec = "Client XD^X^20855^30000^1001.00^20855.76539"_var;
  let file = "xo_clients", key = "XD001";
  let file = "xo_clients", key = "XD001";
  rec.writec(file, key);
  rec.writec(file, key);
Line 1,174: Line 1,327:
  writec(rec on file, key);</syntaxhighlight>
  writec(rec on file, key);</syntaxhighlight>
|-
|-
|if||rec.<em>readc</em>(file, key)||"Read cache" Same as "read() but first reads from a memory cache.</p>
|if||rec.<em>readc</em>(file, key)||"Read cache" Same as "read() but first reads from a memory cache.
1. Tries to read from a memory cache. Returns true if successful.</p>
 
2a. Tries to read from the actual db file and returns false if unsuccessful.</p>
1. Tries to read from a memory cache. Returns true if successful.
2b. Writes the record and key to the memory cache and returns true.</p>
 
2a. Tries to read from the actual db file and returns false if unsuccessful.
 
2b. Writes the record and key to the memory cache and returns true.
 
Cached db file data lives in exodus process memory and is lost when the process terminates or cleardbcache() is called.
Cached db file data lives in exodus process memory and is lost when the process terminates or cleardbcache() is called.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var rec;
var rec;
  let file = "xo_clients", key = "XD001";
  let file = "xo_clients", key = "XD001";
  if (rec.readc(file, key)) ... ok
  if (rec.readc(file, key)) ... ok
Line 1,189: Line 1,346:
  if (read(rec from file, key)) abort("Error: " ^ key ^ " should not be in the actual database file"); // error</syntaxhighlight>
  if (read(rec from file, key)) abort("Error: " ^ key ^ " should not be in the actual database file"); // error</syntaxhighlight>
|-
|-
|if||dbfile.<em>deletec</em>(key)||Deletes a record and key from a memory cached "file".</p>
|if||dbfile.<em>deletec</em>(key)||Deletes a record and key from a memory cached "file".
The actual database file is NOT updated.</p>
 
The actual database file is NOT updated.
 
<em>Returns:</em> False if the key doesnt exist
<em>Returns:</em> False if the key doesnt exist
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var file = "xo_clients", key = "XD001";
var file = "xo_clients", key = "XD001";
  if (file.deletec(key)) ... ok
  if (file.deletec(key)) ... ok
  // or
  // or
  if (deletec(file, key)) ...</syntaxhighlight>
  if (deletec(file, key)) ...</syntaxhighlight>
|-
|-
|cmd||conn.<em>cleardbcache</em>()||Clears the memory cache of all records for the given connection</p>
|cmd||conn.<em>cleardbcache</em>()||Clears the memory cache of all records for the given connection
 
All future cache readc() function calls will be forced to obtain records from the actual database and refresh the cache.
All future cache readc() function calls will be forced to obtain records from the actual database and refresh the cache.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
conn.cleardbcache();
conn.cleardbcache();
  // or
  // or
cleardbcache(conn);</syntaxhighlight>
cleardbcache(conn);</syntaxhighlight>
|-
|-
|var=||conn.<em>xlate</em>(filename, fieldno, mode)||The xlate ("translate") function is similar to readf() but, when called as an exodus program member function, it can be used efficiently with exodus file dictionaries using column names and functions and multivalued data.</p>
|var=||conn.<em>xlate</em>(filename, fieldno, mode)||The xlate ("translate") function is similar to readf() but, when called as an exodus program member function, it can be used efficiently with exodus file dictionaries using column names and functions and multivalued data.
Arguments:</p>
 
strvar: Used as the primary key to lookup a field in a given file and field no or field name.</p>
<em>Arguments:</em>
filename: The db file in which to look up data.</p>
 
If var key is multivalued then a multivalued field is returned.</p>
<em>strvar:</em> Used as the primary key to lookup a field in a given file and field no or field name.
fieldno: Determines which field of the record is returned.</p>
 
* Integer returns that field number</p>
<em>filename:</em> The db file in which to look up data.
* 0 means return the key unchanged.</p>
 
* "" means return the whole record.</p>
If var key is multivalued then a multivalued field is returned.
mode: Determines what is returned if the record does not exist for the given key and file.</p>
 
* "X" returns ""</p>
<em>fieldno:</em> Determines which field of the record is returned.
 
* Integer returns that field number
 
* 0 means return the key unchanged.
 
* "" means return the whole record.
 
<em>mode:</em> Determines what is returned if the record does not exist for the given key and file.
 
* "X" returns ""
 
* "C" returns the key unconverted.
* "C" returns the key unconverted.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let key = "SB001";
let key = "SB001";
  let client_name = key.xlate("xo_clients", 1, "X"); // "Client AAA"
  let client_name = key.xlate("xo_clients", 1, "X"); // "Client AAA"
  // or
  // or
Line 1,228: Line 1,399:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|if||dbfile.<em>select</em>(sort_select_command = "")||Create an active select list of keys of a database file.</p>
|if||dbfile.<em>select</em>(sort_select_command = "")||Create an active select list of keys of a database file.
The select(command) function searches and orders database records for subsequent processing given an English language-like command.</p>
 
The primary job of a database, beyond mere storage and retrieval of information, is to allow rapid searching and ordering of information on demand.</p>
The select(command) function searches and orders database records for subsequent processing given an English language-like command.
In Exodus, searching and ordering of information is known as "sort/select" and is performed by the select() function.</p>
 
Executing the select() function creates an "active select list" which can then be consumed by the readnext() function.</p>
The primary job of a database, beyond mere storage and retrieval of information, is to allow rapid searching and ordering of information on demand.
dbfile: A opened database file or file name, or an open connection or an empty var for default connections. Subsequent readnext calls must use the same.</p>
 
sort_select_command: A natural language command using dictionary field names. The command can be blank if a dbfile or filename is given in dbfile or just a file name and all keys will be selected in undefined order.</p>
In Exodus, searching and ordering of information is known as "sort/select" and is performed by the select() function.
Example: "select xo_clients with type 'B' and with balance ge 100 by type by name"</p>
 
Option: "(R)" appended to the sort_select_command acquires the database records as well.</p>
Executing the select() function creates an "active select list" which can then be consumed by the readnext() function.
<em>Returns:</em> True if any records are selected or false if none.</p>
 
Throws: VarDBException in case of any syntax error in the command.</p>
<em>dbfile:</em> A opened database file or file name, or an open connection or an empty var for default connections. Subsequent readnext calls must use the same.
Active select lists created using var.select()'s member function syntax cannot be consumed by the free function form of readnext() and vice versa.
 
<syntaxhighlight lang="c++">
<em>sort_select_command:</em> A natural language command using dictionary field names. The command can be blank if a dbfile or filename is given in dbfile or just a file name and all keys will be selected in undefined order.
var clients = "xo_clients";
 
  if (clients.select("with type 'B' and with balance ge 100 by type by name"))
<em>Example:</em> "select xo_clients with type 'B' and with balance ge 100 by type by name"
 
<em>Option:</em> "(R)" appended to the sort_select_command acquires the database records as well.
 
<em>Returns:</em> True if any records are selected or false if none.
 
<em>Throws:</em> VarDBException in case of any syntax error in the command.
 
Active select lists created using var.select()'s member function syntax cannot be consumed by the free function form of readnext() and vice versa.
<syntaxhighlight lang="c++">
var clients = "xo_clients";
  if (clients.select("with type 'B' and with balance ge 100 by type by name"))
     while (clients.readnext(ID))
     while (clients.readnext(ID))
         println("Client code is {}", ID);
         println("Client code is {}", ID);
Line 1,250: Line 1,432:
         println("Client code is {}", ID);</syntaxhighlight>
         println("Client code is {}", ID);</syntaxhighlight>
|-
|-
|if||dbfile.<em>selectkeys</em>(keys)||Create an active select list from a string of keys.</p>
|if||dbfile.<em>selectkeys</em>(keys)||Create an active select list from a string of keys.
Similar to select() but creates the list directly from a var.</p>
 
keys: An FM separated list of keys or key^VM^valueno pairs.</p>
Similar to select() but creates the list directly from a var.
 
<em>keys:</em> An FM separated list of keys or key^VM^valueno pairs.
 
<em>Returns:</em> True if any keys are provided or false if not.
<em>Returns:</em> True if any keys are provided or false if not.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var dbfile = "";
var dbfile = "";
  let keys = "A01^B02^C03"_var;
  let keys = "A01^B02^C03"_var;
  if (dbfile.selectkeys(keys)) ... ok
  if (dbfile.selectkeys(keys)) ... ok
Line 1,263: Line 1,448:
  assert(readnext(ID) and ID == "A01");</syntaxhighlight>
  assert(readnext(ID) and ID == "A01");</syntaxhighlight>
|-
|-
|if||dbfile.<em>hasnext</em>()||Checks if a select list is active.</p>
|if||dbfile.<em>hasnext</em>()||Checks if a select list is active.
dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.</p>
 
<em>Returns:</em> True if a select list is active and false if not.</p>
<em>dbfile:</em> A file or connection var used in a prior select, selectkeys or getlist function call.
 
<em>Returns:</em> True if a select list is active and false if not.
 
If it returns true then a call to readnext() will return a database record key, otherwise not.
If it returns true then a call to readnext() will return a database record key, otherwise not.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var clients = "xo_clients", key;
var clients = "xo_clients", key;
  if (clients.select()) {
  if (clients.select()) {
     assert(clients.hasnext());
     assert(clients.hasnext());
Line 1,277: Line 1,465:
  }</syntaxhighlight>
  }</syntaxhighlight>
|-
|-
|if||dbfile.<em>readnext</em>(out key)||Acquires and consumes one key from an active select list of database record keys.</p>
|if||dbfile.<em>readnext</em>(out key)||Acquires and consumes one key from an active select list of database record keys.
dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.</p>
 
key: Returns the first (next) key present in an active select list or "" if no select list is active.</p>
<em>dbfile:</em> A file or connection var used in a prior select, selectkeys or getlist function call.
<em>Returns:</em> True if a list is active and a key is available, false if not.</p>
 
Each call to readnext consumes one key from the list.</p>
<em>key:</em> Returns the first (next) key present in an active select list or "" if no select list is active.
Once all the keys in an active select list have been consumed by calls to readnext, the list becomes inactive.</p>
 
<em>Returns:</em> True if a list is active and a key is available, false if not.
 
Each call to readnext consumes one key from the list.
 
Once all the keys in an active select list have been consumed by calls to readnext, the list becomes inactive.
 
See select() for example code.
See select() for example code.
|-
|-
|if||dbfile.<em>readnext</em>(out key, out valueno)||Similar to readnext(key) but multivalued.</p>
|if||dbfile.<em>readnext</em>(out key, out valueno)||Similar to readnext(key) but multivalued.
 
If the active list was ordered by multivalued database fields then pairs of key and multivalue number will be available to the readnext function.
If the active list was ordered by multivalued database fields then pairs of key and multivalue number will be available to the readnext function.
|-
|-
|if||dbfile.<em>readnext</em>(out record, out key, out valueno)||Similar to readnext(key) but acquires the database record as well.</p>
|if||dbfile.<em>readnext</em>(out record, out key, out valueno)||Similar to readnext(key) but acquires the database record as well.
record: Returns the next database record from the select list assuming that the select list was created with the (R) option otherwise "" if not.</p>
 
key: Returns the next database record key in the select list.</p>
<em>record:</em> Returns the next database record from the select list assuming that the select list was created with the (R) option otherwise "" if not.
valueno: The multivalue number if the select list was ordered on multivalued database record fields or 1 if not.
 
<em>key:</em> Returns the next database record key in the select list.
 
<em>valueno:</em> The multivalue number if the select list was ordered on multivalued database record fields or 1 if not.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var clients = "xo_clients";
var clients = "xo_clients";
  if (clients.select("with type 'B' and with balance ge 100 by type by name (R)"))
  if (clients.select("with type 'B' and with balance ge 100 by type by name (R)"))
     while (clients.readnext(RECORD, ID, MV))
     while (clients.readnext(RECORD, ID, MV))
Line 1,303: Line 1,501:
         println("Code is {}, Name is {}", calculate("CODE"), calculate("NAME"));</syntaxhighlight>
         println("Code is {}, Name is {}", calculate("CODE"), calculate("NAME"));</syntaxhighlight>
|-
|-
|cmd||dbfile.<em>clearselect</em>()||Deactivates an active select list.</p>
|cmd||dbfile.<em>clearselect</em>()||Deactivates an active select list.
dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.</p>
 
<em>Returns:</em> Nothing</p>
<em>dbfile:</em> A file or connection var used in a prior select, selectkeys or getlist function call.
Has no effect if no select list is active for dbfile.
 
<em>Returns:</em> Nothing
 
Has no effect if no select list is active for dbfile.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var clients = "xo_clients";
var clients = "xo_clients";
  clients.clearselect();
  clients.clearselect();
  if (not clients.hasnext()) ... ok
  if (not clients.hasnext()) ... ok
Line 1,315: Line 1,516:
  if (not hasnext()) ... ok</syntaxhighlight>
  if (not hasnext()) ... ok</syntaxhighlight>
|-
|-
|if||dbfile.<em>savelist</em>(listname)||Stores an active select list for later retrieval.</p>
|if||dbfile.<em>savelist</em>(listname)||Stores an active select list for later retrieval.
dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.</p>
 
listname: A suitable name that will be required for later retrieval.</p>
<em>dbfile:</em> A file or connection var used in a prior select, selectkeys or getlist function call.
<em>Returns:</em> True if saved successfully or false if there was no active list to be saved.</p>
 
Any existing list with the same name will be overwritten.</p>
<em>listname:</em> A suitable name that will be required for later retrieval.
Only the remaining unconsumed part of the active select list is saved.</p>
 
Saved lists are stand-alone and are not tied to specific database files although they usually hold keys related to specific files.</p>
<em>Returns:</em> True if saved successfully or false if there was no active list to be saved.
Saved lists can be created from one file and used to access another.</p>
 
savelist() merely writes an FM separated string of keys as a record in the "lists" database file using the list name as the key of the record.</p>
Any existing list with the same name will be overwritten.
If a saved list is very long, additional blocks of keys for the same list may be stored with keys like listname*2, listname*3 etc.</p>
 
Only the remaining unconsumed part of the active select list is saved.
 
Saved lists are stand-alone and are not tied to specific database files although they usually hold keys related to specific files.
 
Saved lists can be created from one file and used to access another.
 
savelist() merely writes an FM separated string of keys as a record in the "lists" database file using the list name as the key of the record.
 
If a saved list is very long, additional blocks of keys for the same list may be stored with keys like listname*2, listname*3 etc.
 
Select lists saved in the lists database file may be created, deleted and listed like database records in any other database file.
Select lists saved in the lists database file may be created, deleted and listed like database records in any other database file.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var clients = "xo_clients";
var clients = "xo_clients";
  if (clients.select("with type 'B' by name")) {
  if (clients.select("with type 'B' by name")) {
  }
  }
Line 1,335: Line 1,546:
  }</syntaxhighlight>
  }</syntaxhighlight>
|-
|-
|if||dbfile.<em>getlist</em>(listname)||Retrieve and reactivate a saved select list.</p>
|if||dbfile.<em>getlist</em>(listname)||Retrieve and reactivate a saved select list.
dbfile: A file or connection var to be used by subsequent readnext function calls.</p>
 
listname: The name of an existing list in the "lists" database file, either created by savelist or manually.</p>
<em>dbfile:</em> A file or connection var to be used by subsequent readnext function calls.
<em>Returns:</em> True if the list was successfully retrieved and activated, or false if the list name doesnt exist.</p>
 
Any currently active select list is replaced.</p>
<em>listname:</em> The name of an existing list in the "lists" database file, either created by savelist or manually.
 
<em>Returns:</em> True if the list was successfully retrieved and activated, or false if the list name doesnt exist.
 
Any currently active select list is replaced.
 
Retrieving a list does not delete it and a list can be retrieved more than once until specifically deleted.
Retrieving a list does not delete it and a list can be retrieved more than once until specifically deleted.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var file = "";
var file = "";
  if (file.getlist("mylist")) {
  if (file.getlist("mylist")) {
     while (file.readnext(ID))
     while (file.readnext(ID))
Line 1,353: Line 1,569:
  }</syntaxhighlight>
  }</syntaxhighlight>
|-
|-
|if||dbfile.<em>deletelist</em>(listname)||Delete a saved select list.</p>
|if||dbfile.<em>deletelist</em>(listname)||Delete a saved select list.
dbfile: A file or connection to the desired database.</p>
 
listname: The name of an existing list in the "lists" database file.</p>
<em>dbfile:</em> A file or connection to the desired database.
 
<em>listname:</em> The name of an existing list in the "lists" database file.
 
<em>Returns:</em> True if successful or false if the list name doesnt exist.
<em>Returns:</em> True if successful or false if the list name doesnt exist.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var conn = "";
var conn = "";
  if (conn.deletelist("mylist")) ... ok
  if (conn.deletelist("mylist")) ... ok
  // or
  // or
Line 1,368: Line 1,587:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||var().<em>date</em>()||Number of whole days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.</p>
|var=||var().<em>date</em>()||Number of whole days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.
 
e.g. was 20821 from 2025-01-01 00:00:00 UTC for 24 hours
e.g. was 20821 from 2025-01-01 00:00:00 UTC for 24 hours
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let today1 = var().date();
let today1 = var().date();
  // or
  // or
  let today2 = date();</syntaxhighlight>
  let today2 = date();</syntaxhighlight>
|-
|-
|var=||var().<em>time</em>()||Number of whole seconds since last 00:00:00 (UTC).</p>
|var=||var().<em>time</em>()||Number of whole seconds since last 00:00:00 (UTC).
e.g. 43200 if time is 12:00</p>
 
e.g. 43200 if time is 12:00
 
Range 0 - 86399 since there are 24*60*60 (86400) seconds in a day.
Range 0 - 86399 since there are 24*60*60 (86400) seconds in a day.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let now1 = var().time();
let now1 = var().time();
  // or
  // or
  let now2 = time();</syntaxhighlight>
  let now2 = time();</syntaxhighlight>
|-
|-
|var=||var().<em>ostime</em>()||Number of fractional seconds since last 00:00:00 (UTC).</p>
|var=||var().<em>ostime</em>()||Number of fractional seconds since last 00:00:00 (UTC).
A floating point with approx. nanosecond resolution depending on hardware.</p>
 
A floating point with approx. nanosecond resolution depending on hardware.
 
e.g. 23343.704387955 approx. 06:29:03 UTC
e.g. 23343.704387955 approx. 06:29:03 UTC
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let now1 = var().ostime();
let now1 = var().ostime();
  // or
  // or
  let now2 = ostime();</syntaxhighlight>
  let now2 = ostime();</syntaxhighlight>
|-
|-
|var=||var().<em>timestamp</em>()||Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.</p>
|var=||var().<em>timestamp</em>()||Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.
A floating point with approx. nanosecond resolution depending on hardware.</p>
 
A floating point with approx. nanosecond resolution depending on hardware.
 
e.g. Was 20821.99998842593 around 2025-01-01 23:59:59 UTC
e.g. Was 20821.99998842593 around 2025-01-01 23:59:59 UTC
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let now1 = var().timestamp();
let now1 = var().timestamp();
  // or
  // or
  let now2 = timestamp();</syntaxhighlight>
  let now2 = timestamp();</syntaxhighlight>
Line 1,401: Line 1,627:
|var=||var().<em>timestamp</em>(ostime)||Construct a timestamp from a date and time
|var=||var().<em>timestamp</em>(ostime)||Construct a timestamp from a date and time
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let idate = iconv("2025-01-01", "D"), itime = iconv("23:59:59", "MT");
let idate = iconv("2025-01-01", "D"), itime = iconv("23:59:59", "MT");
  let ts1 = idate.timestamp(itime); // 20821.99998842593
  let ts1 = idate.timestamp(itime); // 20821.99998842593
  // or
  // or
  let ts2 = timestamp(idate, itime);</syntaxhighlight>
  let ts2 = timestamp(idate, itime);</syntaxhighlight>
|-
|-
|cmd||var().<em>ossleep</em>(milliseconds)||Sleep/pause/wait for a number of milliseconds</p>
|cmd||var().<em>ossleep</em>(milliseconds)||Sleep/pause/wait for a number of milliseconds
 
Releases the processor if not needed for a period of time or a delay is required.
Releases the processor if not needed for a period of time or a delay is required.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var().ossleep(100); // sleep for 100ms
var().ossleep(100); // sleep for 100ms
  // or
  // or
  ossleep(100);</syntaxhighlight>
  ossleep(100);</syntaxhighlight>
|-
|-
|var=||file_dir_list.<em>oswait</em>(milliseconds)||Sleep/pause/wait up to a given number of milliseconds or until any changes occur in an FM delimited list of directories and/or files.</p>
|var=||file_dir_list.<em>oswait</em>(milliseconds)||Sleep/pause/wait up to a given number of milliseconds or until any changes occur in an FM delimited list of directories and/or files.
Any terminal input (e.g. a key press) will also terminate the wait.</p>
 
An FM array of event information is returned. See below.</p>
Any terminal input (e.g. a key press) will also terminate the wait.
 
An FM array of event information is returned. See below.
 
Multiple events are returned in multivalues.
Multiple events are returned in multivalues.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = ".^/etc/hosts"_var.oswait(100); /// e.g. "IN_CLOSE_WRITE^/etc^hosts^f"_var
let v1 = ".^/etc/hosts"_var.oswait(100); /// e.g. "IN_CLOSE_WRITE^/etc^hosts^f"_var
  // or
  // or
  let v2 = oswait(".^/etc/hosts"_var, 100);</syntaxhighlight>
  let v2 = oswait(".^/etc/hosts"_var, 100);</syntaxhighlight>
Returned array fields</p>
Returned array fields
1. Event type codes</p>
 
2. dirpaths</p>
1. Event type codes
3. filenames</p>
 
4. d=dir, f=file</p>
2. dirpaths
</p>
 
Possible event type codes are as follows:</p>
3. filenames
* IN_CLOSE_WRITE - A file opened for writing was closed</p>
 
* IN_ACCESS      - Data was read from file</p>
4. d=dir, f=file
* IN_MODIFY      - Data was written to file</p>
 
* IN_ATTRIB      - File attributes changed</p>
</pre>
* IN_CLOSE      - File was closed (read or write)</p>
 
* IN_MOVED_FROM  - File was moved away from watched directory</p>
Possible event type codes are as follows:
* IN_MOVED_TO    - File was moved into watched directory</p>
 
* IN_MOVE        - File was moved (in or out of directory)</p>
* IN_CLOSE_WRITE - A file opened for writing was closed
* IN_CREATE      - A file was created in the directory</p>
 
* IN_DELETE      - A file was deleted from the directory</p>
* IN_ACCESS      - Data was read from file
* IN_DELETE_SELF - Directory or file under observation was deleted</p>
 
* IN_MODIFY      - Data was written to file
 
* IN_ATTRIB      - File attributes changed
 
* IN_CLOSE      - File was closed (read or write)
 
* IN_MOVED_FROM  - File was moved away from watched directory
 
* IN_MOVED_TO    - File was moved into watched directory
 
* IN_MOVE        - File was moved (in or out of directory)
 
* IN_CREATE      - A file was created in the directory
 
* IN_DELETE      - A file was deleted from the directory
 
* IN_DELETE_SELF - Directory or file under observation was deleted
 
* IN_MOVE_SELF  - Directory or file under observation was moved
* IN_MOVE_SELF  - Directory or file under observation was moved
</pre>
|}
|}
===== OS File I/O =====
===== OS File I/O =====
Line 1,446: Line 1,696:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|if||osfilevar.<em>osopen</em>(osfilename, utf8 = true)||Given the name of an existing os file name including path, initialises an os file handle var that can be used in random access osbread and osbwrite functions.</p>
|if||osfilevar.<em>osopen</em>(osfilename, utf8 = true)||Given the name of an existing os file name including path, initialises an os file handle var that can be used in random access osbread and osbwrite functions.
The utf8 option defaults to true which causes trimming of partial utf-8 unicode byte sequences from the end of osbreads. For raw untrimmed osbreads pass utf8 = false;</p>
 
File will be opened for writing if possible otherwise for reading.</p>
The utf8 option defaults to true which causes trimming of partial utf-8 unicode byte sequences from the end of osbreads. For raw untrimmed osbreads pass utf8 = false;
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
 
File will be opened for writing if possible otherwise for reading.
 
<em>Returns:</em> True if successful or false if not possible for any reason.
 
e.g. Target doesnt exist, permissions etc.
e.g. Target doesnt exist, permissions etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  if (oswrite("" on osfilename)) ... ok /// Create an empty os file
  if (oswrite("" on osfilename)) ... ok /// Create an empty os file
  var ostempfile;
  var ostempfile;
Line 1,459: Line 1,713:
  if (osopen(osfilename to ostempfile)) ... ok</syntaxhighlight>
  if (osopen(osfilename to ostempfile)) ... ok</syntaxhighlight>
|-
|-
|if||osfilevar.<em>osbwrite</em>(osfilevar, io offset)||Writes data to an existing os file starting at a given byte offset (0 based).</p>
|if||osfilevar.<em>osbwrite</em>(osfilevar, io offset)||Writes data to an existing os file starting at a given byte offset (0 based).
 
See osbread for more info.
See osbread for more info.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  let text = "aaa=123\nbbb=456\n";
  let text = "aaa=123\nbbb=456\n";
  var offset = osfile(osfilename).f(1); /// Size of file therefore append
  var offset = osfile(osfilename).f(1); /// Size of file therefore append
Line 1,469: Line 1,724:
  if (not osbwrite(text on osfilename, offset)) ...</syntaxhighlight>
  if (not osbwrite(text on osfilename, offset)) ...</syntaxhighlight>
|-
|-
|if||osfilevar.<em>osbread</em>(osfilevar, io offset, length)||Reads length bytes from an existing os file starting at a given byte offset (0 based).</p>
|if||osfilevar.<em>osbread</em>(osfilevar, io offset, length)||Reads length bytes from an existing os file starting at a given byte offset (0 based).
The osfilevar file handle may either be initialised by osopen or be just be a normal string variable holding the path and name of the os file.</p>
 
After reading, the offset is updated to point to the correct offset for a subsequent sequential read.</p>
The osfilevar file handle may either be initialised by osopen or be just be a normal string variable holding the path and name of the os file.
 
After reading, the offset is updated to point to the correct offset for a subsequent sequential read.
 
If reading utf8 data (the default) then the length of data actually returned may be a few bytes shorter than requested in order to be a complete number of UTF-8 code points.
If reading utf8 data (the default) then the length of data actually returned may be a few bytes shorter than requested in order to be a complete number of UTF-8 code points.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  var text, offset = 0;
  var text, offset = 0;
  if (text.osbread(osfilename, offset, 8)) ... ok // text -> "aaa=123\n" // offset -> 8
  if (text.osbread(osfilename, offset, 8)) ... ok // text -> "aaa=123\n" // offset -> 8
Line 1,480: Line 1,738:
  if (osbread(text from osfilename, offset, 8)) ... ok // text -> "bbb=456\n" // offset -> 16</syntaxhighlight>
  if (osbread(text from osfilename, offset, 8)) ... ok // text -> "bbb=456\n" // offset -> 16</syntaxhighlight>
|-
|-
|cmd||osfilevar.<em>osclose</em>()||Removes an osfilevar handle from the internal memory cache of os file handles. This frees up both exodus process memory and operating system resources.</p>
|cmd||osfilevar.<em>osclose</em>()||Removes an osfilevar handle from the internal memory cache of os file handles. This frees up both exodus process memory and operating system resources.
 
It is advisable to osclose any file handles after use, regardless of whether they were specifically opened using osopen or not, especially in long running programs. Exodus performs caching of internal os file handles per thread and os file. If not closed, then the operating system will probably not flush deleted files from storage until the process is terminated. This can potentially create an memory issue or file system resource issue especially if osopening/osreading/oswriting many perhaps temporary files in a long running process.
It is advisable to osclose any file handles after use, regardless of whether they were specifically opened using osopen or not, especially in long running programs. Exodus performs caching of internal os file handles per thread and os file. If not closed, then the operating system will probably not flush deleted files from storage until the process is terminated. This can potentially create an memory issue or file system resource issue especially if osopening/osreading/oswriting many perhaps temporary files in a long running process.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
osfilevar.osclose();
osfilevar.osclose();
  // or
  // or
  osclose(osfilevar);</syntaxhighlight>
  osclose(osfilevar);</syntaxhighlight>
|-
|-
|if||osfilevar.<em>oswrite</em>(osfilename, codepage = "")||Create a complete os file from a var.</p>
|if||osfilevar.<em>oswrite</em>(osfilename, codepage = "")||Create a complete os file from a var.
Any existing os file is removed first.</p>
 
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
Any existing os file is removed first.
e.g. Path is not writeable, permissions etc.</p>
 
<em>Returns:</em> True if successful or false if not possible for any reason.
 
e.g. Path is not writeable, permissions etc.
 
If codepage is specified then output is converted from utf-8 to that codepage. Otherwise no conversion is done.
If codepage is specified then output is converted from utf-8 to that codepage. Otherwise no conversion is done.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let text = "aaa = 123\nbbb = 456";
let text = "aaa = 123\nbbb = 456";
  let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  if (text.oswrite(osfilename)) ... ok
  if (text.oswrite(osfilename)) ... ok
Line 1,499: Line 1,762:
  if (oswrite(text on osfilename)) ... ok</syntaxhighlight>
  if (oswrite(text on osfilename)) ... ok</syntaxhighlight>
|-
|-
|if||osfilevar.<em>osread</em>(osfilename, codepage = "")||Read a complete os file into a var.</p>
|if||osfilevar.<em>osread</em>(osfilename, codepage = "")||Read a complete os file into a var.
If codepage is specified then input is converted from that codepage to utf-8 otherwise no conversion is done.</p>
 
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
If codepage is specified then input is converted from that codepage to utf-8 otherwise no conversion is done.
 
<em>Returns:</em> True if successful or false if not possible for any reason.
 
e.g. File doesnt exist, permissions etc.
e.g. File doesnt exist, permissions etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var text;
var text;
  let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  if (text.osread(osfilename)) ... ok // text -> "aaa = 123\nbbb = 456"
  if (text.osread(osfilename)) ... ok // text -> "aaa = 123\nbbb = 456"
Line 1,510: Line 1,776:
  if (osread(text from osfilename)) ... ok</syntaxhighlight>
  if (osread(text from osfilename)) ... ok</syntaxhighlight>
|-
|-
|if||osfile_or_dirname.<em>osrename</em>(new_dirpath_or_filepath)||Renames an os file or dir in the OS file system.</p>
|if||osfile_or_dirname.<em>osrename</em>(new_dirpath_or_filepath)||Renames an os file or dir in the OS file system.
Will not overwrite an existing os file or dir.</p>
 
Source and target must exist in the same storage device.</p>
Will not overwrite an existing os file or dir.
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
 
e.g. Target already exists, path is not writeable, permissions etc.</p>
Source and target must exist in the same storage device.
 
<em>Returns:</em> True if successful or false if not possible for any reason.
 
e.g. Target already exists, path is not writeable, permissions etc.
 
Uses std::filesystem::rename internally.
Uses std::filesystem::rename internally.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  let to_osfilename = from_osfilename ^ ".bak";
  let to_osfilename = from_osfilename ^ ".bak";
  if (not osremove(ostempdirpath() ^ "xo_gendoc_test.conf.bak")) {}; // Cleanup first
  if (not osremove(ostempdirpath() ^ "xo_gendoc_test.conf.bak")) {}; // Cleanup first
Line 1,525: Line 1,796:
  if (osrename(from_osfilename, to_osfilename)) ...</syntaxhighlight>
  if (osrename(from_osfilename, to_osfilename)) ...</syntaxhighlight>
|-
|-
|if||osfile_or_dirname.<em>osmove</em>(to_osfilename)||"Moves" an os file or dir within the os file system.</p>
|if||osfile_or_dirname.<em>osmove</em>(to_osfilename)||"Moves" an os file or dir within the os file system.
Will not overwrite an existing os file or dir.</p>
 
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
Will not overwrite an existing os file or dir.
e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions etc.</p>
 
<em>Returns:</em> True if successful or false if not possible for any reason.
 
e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions etc.
 
Attempts osrename first then oscopy followed by osremove original.
Attempts osrename first then oscopy followed by osremove original.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf.bak";
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf.bak";
  let to_osfilename = from_osfilename.cut(-4);
  let to_osfilename = from_osfilename.cut(-4);


Line 1,539: Line 1,814:
  if (osmove(from_osfilename, to_osfilename)) ...</syntaxhighlight>
  if (osmove(from_osfilename, to_osfilename)) ...</syntaxhighlight>
|-
|-
|if||osfile_or_dirname.<em>oscopy</em>(to_osfilename)||Copies an os file or directory recursively within the os file system.</p>
|if||osfile_or_dirname.<em>oscopy</em>(to_osfilename)||Copies an os file or directory recursively within the os file system.
Will overwrite an existing os file or dir.</p>
 
Will overwrite an existing os file or dir.
 
Uses std::filesystem::copy internally with recursive and overwrite options
Uses std::filesystem::copy internally with recursive and overwrite options
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  let to_osfilename = from_osfilename ^ ".bak";
  let to_osfilename = from_osfilename ^ ".bak";


Line 1,550: Line 1,827:
  if (oscopy(from_osfilename, to_osfilename)) ... ok</syntaxhighlight>
  if (oscopy(from_osfilename, to_osfilename)) ... ok</syntaxhighlight>
|-
|-
|if||osfilename.<em>osremove</em>()||Removes/deletes an os file from the OS file system given path and name.</p>
|if||osfilename.<em>osremove</em>()||Removes/deletes an os file from the OS file system given path and name.
Will not remove directories. Use osrmdir() to remove directories</p>
 
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
Will not remove directories. Use osrmdir() to remove directories
e.g. Target doesnt exist, path is not writeable, permissions etc.
 
<em>Returns:</em> True if successful or false if not possible for any reason.
 
e.g. Target doesnt exist, path is not writeable, permissions etc.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
  if (osfilename.osremove()) ... ok
  if (osfilename.osremove()) ... ok
  // or
  // or
Line 1,565: Line 1,845:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||dirpath.<em>oslist</em>(globpattern = "", mode = 0)||<em>Returns:</em> A FM delimited string containing all matching dir entries given a dir path</p>
|var=||dirpath.<em>oslist</em>(globpattern = "", mode = 0)||Returns: A FM delimited string containing all matching dir entries given a dir path
 
A glob pattern (e.g. *.conf) can be appended to the path or passed as argument.
A glob pattern (e.g. *.conf) can be appended to the path or passed as argument.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var entries1 = "/etc/"_var.oslist("*.cfg"); /// e.g. "adduser.conf^ca-certificates.con^... etc."
var entries1 = "/etc/"_var.oslist("*.cfg"); /// e.g. "adduser.conf^ca-certificates.con^... etc."
  // or
  // or
  var entries2 = oslist("/etc/" "*.conf");</syntaxhighlight>
  var entries2 = oslist("/etc/" "*.conf");</syntaxhighlight>
Line 1,576: Line 1,857:
|var=||dirpath.<em>oslistd</em>(globpattern = "")||Same as oslist for files only
|var=||dirpath.<em>oslistd</em>(globpattern = "")||Same as oslist for files only
|-
|-
|var=||osfile_or_dirpath.<em>osinfo</em>(mode = 0)||<em>Returns:</em> Dir info for any dir entry or "" if it doesnt exist</p>
|var=||osfile_or_dirpath.<em>osinfo</em>(mode = 0)||Returns: Dir info for any dir entry or "" if it doesnt exist
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time</p>
 
mode 0 default</p>
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time
mode 1 returns "" if not an os file</p>
 
mode 2 returns "" if not an os dir</p>
mode 0 default
 
mode 1 returns "" if not an os file
 
mode 2 returns "" if not an os dir
 
See also osfile() and osdir()
See also osfile() and osdir()
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var info1 = "/etc/hosts"_var.osinfo(); /// e.g. "221^20597^78309"_var
var info1 = "/etc/hosts"_var.osinfo(); /// e.g. "221^20597^78309"_var
  // or
  // or
  var info2 = osinfo("/etc/hosts");</syntaxhighlight>
  var info2 = osinfo("/etc/hosts");</syntaxhighlight>
|-
|-
|var=||osfilename.<em>osfile</em>()||<em>Returns:</em> Dir info for a os file</p>
|var=||osfilename.<em>osfile</em>()||Returns: Dir info for a os file
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time</p>
 
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time
 
Alias for osinfo(1)
Alias for osinfo(1)
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var fileinfo1 = "/etc/hosts"_var.osfile(); /// e.g. "221^20597^78309"_var
var fileinfo1 = "/etc/hosts"_var.osfile(); /// e.g. "221^20597^78309"_var
  // or
  // or
  var fileinfo2 = osfile("/etc/hosts");</syntaxhighlight>
  var fileinfo2 = osfile("/etc/hosts");</syntaxhighlight>
|-
|-
|var=||dirpath.<em>osdir</em>()||<em>Returns:</em> Dir info for a dir.</p>
|var=||dirpath.<em>osdir</em>()||Returns: Dir info for a dir.
A short string containing FM ^ modified_time ^ FM ^ modified_time</p>
 
A short string containing FM ^ modified_time ^ FM ^ modified_time
 
Alias for osinfo(2)
Alias for osinfo(2)
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var dirinfo1 = "/etc/"_var.osdir(); /// e.g. "^20848^44464"_var
var dirinfo1 = "/etc/"_var.osdir(); /// e.g. "^20848^44464"_var
  // or
  // or
  var dirinfo2 = osfile("/etc/");</syntaxhighlight>
  var dirinfo2 = osfile("/etc/");</syntaxhighlight>
|-
|-
|if||dirpath.<em>osmkdir</em>()||Makes a new directory and returns true if successful.</p>
|if||dirpath.<em>osmkdir</em>()||Makes a new directory and returns true if successful.
 
Including parent dirs if necessary.
Including parent dirs if necessary.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osdirname = "xo_test/aaa";
let osdirname = "xo_test/aaa";
  if (osrmdir("xo_test/aaa")) {}; // Cleanup first
  if (osrmdir("xo_test/aaa")) {}; // Cleanup first
  if (osdirname.osmkdir()) ... ok
  if (osdirname.osmkdir()) ... ok
Line 1,614: Line 1,905:
|if||dirpath.<em>oscwd</em>(newpath)||Changes the current working dir and returns true if successful.
|if||dirpath.<em>oscwd</em>(newpath)||Changes the current working dir and returns true if successful.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osdirname = "xo_test/aaa";
let osdirname = "xo_test/aaa";
  if (osdirname.oscwd()) ... ok
  if (osdirname.oscwd()) ... ok
  // or
  // or
  if (oscwd(osdirname)) ... ok</syntaxhighlight>
  if (oscwd(osdirname)) ... ok</syntaxhighlight>
|-
|-
|var=||dirpath.<em>oscwd</em>()||<em>Returns:</em> The current working directory</p>
|var=||dirpath.<em>oscwd</em>()||Returns: The current working directory
 
e.g. "/root/exodus/cli/src/xo_test/aaa"
e.g. "/root/exodus/cli/src/xo_test/aaa"
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var cwd1 = var().oscwd();
var cwd1 = var().oscwd();
  // or
  // or
  var cwd2 = oscwd();</syntaxhighlight>
  var cwd2 = oscwd();</syntaxhighlight>
|-
|-
|if||dirpath.<em>osrmdir</em>(evenifnotempty = false)||Removes a os dir and returns true if successful.</p>
|if||dirpath.<em>osrmdir</em>(evenifnotempty = false)||Removes a os dir and returns true if successful.
 
Optionally even if not empty. Including subdirs.
Optionally even if not empty. Including subdirs.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let osdirname = "xo_test/aaa";
let osdirname = "xo_test/aaa";
  if (oscwd("../..")) ... ok /// Change up before removing because cannot remove dir while it is current
  if (oscwd("../..")) ... ok /// Change up before removing because cannot remove dir while it is current
  if (osdirname.osrmdir()) ... ok
  if (osdirname.osrmdir()) ... ok
Line 1,640: Line 1,933:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|if||command.<em>osshell</em>()||Execute a shell command.</p>
|if||command.<em>osshell</em>()||Execute a shell command.
<em>Returns:</em> True if the process terminates with error status 0 and false otherwise.</p>
 
<em>Returns:</em> True if the process terminates with error status 0 and false otherwise.
 
Append "&>/dev/null" to the command to suppress terminal output.
Append "&>/dev/null" to the command to suppress terminal output.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let cmd = "echo $HOME";
let cmd = "echo $HOME";
  if (cmd.osshell()) ... ok
  if (cmd.osshell()) ... ok
  // or
  // or
  if (osshell(cmd)) ... ok</syntaxhighlight>
  if (osshell(cmd)) ... ok</syntaxhighlight>
|-
|-
|if||instr.<em>osshellread</em>(oscmd)||Same as osshell but captures and returns stdout</p>
|if||instr.<em>osshellread</em>(oscmd)||Same as osshell but captures and returns stdout
<em>Returns:</em> The stout of the shell command.</p>
 
<em>Returns:</em> The stout of the shell command.
 
Append "2>&1" to the command to capture stderr/stdlog output as well.
Append "2>&1" to the command to capture stderr/stdlog output as well.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let cmd = "echo $HOME";
let cmd = "echo $HOME";
  var text;
  var text;
  if (text.osshellread(cmd)) ... ok
  if (text.osshellread(cmd)) ... ok
Line 1,660: Line 1,957:
  text = osshellread(cmd);</syntaxhighlight>
  text = osshellread(cmd);</syntaxhighlight>
|-
|-
|if||outstr.<em>osshellwrite</em>(oscmd)||Same as osshell but provides stdin to the process</p>
|if||outstr.<em>osshellwrite</em>(oscmd)||Same as osshell but provides stdin to the process
<em>Returns:</em> True if the process terminates with error status 0 and false otherwise.</p>
 
<em>Returns:</em> True if the process terminates with error status 0 and false otherwise.
 
Append "&> somefile" to the command to suppress and/or capture output.
Append "&> somefile" to the command to suppress and/or capture output.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let outtext = "abc xyz";
let outtext = "abc xyz";
  if (outtext.osshellwrite("grep xyz")) ... ok
  if (outtext.osshellwrite("grep xyz")) ... ok
  // or
  // or
  if (osshellwrite(outtext, "grep xyz")) ... ok</syntaxhighlight>
  if (osshellwrite(outtext, "grep xyz")) ... ok</syntaxhighlight>
|-
|-
|var=||var().<em>ostempdirpath</em>()||<em>Returns:</em> The path of the tmp dir</p>
|var=||var().<em>ostempdirpath</em>()||Returns: The path of the tmp dir
 
e.g. "/tmp/"
e.g. "/tmp/"
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var().ostempdirpath();
let v1 = var().ostempdirpath();
  // or
  // or
  let v2 = ostempdirpath();</syntaxhighlight>
  let v2 = ostempdirpath();</syntaxhighlight>
|-
|-
|var=||var().<em>ostempfilename</em>()||<em>Returns:</em> The name of a new temporary file</p>
|var=||var().<em>ostempfilename</em>()||Returns: The name of a new temporary file
 
e.g. Something like "/tmp/~exoEcLj3C"
e.g. Something like "/tmp/~exoEcLj3C"
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var temposfilename1 = var().ostempfilename();
var temposfilename1 = var().ostempfilename();
  // or
  // or
  var temposfilename2 = ostempfilename();</syntaxhighlight>
  var temposfilename2 = ostempfilename();</syntaxhighlight>
Line 1,685: Line 1,986:
|cmd||envvalue.<em>ossetenv</em>(envcode)||Set the value of an environment variable code
|cmd||envvalue.<em>ossetenv</em>(envcode)||Set the value of an environment variable code
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let envcode = "EXO_ABC", envvalue = "XYZ";
let envcode = "EXO_ABC", envvalue = "XYZ";
  envvalue.ossetenv(envcode);
  envvalue.ossetenv(envcode);
  // or
  // or
Line 1,692: Line 1,993:
|if||envvalue.<em>osgetenv</em>(envcode)||Get the value of an environment variable
|if||envvalue.<em>osgetenv</em>(envcode)||Get the value of an environment variable
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var envvalue1;
var envvalue1;
  if (envvalue1.osgetenv("HOME")) ... ok // e.g. "/home/exodus"
  if (envvalue1.osgetenv("HOME")) ... ok // e.g. "/home/exodus"
  // or
  // or
Line 1,699: Line 2,000:
|var=||var().<em>ospid</em>()||Get the os process id
|var=||var().<em>ospid</em>()||Get the os process id
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let pid1 = var().ospid(); /// e.g. 663237
let pid1 = var().ospid(); /// e.g. 663237
  // or
  // or
  let pid2 = ospid();</syntaxhighlight>
  let pid2 = ospid();</syntaxhighlight>
Line 1,705: Line 2,006:
|var=||var().<em>ostid</em>()||Get the os thread process id
|var=||var().<em>ostid</em>()||Get the os thread process id
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let tid1 = var().ostid(); /// e.g. 663237
let tid1 = var().ostid(); /// e.g. 663237
  // or
  // or
  let tid2 = ostid();</syntaxhighlight>
  let tid2 = ostid();</syntaxhighlight>
Line 1,711: Line 2,012:
|var=||var().<em>version</em>()||Get the libexodus build date and time
|var=||var().<em>version</em>()||Get the libexodus build date and time
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var().version(); /// e.g. "29 JAN 2025 14:56:52"</syntaxhighlight>
let v1 = var().version(); /// e.g. "29 JAN 2025 14:56:52"</syntaxhighlight>
|-
|-
|if||strvar.<em>setxlocale</em>()||Sets the current thread's default locale codepage code</p>
|if||strvar.<em>setxlocale</em>()||Sets the current thread's default locale codepage code
 
True if successful
True if successful
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
if ("en_US.utf8"_var.setxlocale()) ... ok
if ("en_US.utf8"_var.setxlocale()) ... ok
  // or
  // or
  if (setxlocale("en_US.utf8")) ... ok</syntaxhighlight>
  if (setxlocale("en_US.utf8")) ... ok</syntaxhighlight>
|-
|-
|var=||var.<em>getxlocale</em>()||<em>Returns:</em> The current thread's default locale codepage code
|var=||var.<em>getxlocale</em>()||Returns: The current thread's default locale codepage code
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var().getxlocale(); // "en_US.utf8"
let v1 = var().getxlocale(); // "en_US.utf8"
  // or
  // or
  let v2 = getxlocale();</syntaxhighlight>
  let v2 = getxlocale();</syntaxhighlight>
Line 1,731: Line 2,033:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|expr||varstr.<em>outputl</em>(prefix = "")||Output to stdout with optional prefix.</p>
|expr||varstr.<em>outputl</em>(prefix = "")||Output to stdout with optional prefix.
Appends an NL char.</p>
 
Is FLUSHED, not buffered.</p>
Appends an NL char.
The raw string bytes are output. No character or byte conversion is performed.
 
Is FLUSHED, not buffered.
 
The raw string bytes are output. No character or byte conversion is performed.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
"abc"_var.outputl("xyz = "); /// Sends "xyz = abc\n" to stdout and flushes.
"abc"_var.outputl("xyz = "); /// Sends "xyz = abc\n" to stdout and flushes.
  // or
  // or
  outputl("xyz = ", "abc"); /// Any number of arguments is allowed. All will be output.</syntaxhighlight>
  outputl("xyz = ", "abc"); /// Any number of arguments is allowed. All will be output.</syntaxhighlight>
Line 1,744: Line 2,049:
|expr||varstr.<em>outputt</em>(prefix = "")|| Same as outputl() but appends a tab char instead of an NL char and is BUFFERED, not flushed.
|expr||varstr.<em>outputt</em>(prefix = "")|| Same as outputl() but appends a tab char instead of an NL char and is BUFFERED, not flushed.
|-
|-
|expr||varstr.<em>logputl</em>(prefix = "")||Output to stdlog with optional prefix.</p>
|expr||varstr.<em>logputl</em>(prefix = "")||Output to stdlog with optional prefix.
Appends an NL char.</p>
 
Is BUFFERED not flushed.</p>
Appends an NL char.
 
Is BUFFERED not flushed.
 
Any of the six types of field mark characters present are converted to their visible versions,
Any of the six types of field mark characters present are converted to their visible versions,
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
"abc"_var.logputl("xyz = "); /// Sends "xyz = abc\n" to stdlog buffer and is not flushed.
"abc"_var.logputl("xyz = "); /// Sends "xyz = abc\n" to stdlog buffer and is not flushed.
  // or
  // or
  logputl("xyz = ", "abc");; /// Any number of arguments is allowed. All will be output.</syntaxhighlight>
  logputl("xyz = ", "abc");; /// Any number of arguments is allowed. All will be output.</syntaxhighlight>
Line 1,755: Line 2,063:
|expr||varstr.<em>logput</em>(prefix = "")|| Same as logputl() but doesnt append an NL char.
|expr||varstr.<em>logput</em>(prefix = "")|| Same as logputl() but doesnt append an NL char.
|-
|-
|expr||varstr.<em>errputl</em>(prefix = "")||Output to stderr with optional prefix.</p>
|expr||varstr.<em>errputl</em>(prefix = "")||Output to stderr with optional prefix.
Appends an NL char.</p>
 
Is FLUSHED not buffered.</p>
Appends an NL char.
 
Is FLUSHED not buffered.
 
Any of the six types of field mark characters present are converted to their visible versions,
Any of the six types of field mark characters present are converted to their visible versions,
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
"abc"_var.errputl("xyz = "); /// Sends "xyz = abc\n" to stderr
"abc"_var.errputl("xyz = "); /// Sends "xyz = abc\n" to stderr
  // or
  // or
  errputl("xyz = ", "abc"); /// Any number of arguments is allowed. All will be output.</syntaxhighlight>
  errputl("xyz = ", "abc"); /// Any number of arguments is allowed. All will be output.</syntaxhighlight>
Line 1,766: Line 2,077:
|expr||varstr.<em>errput</em>(prefix = "")|| Same as errputl() but doesnt append an NL char and is BUFFERED not flushed.
|expr||varstr.<em>errput</em>(prefix = "")|| Same as errputl() but doesnt append an NL char and is BUFFERED not flushed.
|-
|-
|expr||varstr.<em>put</em>(std::ostream& ostream1)||Output to a given stream.</p>
|expr||varstr.<em>put</em>(std::ostream& ostream1)||Output to a given stream.
Is BUFFERED not flushed.</p>
 
Is BUFFERED not flushed.
 
The raw string bytes are output. No character or byte conversion is performed.
The raw string bytes are output. No character or byte conversion is performed.
|-
|-
|cmd||var().<em>osflush</em>()||Flush any and all buffered output to stdout and stdlog.
|cmd||var().<em>osflush</em>()||Flush any and all buffered output to stdout and stdlog.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var().osflush();
var().osflush();
  // or
  // or
  osflush();</syntaxhighlight>
  osflush();</syntaxhighlight>
Line 1,781: Line 2,094:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|expr||var.<em>input</em>(prompt = "")||Returns one line of input from stdin.</p>
|expr||var.<em>input</em>(prompt = "")||Returns one line of input from stdin.
Returns raw bytes up to but excluding the first new line character.</p>
 
Prompt: Optional. Will be displayed before the input field if provided.</p>
Returns raw bytes up to but excluding the first new line character.
 
<em>Prompt:</em> Optional. Will be displayed before the input field if provided.
 
If stdin is a terminal then the initial value of the var, if any, is the default value and can be edited with cursor keys like an OS command line. Pressing Enter or Ctrl+D will complete the input.
If stdin is a terminal then the initial value of the var, if any, is the default value and can be edited with cursor keys like an OS command line. Pressing Enter or Ctrl+D will complete the input.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
// var v1 = "default"; v1.input("Prompt:");
// var v1 = "default"; v1.input("Prompt:");
  // or
  // or
  // var v2 = input();</syntaxhighlight>
  // var v2 = input();</syntaxhighlight>
|-
|-
|expr||var.<em>inputn</em>(nchars)||Get raw bytes from standard input.</p>
|expr||var.<em>inputn</em>(nchars)||Get raw bytes from standard input.
Any new line characters are treated like any other bytes.</p>
 
Care must be taken to handle incomplete UTF8 byte sequences at the end of one block and the beginning of the next block.</p>
Any new line characters are treated like any other bytes.
<em>Returns:</em> The requested number of bytes or fewer if not available.</p>
 
nchars:</p>
Care must be taken to handle incomplete UTF8 byte sequences at the end of one block and the beginning of the next block.
99 : Get up to 99 bytes or fewer if not available. Caution required with UTF8.</p>
 
⋅0 : Get all bytes presently available.</p>
<em>Returns:</em> The requested number of bytes or fewer if not available.
⋅1 : Same as keypressed(true). Deprecated.</p>
 
<em>nchars:</em>
 
99 : Get up to 99 bytes or fewer if not available. Caution required with UTF8.
 
⋅0 : Get all bytes presently available.
 
⋅1 : Same as keypressed(true). Deprecated.
 
-1 : Same as keypressed(). Deprecated.
-1 : Same as keypressed(). Deprecated.
|-
|-
|expr||var.<em>keypressed</em>(wait = false)||Return the code of the current terminal key pressed.</p>
|expr||var.<em>keypressed</em>(wait = false)||Return the code of the current terminal key pressed.
wait: Defaults to false. True means wait for a key to be pressed if not already pressed.</p>
 
<em>Returns:</em> ASCII or key code defined according to terminal protocol.</p>
<em>wait:</em> Defaults to false. True means wait for a key to be pressed if not already pressed.
<em>Returns:</em> "" if stdin is not a terminal.</p>
 
e.g. The PgDn key if pressed might return an escape sequence like "\x1b[6~"</p>
<em>Returns:</em> ASCII or key code defined according to terminal protocol.
 
<em>Returns:</em> "" if stdin is not a terminal.
 
e.g. The PgDn key if pressed might return an escape sequence like "\x1b[6~"
 
It only takes a few µsecs to return false if no key is pressed.
It only takes a few µsecs to return false if no key is pressed.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1; v1.keypressed();
var v1; v1.keypressed();
  // or
  // or
  var v2 = keypressed();</syntaxhighlight>
  var v2 = keypressed();</syntaxhighlight>
|-
|-
|if||var().<em>isterminal</em>(arg = 1)||Checks if one of stdin, stdout, stderr is a terminal or a file/pipe.</p>
|if||var().<em>isterminal</em>(arg = 1)||Checks if one of stdin, stdout, stderr is a terminal or a file/pipe.
arg: 0 - stdin, 1 - stdout (Default), 2 - stderr.</p>
 
<em>Returns:</em> True if it is a terminal or false if it is a file or pipe.</p>
<em>arg:</em> 0 - stdin, 1 - stdout (Default), 2 - stderr.
Note that if the process is at the start or end of a pipeline, then only stdin or stdout will be a terminal.</p>
 
<em>Returns:</em> True if it is a terminal or false if it is a file or pipe.
 
Note that if the process is at the start or end of a pipeline, then only stdin or stdout will be a terminal.
 
The type of stdout terminal can be obtained from the TERM environment variable.
The type of stdout terminal can be obtained from the TERM environment variable.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = var().isterminal(); /// 1 or 0
var v1 = var().isterminal(); /// 1 or 0
  // or
  // or
  var v2 = isterminal();</syntaxhighlight>
  var v2 = isterminal();</syntaxhighlight>
|-
|-
|if||var().<em>hasinput</em>(milliseconds = 0)||Checks if stdin has any bytes available for input.</p>
|if||var().<em>hasinput</em>(milliseconds = 0)||Checks if stdin has any bytes available for input.
If no bytes are immediately available, the process sleeps for up to the given number of milliseconds, returning true immediately any bytes become available or false if the period expires without any bytes becoming available.</p>
 
<em>Returns:</em> True if any bytes are available otherwise false.</p>
If no bytes are immediately available, the process sleeps for up to the given number of milliseconds, returning true immediately any bytes become available or false if the period expires without any bytes becoming available.
 
<em>Returns:</em> True if any bytes are available otherwise false.
 
It only takes a few µsecs to return false if no bytes are available and no wait time has been requested.
It only takes a few µsecs to return false if no bytes are available and no wait time has been requested.
|-
|-
|if||var().<em>eof</em>()||True if stdin is at end of file
|if||var().<em>eof</em>()||True if stdin is at end of file
|-
|-
|if||var().<em>echo</em>(on_off = true)||Sets terminal echo on or off.</p>
|if||var().<em>echo</em>(on_off = true)||Sets terminal echo on or off.
"On" causes all stdin characters to be reflected to stdout if stdin is a terminal.</p>
 
Turning terminal echo off can be used to prevent display of confidential information.</p>
"On" causes all stdin characters to be reflected to stdout if stdin is a terminal.
 
Turning terminal echo off can be used to prevent display of confidential information.
 
<em>Returns:</em> True if successful.
<em>Returns:</em> True if successful.
|-
|-
|cmd||var().<em>breakon</em>()||Install various interrupt handlers.</p>
|cmd||var().<em>breakon</em>()||Install various interrupt handlers.
Automatically called in program/thread initialisation by exodus_main.</p>
 
SIGINT - Ctrl+C -> "Interrupted. (C)ontinue (Q)uit (B)acktrace (D)ebug (A)bort ?"</p>
Automatically called in program/thread initialisation by exodus_main.
SIGHUP - Sets a static variable "RELOAD_req" which may be handled or ignored by the program.</p>
 
SIGINT - Ctrl+C -> "Interrupted. (C)ontinue (Q)uit (B)acktrace (D)ebug (A)bort ?"
 
SIGHUP - Sets a static variable "RELOAD_req" which may be handled or ignored by the program.
 
SIGTERM - Sets a static variable "TERMINATE_req" which may be handled or ignored by the program.
SIGTERM - Sets a static variable "TERMINATE_req" which may be handled or ignored by the program.
|-
|-
|cmd||var().<em>breakoff</em>()||Disable keyboard interrupt.</p>
|cmd||var().<em>breakoff</em>()||Disable keyboard interrupt.
 
Ctrl+C becomes inactive in terminal.
Ctrl+C becomes inactive in terminal.
|}
|}
Line 1,849: Line 2,193:
|var=||varnum.<em>abs</em>()||Absolute value
|var=||varnum.<em>abs</em>()||Absolute value
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(-12.34).abs(); // 12.34
let v1 = var(-12.34).abs(); // 12.34
  // or
  // or
  let v2 = abs(-12.34);</syntaxhighlight>
  let v2 = abs(-12.34);</syntaxhighlight>
Line 1,855: Line 2,199:
|var=||varnum.<em>pwr</em>(exponent)||Power
|var=||varnum.<em>pwr</em>(exponent)||Power
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(2).pwr(8); // 256
let v1 = var(2).pwr(8); // 256
  // or
  // or
  let v2 = pwr(2, 8);</syntaxhighlight>
  let v2 = pwr(2, 8);</syntaxhighlight>
|-
|-
|cmd||varnum.<em>initrnd</em>()||Initialise the seed for rnd()</p>
|cmd||varnum.<em>initrnd</em>()||Initialise the seed for rnd()
Allows the stream of pseudo random numbers generated by rnd() to be reproduced.</p>
 
Allows the stream of pseudo random numbers generated by rnd() to be reproduced.
 
Seeded from std::chrono::high_resolution_clock::now() if the argument is 0;
Seeded from std::chrono::high_resolution_clock::now() if the argument is 0;
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var(123).initrnd(); /// Set seed to 123
var(123).initrnd(); /// Set seed to 123
  // or
  // or
  initrnd(123);</syntaxhighlight>
  initrnd(123);</syntaxhighlight>
|-
|-
|var=||varnum.<em>rnd</em>()||Pseudo random number generator</p>
|var=||varnum.<em>rnd</em>()||Pseudo random number generator
<em>Returns:</em> a pseudo random integer between 0 and the provided maximum minus 1.</p>
 
<em>Returns:</em> a pseudo random integer between 0 and the provided maximum minus 1.
 
Uses std::mt19937 and std::uniform_int_distribution<int>
Uses std::mt19937 and std::uniform_int_distribution<int>
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(100).rnd(); /// Random 0 to 99
let v1 = var(100).rnd(); /// Random 0 to 99
  // or
  // or
  let v2 = rnd(100);</syntaxhighlight>
  let v2 = rnd(100);</syntaxhighlight>
Line 1,877: Line 2,225:
|var=||varnum.<em>exp</em>()||Power of e
|var=||varnum.<em>exp</em>()||Power of e
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(1).exp(); // 2.718281828459045
let v1 = var(1).exp(); // 2.718281828459045
  // or
  // or
  let v2 = exp(1);</syntaxhighlight>
  let v2 = exp(1);</syntaxhighlight>
Line 1,883: Line 2,231:
|var=||varnum.<em>sqrt</em>()||Square root
|var=||varnum.<em>sqrt</em>()||Square root
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(100).sqrt(); // 10
let v1 = var(100).sqrt(); // 10
  // or
  // or
  let v2 = sqrt(100);</syntaxhighlight>
  let v2 = sqrt(100);</syntaxhighlight>
Line 1,889: Line 2,237:
|var=||varnum.<em>sin</em>()||Sine of degrees
|var=||varnum.<em>sin</em>()||Sine of degrees
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(30).sin(); // 0.5
let v1 = var(30).sin(); // 0.5
  // or
  // or
  let v2 = sin(30);</syntaxhighlight>
  let v2 = sin(30);</syntaxhighlight>
Line 1,895: Line 2,243:
|var=||varnum.<em>cos</em>()||Cosine of degrees
|var=||varnum.<em>cos</em>()||Cosine of degrees
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(60).cos(); // 0.5
let v1 = var(60).cos(); // 0.5
  // or
  // or
  let v2 = cos(60);</syntaxhighlight>
  let v2 = cos(60);</syntaxhighlight>
Line 1,901: Line 2,249:
|var=||varnum.<em>tan</em>()||Tangent of degrees
|var=||varnum.<em>tan</em>()||Tangent of degrees
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(45).tan(); // 1
let v1 = var(45).tan(); // 1
  // or
  // or
  let v2 = tan(45);</syntaxhighlight>
  let v2 = tan(45);</syntaxhighlight>
Line 1,907: Line 2,255:
|var=||varnum.<em>atan</em>()||Arctangent of degrees
|var=||varnum.<em>atan</em>()||Arctangent of degrees
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(1).atan(); // 45
let v1 = var(1).atan(); // 45
  // or
  // or
  let v2 = atan(1);</syntaxhighlight>
  let v2 = atan(1);</syntaxhighlight>
|-
|-
|var=||varnum.<em>loge</em>()||Natural logarithm</p>
|var=||varnum.<em>loge</em>()||Natural logarithm
 
<em>Returns:</em> Floating point ver (double)
<em>Returns:</em> Floating point ver (double)
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(2.718281828459045).loge(); // 1
let v1 = var(2.718281828459045).loge(); // 1
  // or
  // or
  let v2 = loge(2.718281828459045);</syntaxhighlight>
  let v2 = loge(2.718281828459045);</syntaxhighlight>
|-
|-
|var=||varnum.<em>integer</em>()||Truncate decimal numbers towards zero</p>
|var=||varnum.<em>integer</em>()||Truncate decimal numbers towards zero
 
<em>Returns:</em> An integer var
<em>Returns:</em> An integer var
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(2.9).integer(); // 2
let v1 = var(2.9).integer(); // 2
  // or
  // or
  let v2 = integer(2.9);
  let v2 = integer(2.9);
Line 1,929: Line 2,279:
  var v4 = integer(-2.9);</syntaxhighlight>
  var v4 = integer(-2.9);</syntaxhighlight>
|-
|-
|var=||varnum.<em>floor</em>()||Truncate decimal numbers towards negative</p>
|var=||varnum.<em>floor</em>()||Truncate decimal numbers towards negative
 
<em>Returns:</em> An integer var
<em>Returns:</em> An integer var
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(2.9).floor(); // 2
let v1 = var(2.9).floor(); // 2
  // or
  // or
  let v2 = floor(2.9);
  let v2 = floor(2.9);
Line 1,940: Line 2,291:
  var v4 = floor(-2.9);</syntaxhighlight>
  var v4 = floor(-2.9);</syntaxhighlight>
|-
|-
|var=||varnum.<em>mod</em>(modulus)||Modulus function</p>
|var=||varnum.<em>mod</em>(modulus)||Modulus function
Identical to C++ % operator only for positive numbers and modulus</p>
 
Negative denominators are considered as periodic with positiive numbers</p>
Identical to C++ % operator only for positive numbers and modulus
Result is between [0, modulus) if modulus is positive</p>
 
Result is between (modulus, 0] if modulus is negative (symmetric)</p>
Negative denominators are considered as periodic with positiive numbers
Throws: VarDivideByZero if modulus is zero.</p>
 
Result is between [0, modulus) if modulus is positive
 
Result is between (modulus, 0] if modulus is negative (symmetric)
 
<em>Throws:</em> VarDivideByZero if modulus is zero.
 
Floating point works.
Floating point works.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = var(11).mod(5); // 1
let v1 = var(11).mod(5); // 1
  // or
  // or
  let v2 = mod(11, 5); // 1
  let v2 = mod(11, 5); // 1
Line 1,960: Line 2,317:
!Usage!!Function!!Description
!Usage!!Function!!Description
|-
|-
|var=||vardate.<em>oconv_D</em>(conversion)||Date output: Convert internal date format to human readable date or calendar info in text format.</p>
|var=||vardate.<em>oconv_D</em>(conversion)||Date output: Convert internal date format to human readable date or calendar info in text format.
<em>Returns:</em> Human readable date or calendar info, or the original value unconverted if non-numeric.</p>
 
Flags: See examples below.</p>
<em>Returns:</em> Human readable date or calendar info, or the original value unconverted if non-numeric.
 
<em>Flags:</em> See examples below.
 
Any multifield/multivalue structure is preserved.
Any multifield/multivalue structure is preserved.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
let v1 = 12345;
let v1 = 12345;
  assert( v1.oconv( "D"  ) == "18 OCT 2001"  ); // Default
  assert( v1.oconv( "D"  ) == "18 OCT 2001"  ); // Default
  assert( v1.oconv( "D/"  ) == "10/18/2001"  ); // / separator
  assert( v1.oconv( "D/"  ) == "10/18/2001"  ); // / separator
Line 1,991: Line 2,351:
   assert( oconv(v1, "D"  ) == "18 OCT 2001"  );</syntaxhighlight>
   assert( oconv(v1, "D"  ) == "18 OCT 2001"  );</syntaxhighlight>
|-
|-
|var=||varstr.<em>iconv_D</em>(conversion)||Date input: Convert human readable date to internal date format.</p>
|var=||varstr.<em>iconv_D</em>(conversion)||Date input: Convert human readable date to internal date format.
<em>Returns:</em> Internal date or "" if the input is an invalid date.</p>
 
Internal date format is whole days since 1967-12-31 00:00:00 which is day 0.</p>
<em>Returns:</em> Internal date or "" if the input is an invalid date.
 
Internal date format is whole days since 1967-12-31 00:00:00 which is day 0.
 
Any multifield/multivalue structure is preserved.
Any multifield/multivalue structure is preserved.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
// International order "DE"
// International order "DE"
  assert(            oconv(19005, "DE") == "12 JAN 2020");
  assert(            oconv(19005, "DE") == "12 JAN 2020");
  assert(  "12/1/2020"_var.iconv("DE") == 19005);
  assert(  "12/1/2020"_var.iconv("DE") == 19005);
Line 2,022: Line 2,385:
  assert(iconv("12/1/2020"_var, "DE") == 19005);</syntaxhighlight>
  assert(iconv("12/1/2020"_var, "DE") == 19005);</syntaxhighlight>
|-
|-
|var=||vartime.<em>oconv_MT</em>(conversion)||Time output: Convert internal time format to human readable time e.g. "10:30:59".</p>
|var=||vartime.<em>oconv_MT</em>(conversion)||Time output: Convert internal time format to human readable time e.g. "10:30:59".
<em>Returns:</em> Human readable time or the original value unconverted if non-numeric.</p>
 
Conversion code (e.g. "MTHS") is "MT" + flags ...</p>
<em>Returns:</em> Human readable time or the original value unconverted if non-numeric.
Flags:</p>
 
"H" - Show AM/PM otherwise 24 hour clock is used.</p>
Conversion code (e.g. "MTHS") is "MT" + flags ...
"S" - Output seconds</p>
 
"2" = Ignored (used in iconv)</p>
<em>Flags:</em>
":" - Any other flag is used as the separator character instead of ":"</p>
 
"H" - Show AM/PM otherwise 24 hour clock is used.
 
"S" - Output seconds
 
"2" = Ignored (used in iconv)
 
":" - Any other flag is used as the separator character instead of ":"
 
Any multifield/multivalue structure is preserved.
Any multifield/multivalue structure is preserved.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = 234800;
var v1 = 234800;
  assert( v1.oconv( "MT"  ) == "17:13"      );
  assert( v1.oconv( "MT"  ) == "17:13"      ); // Default
  assert( v1.oconv( "MTH"  ) == "05:13PM"    );
  assert( v1.oconv( "MTH"  ) == "05:13PM"    ); // 'H' flag for AM/PM
  assert( v1.oconv( "MTS"  ) == "17:13:20"  );
  assert( v1.oconv( "MTS"  ) == "17:13:20"  ); // 'S' flag for seconds
  assert( v1.oconv( "MTHS" ) == "05:13:20PM" );
  assert( v1.oconv( "MTHS" ) == "05:13:20PM" ); // Both flags


  var v2 = 0;
  var v2 = 0;
Line 2,051: Line 2,422:
  assert( oconv(v1, "MT"  ) == "17:13"      );</syntaxhighlight>
  assert( oconv(v1, "MT"  ) == "17:13"      );</syntaxhighlight>
|-
|-
|var=||varstr.<em>iconv_MT</em>(strict)||Time input: Convert human readable time (e.g. "10:30:59") to internal time format.</p>
|var=||varstr.<em>iconv_MT</em>(strict)||Time input: Convert human readable time (e.g. "10:30:59") to internal time format.
<em>Returns:</em> Internal time or "" if the input is an invalid time.</p>
 
Internal time format is whole seconds since midnight.</p>
<em>Returns:</em> Internal time or "" if the input is an invalid time.
Accepts: Two or three groups of digits surrounded and separated by any non-digits character(s).</p>
 
Internal time format is whole seconds since midnight.
 
<em>Accepts:</em> Two or three groups of digits surrounded and separated by any non-digits character(s).
 
Any multifield/multivalue structure is preserved.
Any multifield/multivalue structure is preserved.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
assert(      "17:13"_var.iconv( "MT" ) == 61980);
assert(      "17:13"_var.iconv( "MT" ) == 61980);
  assert(    "05:13PM"_var.iconv( "MT" ) == 61980);
  assert(    "05:13PM"_var.iconv( "MT" ) == 61980);
  assert(  "17:13:20"_var.iconv( "MT" ) == 62000);
  assert(  "17:13:20"_var.iconv( "MT" ) == 62000);
Line 2,074: Line 2,449:
  assert(iconv("17:13", "MT") == 61980);</syntaxhighlight>
  assert(iconv("17:13", "MT") == 61980);</syntaxhighlight>
|-
|-
|var=||varnum.<em>oconv_MD</em>(conversion)||Number output: Convert internal numbers to external text format after rounding and optional scaling.</p>
|var=||varnum.<em>oconv_MD</em>(conversion)||Number output: Convert internal numbers to external text format after rounding and optional scaling.
<em>Returns:</em> A string or, if the value is not numeric, then no conversion is performed and the original value is returned.</p>
 
Conversion code (e.g. "MD20") is "MD" or "MC", 1st digit, 2nd digit, flags ...</p>
<em>Returns:</em> A string or, if the value is not numeric, then no conversion is performed and the original value is returned.
</p>
 
MD outputs like 123.45 (International)</p>
Conversion code (e.g. "MD20") is "MD" or "MC", 1st digit, 2nd digit, flags ...
MC outputs like 123,45 (European)</p>
 
</p>
 
1st digit = Decimal places to display. Also decimal places to move if 2nd digit not present and no P flag present.</p>
 
2nd digit = Optional decimal places to move left if P flag not present.</p>
MD outputs like 123.45 (International)
</p>
 
Flags:</p>
MC outputs like 123,45 (European)
"P" - Preserve decimal places. Same as 2nd digit = 0;</p>
 
"Z" - Zero flag - return "" if zero.</p>
 
"X" - No conversion - return as is.</p>
 
"." or "," - Separate thousands depending on MD or MC.</p>
1st digit = Decimal places to display. Also decimal places to move if 2nd digit not present and no P flag present.
"-" means suffix negatives with "-" and positives with " " (space).</p>
 
"<" means wrap negatives in "<" and ">" characters.</p>
2nd digit = Optional decimal places to move left if P flag not present.
"C" means suffix negatives with "CR" and positives or zero with "DB".</p>
 
"D" means suffix negatives with "DB" and positives or zero with "CR".</p>
 
</p>
 
<em>Flags:</em>
 
"P" - Preserve decimal places. Same as 2nd digit = 0;
 
"Z" - Zero flag - return "" if zero.
 
"X" - No conversion - return as is.
 
"." or "," - Separate thousands depending on MD or MC.
 
"-" means suffix negatives with "-" and positives with " " (space).
 
"<" means wrap negatives in "<" and ">" characters.
 
"C" means suffix negatives with "CR" and positives or zero with "DB".
 
"D" means suffix negatives with "DB" and positives or zero with "CR".
 
 
 
  Any multifield/multivalue structure is preserved.
  Any multifield/multivalue structure is preserved.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = -1234.567;
var v1 = -1234.567;
  assert( v1.oconv( "MD20"  ) ==  "-1234.57"  );
  assert( v1.oconv( "MD20"  ) ==  "-1234.57"  );
  assert( v1.oconv( "MD20,"  ) == "-1,234.57"  ); // , flag
  assert( v1.oconv( "MD20,"  ) == "-1,234.57"  ); // , flag
Line 2,112: Line 2,507:
  assert( oconv(v1, "MD20"  ) ==  "-1234.57"  );</syntaxhighlight>
  assert( oconv(v1, "MD20"  ) ==  "-1234.57"  );</syntaxhighlight>
|-
|-
|var=||var.<em>oconv_LRC</em>(format)||Text justification: Left, right and center. Padding and truncating. See Procrustes.</p>
|var=||var.<em>oconv_LRC</em>(format)||Text justification: Left, right and center. Padding and truncating. See Procrustes.
e.g. "L#10", "R#10", "C#10"</p>
 
Useful when outputting to terminal devices where spaces are used for alignment.</p>
e.g. "L#10", "R#10", "C#10"
Multifield/multivalue structure is preserved.</p>
 
Useful when outputting to terminal devices where spaces are used for alignment.
 
Multifield/multivalue structure is preserved.
 
ASCII only.
ASCII only.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
assert(    "abcde"_var.oconv( "L#3" ) == "abc" ); // Truncating
assert(    "abcde"_var.oconv( "L#3" ) == "abc" ); // Truncating
  assert(    "abcde"_var.oconv( "R#3" ) == "cde" );
  assert(    "abcde"_var.oconv( "R#3" ) == "cde" );
  assert(    "abcde"_var.oconv( "C#3" ) == "abc" );
  assert(    "abcde"_var.oconv( "C#3" ) == "abc" );
Line 2,140: Line 2,539:
  assert(    oconv("abcd", "L#3" ) == "abc" );</syntaxhighlight>
  assert(    oconv("abcd", "L#3" ) == "abc" );</syntaxhighlight>
|-
|-
|var=||varstr.<em>oconv_T</em>(format)||Text folding and justification.</p>
|var=||varstr.<em>oconv_T</em>(format)||Text folding and justification.
e.g. T#20</p>
 
Useful when outputting to terminal devices where spaces are used for alignment.</p>
e.g. T#20
Splits text into multiple fixed length lines by inserting spaces and TM characters.</p>
 
Useful when outputting to terminal devices where spaces are used for alignment.
 
Splits text into multiple fixed length lines by inserting spaces and TM characters.
 
ASCII only.
ASCII only.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
var v1 = "Have a nice day";
var v1 = "Have a nice day";
  assert(  v1.oconv("T#10") == "Have a␣␣␣␣|nice day␣␣"_var);
  assert(  v1.oconv("T#10") == "Have a␣␣␣␣|nice day␣␣"_var);
  // or
  // or
  assert( oconv(v1, "T#10") == "Have a␣␣␣␣|nice day␣␣"_var );</syntaxhighlight>
  assert( oconv(v1, "T#10") == "Have a␣␣␣␣|nice day␣␣"_var );</syntaxhighlight>
|-
|-
|var=||varstr.<em>oconv_HEX</em>(ioratio)||Convert a string of bytes to a string of hexadecimal digits. The size of the output is precisely double that of the input.</p>
|var=||varstr.<em>oconv_HEX</em>(ioratio)||Convert a string of bytes to a string of hexadecimal digits. The size of the output is precisely double that of the input.
 
Multifield/multivalue structure is not preserved. Field marks are converted to HEX as for all other bytes.
Multifield/multivalue structure is not preserved. Field marks are converted to HEX as for all other bytes.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
assert(    "ab01"_var.oconv( "HEX" ) == "61" "62" "30" "31" );
assert(    "ab01"_var.oconv( "HEX" ) == "61" "62" "30" "31" );
  assert( "\xff\x00"_var.oconv( "HEX" ) == "FF" "00"          ); // Any bytes are ok.
  assert( "\xff\x00"_var.oconv( "HEX" ) == "FF" "00"          ); // Any bytes are ok.
  assert(        var(10).oconv( "HEX" ) == "31" "30"          ); // Uses ASCII string equivalent of 10 i.e. "10".
  assert(        var(10).oconv( "HEX" ) == "31" "30"          ); // Uses ASCII string equivalent of 10 i.e. "10".
Line 2,162: Line 2,566:
  assert(      oconv("ab01"_var, "HEX") == "61" "62" "30" "31");</syntaxhighlight>
  assert(      oconv("ab01"_var, "HEX") == "61" "62" "30" "31");</syntaxhighlight>
|-
|-
|var=||varstr.<em>iconv_HEX</em>(ioratio)||Convert a string of hexadecimal digits to a string of bytes. After prefixing a "0" to an odd sized input, the size of the output is precisely half that of the input.</p>
|var=||varstr.<em>iconv_HEX</em>(ioratio)||Convert a string of hexadecimal digits to a string of bytes. After prefixing a "0" to an odd sized input, the size of the output is precisely half that of the input.
 
Reverse of oconv("HEX") above.
Reverse of oconv("HEX") above.
|-
|-
|var=||varnum.<em>oconv_MX</em>()||Numeric hex format: Convert number to hexadecimal string</p>
|var=||varnum.<em>oconv_MX</em>()||Numeric hex format: Convert number to hexadecimal string
 
If the value is not numeric then no conversion is performed and the original value is returned.
If the value is not numeric then no conversion is performed and the original value is returned.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
assert( var("255").oconv("MX") == "FF");
assert( var("255").oconv("MX") == "FF");
  // or
  // or
  assert( oconv(var("255"), "MX") == "FF");</syntaxhighlight>
  assert( oconv(var("255"), "MX") == "FF");</syntaxhighlight>
|-
|-
|var=||varnum.<em>oconv_MB</em>()||Numeric binary format: Convert number to strings of 1s and 0s</p>
|var=||varnum.<em>oconv_MB</em>()||Numeric binary format: Convert number to strings of 1s and 0s
 
If the value is not numeric then no conversion is performed and the original value is returned.
If the value is not numeric then no conversion is performed and the original value is returned.
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
assert( var(255).oconv("MB") == 1111'1111);
assert( var(255).oconv("MB") == 1111'1111);
  // or
  // or
  assert( oconv(var(255), "MB") == 1111'1111);</syntaxhighlight>
  assert( oconv(var(255), "MB") == 1111'1111);</syntaxhighlight>
|-
|-
|var=||varstr.<em>oconv_TX</em>(conversion)||Convert dynamic arrays to standard text format.</p>
|var=||varstr.<em>oconv_TX</em>(conversion)||Convert dynamic arrays to standard text format.
Useful for using text editors on dynamic arrays.</p>
 
Useful for using text editors on dynamic arrays.
 
FMs -> NL after escaping any embedded NL
FMs -> NL after escaping any embedded NL
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
  // backslash in text remains backslash
  // backslash in text remains backslash
   assert(var(_BS).oconv("TX") == _BS);
   assert(var(_BS).oconv("TX") == _BS);


Line 2,207: Line 2,616:
   assert("🌍~🌍"_var.oconv("TX") == "🌍" _BS _BS _BS _BS _NL "🌍");</syntaxhighlight>
   assert("🌍~🌍"_var.oconv("TX") == "🌍" _BS _BS _BS _BS _NL "🌍");</syntaxhighlight>
|-
|-
|var=||varstr.<em>iconv_TX</em>(conversion)||Convert standard text format to dynamic array.</p>
|var=||varstr.<em>iconv_TX</em>(conversion)||Convert standard text format to dynamic array.
 
Reverse of oconv("TX") above.
Reverse of oconv("TX") above.
|}
|}

Revision as of 15:01, 18 February 2025

Complete List of Functions

Generated by cli/gendoc from var.h

String Creation
Usage Function Description
var= varnum.round(ndecimals = 0) Returns: A var containing an ASCII string with the number of decimal places requested.

.5 always rounds away from zero.

 let v1 = var(0.295).round(2);  // "0.30"
 // or
 let v2 = round(1.295, 2);      // "1.30"

 var v3 = var(-0.295).round(2); // "-0.30"
 // or
 var v4 = round(-1.295, 2);     // "-1.30"

Negative number of decimals rounds to the left of the decimal point

 let v1 = round(123456.789,  0); // "123457"
 let v2 = round(123456.789, -1); // "123460"
 let v3 = round(123456.789, -2); // "123500"
var= var().chr(num) Returns: A string containing a single char (byte) given an integer 0-255.

0-127 -> ASCII, 128-255 -> invalid UTF-8 which cannot be written to the database or used in many exodus string operations

 let v1 = var().chr(0x61); // "a"
 // or
 let v2 = chr(0x61);
var= var().textchr(num) Returns: A string of a single unicode code point in utf8 encoding.

To get utf codepoints > 2^63 you must provide negative ints because var doesnt provide an implicit constructor to unsigned int due to getting ambigious conversions because int and unsigned int are parallel priority in c++ implicit conversions.

 let v1 = var().textchr(171416); // "𩶘" // or "\xF0A9B698"
 // or
 let v2 = textchr(171416);
var= var().str(num) Returns: A string of repeating characters or strings
 let v1 = "ab"_var.str(3); // "ababab"
 // or
 let v2 = str("ab", 3);
var= varnum.space() Returns: A string of space characters.
 let v1 = var(3).space(); // "␣␣␣"
 // or
 let v2 = space(3);
var= varnum.numberinwords(languagename_or_locale_id = "") Returns: A string representing a given number written in words instead of digits.

locale: Something like en_GB, ar_AE, el_CY, es_US, fr_FR etc.

 let softhyphen = "\xc2\xad";
 let v1 = var(123.45).numberinwords("de_DE").replace(softhyphen, " "); // "ein␣hundert␣drei␣und␣zwanzig␣Komma␣vier␣fünf"
String Scanning
Usage Function Description
var= var().seq() Returns: The character number of the first char.
 let v1 = "abc"_var.seq(); // 0x61 // decimal 97
 // or
 let v2 = seq("abc");
var= var().textseq() Returns: The Unicode character number of the first unicode code point.
 let v1 = "Γ"_var.textseq(); // 915 // U+0393: Greek Capital Letter Gamma (Unicode Character)
 // or
 let v2 = textseq("Γ");
var= var().len() Returns: The length of a string in number of chars
 let v1 = "abc"_var.len(); // 3
 // or
 let v2 = len("abc");
if var().empty() Returns: true if the var is an empty string.

This is a shorthand and more expressive way of writing 'if (var == "")' or 'if (var.len() == 0)' or 'if (not var.len())'

Note that 'if (var.empty())' is not the same as 'if (not var)' because 'if (var("0.0")' is defined as false because the string can be converted to a 0 which is always considered to be false. Compare thia with common scripting languages where 'if (var("0"))' is defined as true.

 let v1 = "0";
 if (not v1.empty()) ... ok /// true
 // or
 if (not empty(v1)) ... ok // true
var= var().textwidth() Returns: The number of output columns.

Allows multi column unicode and reduces combining characters etc. like e followed by grave accent

Possibly does not properly calculate combining sequences of graphemes e.g. face followed by colour

 let v1 = "🤡x🤡"_var.textwidth(); // 5
 // or
 let v2 = textwidth("🤡x🤡");
var= var().textlen() Returns: The number of Unicode code points
 let v1 = "Γιάννης"_var.textlen(); // 7
 // or
 let v2 = textlen("Γιάννης");
var= var().fcount(sepstr) Returns: The count of the number of fields separated by a given sepstr.

It is the same as var.count(sepstr) + 1 except that it returns 0 for an empty string.

 let v1 = "aa**cc"_var.fcount("*"); // 3
 // or
 let v2 = fcount("aa**cc", "*");
var= var().count(sepstr) Returns: The count of the number of sepstr found.
 let v1 = "aa**cc"_var.count("*"); // 2
 // or
 let v2 = count("aa**cc", "*");
if var().starts(prefix) Returns: True if starts with prefix
 if ("abc"_var.starts("ab")) ... true
 // or
 if (starts("abc", "ab")) ... true
if var().ends(suffix) Returns: True if ends with suffix
 if ("abc"_var.ends("bc")) ... true
 // or
 if (ends("abc", "bc")) ... true
if var().contains(substr) Returns: True if starts, ends or contains substr
 if ("abcd"_var.contains("bc")) ... true
 // or
 if (contains("abcd", "bc")) ... true
var= var().index(substr, startchar1 = 1) Returns: The index (1 based position) of a given substr on or after a given starting char number if present

Returns: 0 if not present.

 let v1 = "abcd"_var.index("bc"); // 2
 // or
 let v2 = index("abcd", "bc");
var= var().indexn(substr, occurrence) Returns: The index (1 based position) of the nth occurrence of a given substr if present

Returns: 0 if not present.

 let v1 = "abcabc"_var.index("bc", 2); // 2
 // or
 let v2 = index("abcabc", "bc", 2);
var= var().indexr(substr, startchar1 = -1) Reverse substr search.

Returns: The index (1 based position) of the substr on or before a given starting char number if present

startchar1 defaults to -1 meaning start searching from the last char (towards the first char).

 let v1 = "abcabc"_var.indexr("bc"); // 5
 // or
 let v2 = indexr("abcabc", "bc");
var= var().match(regex_str, regex_options = "") Returns: All results of regex matching

Multiple matches are returned separated by FMs. Groups are in VMs.

 let v1 = "abc1abc2"_var.match("BC(\\d)", "i"); // "bc1]1^bc2]2"_var
 // or
 let v2 = match("abc1abc2", "BC(\\d)", "i");

regex_options:


l - Literal (any regex chars are treated as normal chars)


i - Case insensitive


p - ECMAScript/Perl (the default)

b - Basic POSIX (same as sed)

e - Extended POSIX

a - awk

g - grep

eg - egrep or grep -E


char ranges like a-z are locale sensitive if ECMAScript


m - Multiline. Default in boost (and therefore exodus)

s - Single line. Default in std::regex


f - First only. Only for replace() (not match() or search())


w - Wildcard glob style (e.g. *.cfg) not regex style. Only for match() and search(). Not replace().

var= var().match(regex) Ditto
var= var().search(regex_str, io startchar1, regex_options = "") Search for first match of a regular expression starting at startchar1

Updates startchar1 ready to search for the next match

regex_options as for match()

 var startchar1 = 1;
 let v1 = "abc1abc2"_var.search("BC(\\d)", startchar1, "i"); // "bc1]1"_var // startchar1 -> 5 /// Ready for the next search
 // or
 startchar1 = 1;
 let v2 = search("abc1abc2", "BC(\\d)", startchar1, "i");
var= var().search(regex_str) Ditto starting from first char
var= var().search(regex, io startchar1) Ditto given a rex
var= var().search(regex) Ditto starting from first char.
var= var().hash(std::uint64_t modulus = 0) Hash by default returns a 64 bit signed integer as a var.

If a modulus is provided then the result is limited to [0, modulus)

MurmurHash3 is used.

 let v1 = "abc"_var.hash(); assert(v1 == var(6'715'211'243'465'481'821));
 // or
 let v2 = hash("abc");
String Conversion - Non-Mutating - Chainable
Usage Function Description
var= var().ucase() To upper case
 let v1 = "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"
 // or
 let v2 = ucase("Γιάννης");
var= var().lcase() To lower case
 let v1 = "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"
 // or
 let v2 = lcase("ΓΙΆΝΝΗΣ");
var= var().tcase() To title case. The first letter of each word is capitalised.
 let v1 = "γιάννης παππάς"_var.tcase(); // "Γιάννης Παππάς"
 // or
 let v2 = tcase("γιάννης παππάς");
var= var().fcase() To folded case to enable standardised indexing and searching,


Case folding is a process of converting a text to case independent representation.

https://www.w3.org/International/wiki/Case_folding

Accents can be significant. As in French cote, coté, côte and côté.

Case folding is not locale-dependent.

 let v1 = "Grüßen"_var.fcase(); // "grüssen"
 // or
 let v2 = tcase("Grüßen");
var= var().normalize() Normalises unicode code points sequences to their standardised NFC form making them binary comparable.


Unicode normalization is the process of converting strings to a standard form, suitable for text processing and comparison, and is an important part of Unicode text processing.

For example, character "é" can be represented by a single code point "\u00E9" (Latin Small Letter E with Acute) or a combination of the character "e" and the combining acute accent "\u0301".

Normalization is not locale-dependent.

 let v1 = "cafe\u0301"_var.normalize(); // "café"
 // or
 let v2 = normalize("cafe\u0301");
var= var().invert() Simple reversible disguising of text

invert(invert()) returns to the original text.

Flips bit 8 of unicode code points. Note that ASCII bytes become multibyte UTF-8 so string sizes change.

 let v1 = "abc"_var.invert(); // "\xC2" "\x9E" "\xC2" "\x9D" "\xC2" "\x9C"
 // or
 let v2 = invert("abc");
var= var().lower() Convert all FM to VM, VM to SM etc.
 let v1 = "a1^b2^c3"_var.lower(); // "a1]b2]c3"_var
 // or
 let v2 = lower("a1^b2^c3"_var);
var= var().raise() Convert all VM to FM, SM to VM etc.
 let v1 = "a1]b2]c3"_var.raise(); // "a1^b2^c3"_var
 // or
 let v2 = "a1]b2]c3"_var;
var= var().crop() Remove any redundant FM, VM etc. characters (Trailing FM; VM before FM etc.)
 let v1 = "a1^b2]]^c3^^"_var.crop(); // "a1^b2^c3"_var
 // or
 let v2 = crop("a1^b2]]^c3^^"_var);
var= var().quote() Wrap in double quotes
 let v1 = "abc"_var.quote(); // "\"abc\""
 // or
 let v2 = quote("abc");
var= var().squote() Wrap in single quotes
 let v1 = "abc"_var.squote(); // "'abc'"
 // or
 let v2 = squote("abc");
var= var().unquote() Remove one pair of double or single quotes
 let v1 = "'abc'"_var.unquote(); // "abc"
 // or
 let v2 = unquote("'abc'");
var= var().trim(trimchars = " ") Remove leading, trailing and excessive inner bytes
 let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trim(); // "a1␣b2␣c3"
 // or
 let v2 = trim("␣␣a1␣␣b2␣c3␣␣");
var= var().trimfirst(trimchars = " ") Ditto leading
 let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimfirst(); // "a1␣␣b2␣c3␣␣"
 // or
 let v2 = trimfirst("␣␣a1␣␣b2␣c3␣␣");
var= var().trimlast(trimchars = " ") Ditto trailing
 let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimlast(); // "␣␣a1␣␣b2␣c3"
 // or
 let v2 = trimlast("␣␣a1␣␣b2␣c3␣␣");
var= var().trimboth(trimchars = " ") Ditto leading, trailing but not inner
 let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimboth(); // "a1␣␣b2␣c3"
 // or
 let v2 = trimboth("␣␣a1␣␣b2␣c3␣␣");
var= var().first() Extract first char or "" if empty
 let v1 = "abc"_var.first(); // "a"
 // or
 let v2 = first("abc");
var= var().last() Extract last char or "" if empty
 let v1 = "abc"_var.last(); // "c"
 // or
 let v2 = last("abc");
var= var().first(std::size_t length) Extract up to length leading chars
 let v1 = "abc"_var.first(2); // "ab"
 // or
 let v2 = first("abc", 2);
var= var().last(std::size_t length) Extract up to length trailing chars
 let v1 = "abc"_var.last(2); // "bc"
 // or
 let v2 = last("abc", 2);
var= var().cut(length) Remove length leading chars
 let v1 = "abcd"_var.cut(2); // "cd"
 // or
 let v2 = cut("abcd", 2);
var= var().paste(pos1, length, insertstr) Insert text at char position overwriting length chars
 let v1 = "abcd"_var.paste(2, 2, "XYZ"); // "aXYZd"
 // or
 let v2 = paste("abcd", 2, 2, "XYZ");
var= var().paste(pos1, insertstr) Insert text at char position without overwriting any following characters
 let v1 = "abcd"_var.paste(2, "XYZ"); // "aXYZbcd"
 // or
 let v2 = paste("abcd", 2, "XYZ");
var= var().prefix(insertstr) Insert text at the beginning
 let v1 = "abc"_var.prefix("XYZ"); // "XYZabc"
 // or
 let v2 = prefix("abc", "XYZ");
var= var().append(appendable, ...) Append text at the end
 let v1 = "abc"_var.append(" is ", 10, " ok", '.'); // "abc is 10 ok."
 // or
 let v2 = append("abc", " is ", 10, " ok", '.');
var= var().pop() Remove one trailing char
 let v1 = "abc"_var.pop(); // "ab"
 // or
 let v2 = pop("abc");
var= var().field(strx, fieldnx = 1, nfieldsx = 1) Extract one or more consecutive fields given a delimiter char or substr.
 let v1 = "aa*bb*cc"_var.field("*", 2); // "bb"
 // or
 let v2 = field("aa*bb*cc", "*", 2);
var= var().field2(separator, fieldno, nfields = 1) field2 is a version that treats fieldn -1 as the last field, -2 the penultimate field etc. -

TODO Should probably make field() do this (since -1 is basically an erroneous call) and remove field2

Same as var.field() but negative fieldnos work backwards from the last field.

 let v1 = "aa*bb*cc"_var.field2("*", -1); // "cc"
 // or
 let v2 = field2("aa*bb*cc", "*", -1);
var= var().fieldstore(separator, fieldno, nfields, replacement) fieldstore() replaces n fields of subfield(s) in a string.
 let v1 = "aa*bb*cc*dd"_var.fieldstore("*", 2, 3, "X*Y"); // "aa*X*Y*"
 // or
 let v2 = fieldstore("aa*bb*cc*dd", "*", 2, 3, "X*Y");

If nfields is 0 then insert fields before fieldno

 let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, 0, "X*Y"); // "a1*X*Y*b2*c3*d4"
 // or
 let v2 = fieldstore("a1*b2*c3*d4", "*", 2, 0, "X*Y");

If nfields is negative then delete abs(n) fields before inserting.

 let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, -3, "X*Y"); // "a1*X*Y"
 // or
 let v2 = fieldstore("a1*b2*c3*d4", "*", 2, -3, "X*Y");
var= var().substr(pos1, length) substr version 1. Extract length chars starting at pos1
 let v1 = "abcd"_var.substr(2, 2); // "bc"
 // or
 let v2 = substr("abcd", 2, 2);

If length is negative then work backwards and return chars reversed

 let v1 = "abcd"_var.substr(3, -2); // "cb"
 // or
 let v2 = substr("abcd", 3, -2);
var= var().b(pos1, length) Same as substr version 1.
var= var().substr(pos1) substr version 2. Extract all chars from pos1 up to the end
 let v1 = "abcd"_var.substr(2); // "bcd"
 // or
 let v2 = substr("abcd", 2);
var= var().b(pos1) Same as substr version 2.
var= var().substr(pos1, delimiterchars, io pos2) substr version 3.

Extract a substr starting from pos1 up to any one of some given delimiter chars

Also returns in pos2 the pos of the following delimiter or one past the end of the string if not found.

Add 1 to pos2 start the next search if continuing.

 var pos1a = 4, pos2a;
 let v1 = "aa,bb,cc"_var.substr(pos1a, ",", pos2a); // "bb" // pos2a -> 6
 // or
 var pos1b = 4, pos2b;
 let v2 = substr("aa,bb,cc", pos1b, ",", pos2b);
var= var().b(pos1, delimiterchars, io pos2) Alias of substr version 3.
var= var().substr2(io pos1, out delimiterno) substr version 4.

Returns: A substr from a given pos1 up to the next RM/FM/VM/SM/TM/ST delimiter char.

Also returns the next index/offset and the delimiter no. found (1-6) or 0 if not found.

 var pos1a = 4, delim1;
 let v1 = "aa^bb^cc"_var.substr2(pos1a, delim1); // "bb" // pos1a -> 7 // delim1 -> 2
 // or
 var pos1b = 4, delim2;
 let v2 = substr2("aa^bb^cc"_var, pos1b, delim2);
var= var().b2(io pos1, out delimiterno) Alias of substr version 4
var= var().convert(fromchars, tochars) Convert chars to other chars one for one or delete where tochars is shorter.
 let v1 = "abcde"_var.convert("aZd", "XY"); // "Xbce" // a is replaced and d is removed
 // or
 let v2 = convert("abcde", "aZd", "XY");
var= var().textconvert(fromchars, tochars) Ditto for Unicode code points.
 let v1 = "a🤡b😀c🌍d"_var.textconvert("🤡😀", "👋"); // "a👋bc🌍d"
 // or
 let v2 = textconvert("a🤡b😀c🌍d", "🤡😀", "👋");
var= var().replace(fromstr, tostr) Replace all occurrences of a substr with another. Case sensitive
 let v1 = "Abc.Abc"_var.replace("bc", "X"); // "AX.AX"
 // or
 let v2 = replace("Abc Abc", "bc", "X");
var= var().replace(regex, tostr) Replace substring(s) using a regular expression.

Use $0, $1, $2 in tostr to refer to groups defined in the regex.

 let v1 = "A a B b"_var.replace("[A-Z]"_rex, "'$0'"); // "'A' a 'B' b"
 // or
 let v2 = replace("A a B b", "[A-Z]"_rex, "'$0'");
var= var().unique() Remove duplicate fields in an FM or VM etc. separated list
 let v1 = "a1^b2^a1^c2"_var.unique(); // "a1^b2^c2"_var
 // or
 let v2 = unique("a1^b2^a1^c2"_var);
var= var().sort(sepchar = FM) Reorder fields in an FM or VM etc. separated list in ascending order

Numerical:

 let v1 = "20^10^2^1^1.1"_var.sort(); // "1^1.1^2^10^20"_var
 // or
 let v2 = sort("20^10^2^1^1.1"_var);

Alphabetical:

 let v1 = "b1^a1^c20^c10^c2^c1^b2"_var.sort(); // "a1^b1^b2^c1^c10^c2^c20"_var
 // or
 let v2 = sort("b1^a1^c20^c10^c2^c1^b2"_var);
var= var().reverse(sepchar = FM) Reorder fields in an FM or VM etc. separated list in descending order
 let v1 = "20^10^2^1^1.1"_var.reverse(); // "1.1^1^2^10^20"_var
 // or
 let v2 = reverse("20^10^2^1^1.1"_var);
var= var().shuffle(sepchar = FM) Randomise the order of fields in an FM, VM separated list
 let v1 = "20^10^2^1^1.1"_var.shuffle(); /// e.g. "2^1^20^1.1^10" (random order depending on initrand())
 // or
 let v2 = shuffle("20^10^2^1^1.1"_var);
var= var().parse(char sepchar = ' ') Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes \" \'
 let v1 = "abc,\"def,\"123\" fgh\",12.34"_var.parse(','); // "abc^\"def,\"123\" fgh\"^12.34"_var
 // or
 let v2 = parse("abc,\"def,\"123\" fgh\",12.34", ',');
String Conversion - Mutating - Standalone Commands
Usage Function Description
cmd var().ucaser() Upper case

All string mutators follow the same pattern as ucaser.
See the non-mutating functions for details.

 var v1 = "abc";
 v1.ucaser(); // "ABC"
 // or
 ucaser(v1);
cmd var().lcaser()
cmd var().tcaser()
cmd var().fcaser()
cmd var().normalizer()
cmd var().inverter()
cmd var().quoter()
cmd var().squoter()
cmd var().unquoter()
cmd var().lowerer()
cmd var().raiser()
cmd var().cropper()
cmd var().trimmer(trimchars = " ")
cmd var().trimmerfirst(trimchars = " ")
cmd var().trimmerlast(trimchars = " ")
cmd var().trimmerboth(trimchars = " ")
cmd var().firster()
cmd var().laster()
cmd var().firster(std::size_t length)
cmd var().laster(std::size_t length)
cmd var().cutter(length)
cmd var().paster(pos1, length, insertstr)
cmd var().paster(pos1, insertstr)
cmd var().prefixer(insertstr)
cmd var().appender(appendable, ...)
cmd var().popper()
cmd var().fieldstorer(sepchar, fieldno, nfields, replacement)
cmd var().substrer(pos1, length)
cmd var().substrer(pos1)
cmd var().converter(fromchars, tochars)
cmd var().textconverter(fromchars, tochars)
cmd var().replacer(regex, tostr)
cmd var().replacer(fromstr, tostr)
cmd var().uniquer()
cmd var().sorter(sepchar = FM)
cmd var().reverser(sepchar = FM)
cmd var().shuffler(sepchar = FM)
cmd var().parser(char sepchar = ' ')
I/O Conversion
Usage Function Description
var= var.oconv(convstr) Converts internal data to output external display format according to a given conversion code or pattern

If the internal data is invalid and cannot be converted then most conversions return the ORIGINAL data unconverted

Throws a runtime error VarNotImplemented if convstr is invalid

See #ICONV/OCONV PATTERNS

 let v1 = var(30123).oconv("D/E"); // "21/06/2050"
 // or
 let v2 = oconv(30123, "D/E");
var= var.iconv(convstr) Converts external data to internal format according to a given conversion code or pattern

If the external data is invalid and cannot be converted then most conversions return the EMPTY STRING ""

Throws a runtime error VarNotImplemented if convstr is invalid

See #ICONV/OCONV PATTERNS

 let v1 = "21 JUN 2050"_var.iconv("D/E"); // 30123
 // or
 let v2 = iconv("21 JUN 2050", "D/E");
var= var.format(fmt_str, args, ...) Classic format function in printf style

vars can be formatted either with C++ format codes e.g. {:_>8.2f}

or with exodus oconv codes e.g. {::MD20P|R(_)#8} as in the below example.

 let v1 = var(12.345).format("'{:_>8.2f}'"); // "'___12.35'"
 let v2 = var(12.345).format("'{::MD20P|R(_)#8}'");
 // or
 var v3 = format("'{:_>8.2f}'", var(12.345)); // "'___12.35'"
 var v4 = format("'{::MD20P|R(_)#8}'", var(12.345));
var= var.from_codepage(codepage) Converts from codepage encoded text to UTF-8 encoded text

e.g. Codepage "CP1124" (Ukrainian).

Use Linux command "iconv -l" for complete list of code pages and encodings.

 let v1 = "\xa4"_var.from_codepage("CP1124"); // "Є"
 // or
 let v2 = from_codepage("\xa4", "CP1124");
 // U+0404 Cyrillic Capital Letter Ukrainian Ie Unicode Character
var= var.to_codepage(codepage) Converts to codepage encoded text from UTF-8 encoded text
 let v1 = "Є"_var.to_codepage("CP1124").oconv("HEX"); // "A4"
 // or
 let v2 = to_codepage("Є", "CP1124").oconv("HEX");
Dynamic Array Functions
Usage Function Description
var= var.f(fieldno, valueno = 0, subvalueno = 0) f() is a highly abbreviated alias for the PICK OS field/value/subvalue extract() function.

"f()" can be thought of as "field" although the function can extract values and subvalues as well.

The convenient PICK OS angle bracket syntax for field extraction (e.g. xxx<20>) is not available in C++.

The abbreviated exodus field extraction function (e.g. xxx.f(20)) is provided instead since field access is extremely heavily used in source code.

 let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
 let v2 = v1.f(2, 2); // "f2v2"
var= var.extract(fieldno, valueno = 0, subvalueno = 0) Extract a specific field, value or subvalue from a dynamic array.
 let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
 let v2 = v1.extract(2, 2); // "f2v2"
 //
 // For brevity the function alias "f()" (standing for "field") is normally used instead of "extract()" as follows:
 var v3 = v1.f(2, 2);
var= var.pickreplace(fieldno, valueno, subvalueno, replacement) Same as var.r() function but returns a new string instead of updating a variable in place.
Rarely used.
var= var.pickreplace(fieldno, valueno, replacement) Ditto for a specific multivalue
var= var.pickreplace(fieldno, replacement) Ditto for a specific field
var= var.insert(fieldno, valueno, subvalueno, insertion) Same as var.inserter() function but returns a new string instead of updating a variable in place.
var= var.insert(fieldno, valueno, insertion) Ditto for a specific multivalue
var= var.insert(fieldno, insertion) Ditto for a specific field
var= var.remove(fieldno, valueno = 0, subvalueno = 0) Same as var.remover() function but returns a new string instead of updating a variable in place.

"remove" was called "delete" in Pick OS.

Dynamic Array Filters
Usage Function Description
var= var.sum() Sum up multiple values into one higher level
 let v1 = "1]2]3^4]5]6"_var.sum(); // "6^15"_var
 // or
 let v2 = sum("1]2]3^4]5]6"_var);
var= var.sumall() Sum up all levels into a single figure
 let v1 = "1]2]3^4]5]6"_var.sumall(); // 21
 // or
 let v2 = sumall("1]2]3^4]5]6"_var);
var= var.sum(sepchar) Ditto allowing commas etc.
 let v1 = "10,20,30"_var.sum(","); // 60
 // or
 let v2 = sum("10,20,30", ",");
var= var.mv(opcode, var2) Binary ops (+, -, *, /) in parallel on multiple values
 let v1 = "10]20]30"_var.mv("+","2]3]4"_var); // "12]23]34"_var
Dynamic Array Mutators Standalone Commands
Usage Function Description
cmd var.r(fieldno, replacement) Replaces a specific field in a dynamic array
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.r(2, "X"); // "f1^X^f3"_var
cmd var.r(fieldno, valueno, replacement) Ditto for specific value in a specific field.
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.r(2, 2, "X"); // "f1^v1]X^f3"_var
cmd var.r(fieldno, valueno, subvalueno, replacement) Ditto for a specific subvalue in a specific value of a specific field
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.r(2, 2, 2, "X"); // "f1^v1]v2}X}s3^f3"_var
cmd var.inserter(fieldno, insertion) Insert a specific field in a dynamic array, moving all other fields up.
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.inserter(2, "X"); // "f1^X^v1]v2}s2}s3^f3"_var
 // or
 inserter(v1, 2, "X");
cmd var.inserter(fieldno, valueno, insertion) Ditto for a specific value in a specific field, moving all other values up.
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.inserter(2, 2, "X"); // "f1^v1]X]v2}s2}s3^f3"_var
 // or
 inserter(v1, 2, 2, "X");
cmd var.inserter(fieldno, valueno, subvalueno, insertion) Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.inserter(2, 2, 2, "X"); // "f1^v1]v2}X}s2}s3^f3"_var
 // or
 v1.inserter(2, 2, 2, "X");
cmd var.remover(fieldno, valueno = 0, subvalueno = 0) Remove a specific field (or value, or subvalue) from a dynamic array, moving all other fields (or values, or subvalues) down.
 var v1 = "f1^v1]v2}s2}s3^f3"_var;
 v1.remover(2, 2); // "f1^v1^f3"_var
 // or
 remover(v1, 2, 2);
Dynamic Array Search
Usage Function Description
var= var.locate(target) locate() with only the target substr argument provided searches unordered values separated by any of the field mark chars.

Returns: The field, value, subvalue etc. number if found or 0 if not.

 if ("UK^US^UA"_var.locate("US")) ... ok // 2
 // or
 if (locate("US", "UK^US^UA"_var)) ... ok
if var.locate(target, out valueno) locate() with only the target substr provided and setting returned searches unordered values separated by any type of field mark chars.

Returns: True if found

Setting: Field, value, subvalue etc. number if found or the max number + 1 if not. Suitable for additiom of new values

 var setting;
 if ("UK]US]UA"_var.locate("US", setting)) ... ok // setting -> 2
 // or
 if (locate("US", "UK]US]UA"_var, setting)) ... ok
if var.locate(target, out setting, fieldno, valueno = 0) locate() the target in unordered fields if fieldno is 0, or values if a fieldno is specified, or subvalues if the valueno argument is provided.

Returns: True if found and with the field, value or subvalue number in setting.

Returns: False if not found and with the max field, value or subvalue number found + 1 in setting. Suitable for replacement of new fields, values or subvalues.

 var setting;
 if ("f1^f2v1]f2v2]s1}s2}s3}s4^f3^f4"_var.locate("s4", setting, 2, 3)) ... ok // setting -> 4 // returns true
if var.locateby(ordercode, target, out valueno) locateby() without fieldno or valueno arguments searches ordered values separated by VM chars.

The order code can be AL, DL, AR, DR meaning Ascending Left, Descending Right, Ascending Right, Ascending Left.

Left is used to indicate alphabetic order where 10 < 2.

Right is used to indicate numeric order where 10 > 2.

Data must be in the correct order for searching to work properly.

Returns: True if found.

In case the target is not exactly found then the correct value no for inserting the target is returned in setting.

 var valueno; if ("aaa]bbb]ccc"_var.locateby("AL", "bb", valueno)) ... // valueno -> 2 // returns false and valueno = where it could be correctly inserted.
if var.locateby(ordercode, target, out setting, fieldno, valueno = 0) locateby() ordered as above but in fields if fieldno is 0, or values in a specific fieldno, or subvalues in a specific valueno.
 var setting;
 if ("f1^f2^aaa]bbb]ccc^f4"_var.locateby("AL", "bb", setting, 3)) ... // setting -> 2 // return false and where it could be correctly inserted.
if var.locateusing(usingchar, target) locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
 if ("AB,EF,CD"_var.locateusing(",", "EF")) ... ok
if var.locateusing(usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0) locate() the target in a specific field, value or subvalue using a specified delimiter and unordered data

Returns: True If found and returns in setting the number of the delimited field found.

Returns: False if not found and returns in setting the maximum number of delimited fields + 1 if not found.

This is similar to the main locate command but the delimiter char can be specified e.g. a comma or TM etc.

 var setting;
 if ("f1^f2^f3c1,f3c2,f3c3^f4"_var.locateusing(",", "f3c2", setting, 3)) ... ok // setting -> 2 // returns true
if var.locatebyusing(ordercode, usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0) locatebyusing() supports all the above features in a single function.

Returns: True if found.

Database Access
Usage Function Description
if conn.connect(conninfo = "") For all db operations, the operative var can either be a db connection created with dbconnect() or be any var and a default connection will be established on the fly.

The db connection string (conninfo) parameters are merged from the following places in descending priority.

1. Provided in connect()'s conninfo argument. See 4. for the complete list of parameters.

2. Any environment variables EXO_HOST EXO_PORT EXO_USER EXO_DATA EXO_PASS EXO_TIME

3. Any parameters found in a configuration file at ~/.config/exodus/exodus.cfg

4. The default conninfo is "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10"

Setting environment variable EXO_DBTRACE=1 will cause tracing of db interface including SQL commands.

 let conninfo = "dbname=exodus user=exodus password=somesillysecret";
 if (not conn.connect(conninfo)) ...;
 // or
 if (not connect()) ...
 // or
 if (not connect("exodus")) ...
if conn.attach(filenames) Attach (connect) specific files by name to specific connections.

It is not necessary to attach files before opening them. Attach is meant to control the defaults.

For the remainder of the session, opening the db file by name without specifying a connection will automatically use the specified connection applies during the attach command.

If conn is not specified then filename will be attached to the default connection.

Multiple file names must be separated by FM

 let filenames = "definitions^dict.definitions"_var, conn = "exodus";
 if (conn.attach(filenames)) ... ok
 // or
 if (attach(filenames)) ... ok
cmd conn.detach(filenames) Detach (disconnect) files that have been attached using attach().
if conn.begintrans() Begin a db transaction.
 if (not conn.begintrans()) ...
 // or
 if (not begintrans()) ...
if conn.statustrans() Check if a db transaction is in progress.
 if (conn.statustrans()) ... ok
 // or
 if (statustrans()) ... ok
if conn.rollbacktrans() Rollback a db transaction.
 if (conn.rollbacktrans()) ... ok
 // or
 if (rollbacktrans()) ... ok
if conn.committrans() Commit a db transaction.

Returns: True if successfully committed or if there was no transaction in progress, otherwise false.

 if (conn.committrans()) ... ok
 // or
 if (committrans()) ... ok
if conn.sqlexec(sqlcmd) Execute an sql command.

Returns: True if there was no sql error otherwise lasterror() returns a detailed error message.

 if (conn.sqlexec("vacuum")) ... ok
 // or
 if (sqlexec("vacuum")) ... ok
if conn.sqlexec(sqlcmd, io response) Execute an SQL command and capture the response.

Returns: True if there was no sql error otherwise response contains a detailed error message.

response: Any rows and columns returned are separated by RM and FM respectively. The first row is the column names.

Recommended: Don't use sql directly unless you must to manage or configure a database.

 let sqlcmd = "select 'xxx' as col1, 'yyy' as col2";
 var response;
 if (conn.sqlexec(sqlcmd, response)) ... ok // response -> "col1^col2\x1fxxx^yyy"_var /// \x1f is the Record Mark (RM) character. The backtick character is used here by gendoc to deliminate source code.
 // or
 if (sqlexec(sqlcmd, response)) ... ok
cmd conn.disconnect() Closes db connection and frees process resources both locally and in the database server.
 conn.disconnect();
 // or
 disconnect();
cmd conn.disconnectall() Closes all connections and frees process resources both locally and in the database server(s).

All connections are closed automatically when a process terminates.

 conn.disconnectall();
 // or
 disconnectall();
var= conn.lasterror() Returns: The last os or db error message.
 var v1 = var().lasterror();
 // or
 var v2 = lasterror();
var= conn.loglasterror(source = "") Log the last os or db error message.

Output: to stdlog

Prefixes the output with source if provided.

 var().loglasterror("main:");
 // or
 loglasterror("main:");
Database Management
Usage Function Description
if conn.dbcreate(new_dbname, old_dbname = "") Create a named database on a particular connection.

The target database cannot already exist.

Optionally copies an existing database from the same connection and which cannot have any current connections.

 var conn = "exodus";
 if (not dbdelete("xo_gendoc_testdb")) {}; // Cleanup first
 if (conn.dbcreate("xo_gendoc_testdb")) ... ok
 // or
 if (dbcreate("xo_gendoc_testdb")) ...
if conn.dbcopy(from_dbname, to_dbname) Create a named database as a copy of an existing database.

The target database cannot already exist.

The source database must exist on the same connection and cannot have any current connections.

 var conn = "exodus";
 if (not dbdelete("xo_gendoc_testdb2")) {}; // Cleanup first
 if (conn.dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ... ok
 // or
 if (dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ...
var= conn.dblist() Returns: A list of available databases on a particular connection.
 let v1 = conn.dblist();
 // or
 let v2 = dblist();
if conn.dbdelete(dbname) Delete (drop) a named database.

The target database must exist and cannot have any current connections.

 var conn = "exodus";
 if (conn.dbdelete("xo_gendoc_testdb2")) ... ok
 // or
 if (dbdelete("xo_gendoc_testdb2")) ...
if conn.createfile(filename) Create a named db file.
 let filename = "xo_gendoc_temp", conn = "exodus";
 if (conn.createfile(filename)) ... ok
 // or
 if (createfile(filename)) ...
if conn.renamefile(filename, newfilename) Rename a db file.
 let conn = "exodus", filename = "xo_gendoc_temp", new_filename = "xo_gendoc_temp2";
 if (conn.renamefile(filename, new_filename)) ... ok
 // or
 if (renamefile(filename, new_filename)) ...
var= conn.listfiles() Returns: A list of all files in a database
 var conn = "exodus";
 if (not conn.listfiles()) ...
 // or
 if (not listfiles()) ...
if conn.clearfile(filename) Delete all records in a db file
 let conn = "exodus", filename = "xo_gendoc_temp2";
 if (not conn.clearfile(filename)) ...
 // or
 if (not clearfile(filename)) ...
if conn.deletefile(filename) Delete a db file
 let conn = "exodus", filename = "xo_gendoc_temp2";
 if (conn.deletefile(filename)) ... ok
 // or
 if (deletefile(filename)) ...
var= conn_or_file.reccount(filename = "") Returns: The approx. number of records in a db file
 let conn = "exodus", filename = "xo_clients";
 var nrecs1 = conn.reccount(filename);
 // or
 var nrecs2 = reccount(filename);
if conn_or_file.flushindex(filename = "") Calls db maintenance function (vacuum)

This doesnt actually flush any indexes but does make sure that reccount() function is reasonably accurate.

Database File I/O
Usage Function Description
if file.open(dbfilename, connection = "") Opens a db file to a var which can be used in subsequent functions to work on the specified file and database connection.
 var file, filename = "definitions";
 if (not file.open(filename)) ...
 // or
 if (not open(filename to file)) ...
cmd file.close() Closes db file var

Does nothing currently since database file vars consume no resources

 var file = "definitions";
 file.close();
 // or
 close(file);
if file.createindex(fieldname, dictfile = "") Creates a secondary index for a given db file and field name.

The fieldname must exist in a dictionary file. The default dictionary is "dict." ^ filename.

Returns: False if the index cannot be created for any reason.

  • Index already exists
  • File does not exist
  • The dictionary file does not have a record with a key of the given field name.
  • The dictionary file does not exist. Default is "dict." ^ filename.
  • The dictionary field defines a calculated field that uses an exodus function. Using a psql function is OK.
 var filename = "definitions", fieldname = "DATE_TIME";
 if (not deleteindex("definitions", "DATE_TIME")) {}; // Cleanup first
 if (filename.createindex(fieldname)) ... ok
 // or
 if (createindex(filename, fieldname)) ...
var= conn.listindex(file_or_filename = "", fieldname = "") Lists secondary indexes in a database or for a db file

Returns: False if the db file or fieldname are given and do not exist

 var conn = "exodus";
 if (conn.listindex()) ... ok // includes "xo_clients__date_time"
 // or
 if (listindex()) ... ok
if file.deleteindex(fieldname) Deletes a secondary index for a db file and field name.

Returns: False if the index cannot be deleted for any reason

  • File does not exist
  • Index does not already exists
 var file = "definitions", fieldname = "DATE_TIME";
 if (file.deleteindex(fieldname)) ... ok
 // or
 if (deleteindex(file, fieldname)) ...
var= file.lock(key) Places a metaphorical db lock on a particular record given a db file and key.

This is a advisory lock, not a physical lock, since it makes no restriction on the access or modification of data by other connections.

Neither the db file nor the record key need to actually exist since a lock is just a hash of the db file name and key combined.

If another connection attempts to place an identical lock on the same database it will be denied.

Locks can be removed by unlock() or unlockall() or will be automatically removed at the end of a transaction or when the connection is closed.

If the same process attempts to place an identical lock more than once it may be denied (if not in a transaction) or succeed but be ignored (if in a transaction).

Locks can be used to avoid processing a transaction simultaneously with another connection only to have one of them fail due to mutually updating the same records.

Returns::

  • 0: Failure: Another connection has already placed the same lock.
  • "" Failure: The lock has already been placed.
  • 1: Success: A new lock has been placed.
  • 2: Success: The lock has already been placed and the connection is in a transaction.
 var file = "xo_clients", key = "1000";
 if (file.lock(key)) ... ok
 // or
 if (lock(file, key)) ...
if file.unlock(key) Removes a db lock placed by the lock function.

Only locks placed on the specified connection can be removed.

Locks cannot be removed while a connection is in a transaction.

Returns: False if the lock is not present in a connection.

 var file = "xo_clients", key = "1000";
 if (file.unlock(key)) ... ok
 // or
 if (unlock(file, key)) ...
if file.unlockall() Removes all db locks placed by the lock function in the specified connection.

Locks cannot be removed while in a transaction.

 var conn = "exodus";
 if (not conn.unlockall()) ...
 // or
 if (not unlockall(conn)) ...
cmd rec.write(file, key) Writes a record into a db file given a unique primary key.

Either inserts a new record or updates an existing record.

It always succeeds so no result code is returned.

Any memory cached record is deleted.

 let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
 let file = "xo_clients", key = "GD001";
 if (not deleterecord("xo_clients", "GD001")) {}; // Cleanup first
 rec.write(file, key);
 // or
 write(rec on file, key);
if rec.read(file, key) Reads a record from a db file for a given key.

Returns: False if the key doesnt exist

 var rec;
 let file = "xo_clients", key = "GD001";
 if (not rec.read(file, key)) ... // rec -> "Client GD^G^20855^30000^1001.00^20855.76539"_var
 // or
 if (not read(rec from file, key)) ...
if file.deleterecord(key) Deletes a record from a db file given a key.

Returns: False if the key doesnt exist

Any memory cached record is deleted.

 let file = "xo_clients", key = "GD001";
 if (file.deleterecord(key)) ... ok
 // or
if (deleterecord(file, key)) ...
if rec.insertrecord(file, key) Inserts a new record in a db file.

Returns: False if the key already exists

Any memory cached record is deleted.

 let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
 let file = "xo_clients", key = "GD001";
 if (rec.insertrecord(file, key)) ... ok
 // or
 if (insertrecord(rec on file, key)) ...
if rec.updaterecord(file, key) Updates an existing record in a db file.

Returns: False if the key doesnt already exist

Any memory cached record is deleted.

 let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
 let file = "xo_clients", key = "GD001";
 if (not rec.updaterecord(file, key)) ...
 // or
 if (not updaterecord(rec on file, key)) ...
if rec.readf(file, key, fieldno) "Read field" Same as read() but only returns a specific field from the record
 var field, file = "xo_clients", key = "GD001", fieldno = 2;
 if (not field.readf(file, key, fieldno)) ... // field -> "G"
 // or
 if (not readf(field from file, key, fieldno)) ...
cmd rec.writef(file, key, fieldno) "write field" Same as write() but only writes to a specific field in the record
 var field = "f3", file = "definitions", key = "1000", fieldno = 3;
 field.writef(file, key, fieldno);
 // or
 writef(field on file, key, fieldno);
cmd rec.writec(file, key) "Write cache" Writes a record and key into a memory cached "db file".

The actual database file is NOT updated.

writec() either updates an existing cache record if the key already exists or otherwise inserts a new record into the cache.

It always succeeds so no result code is returned.

Neither the db file nor the record key need to actually exist in the actual db.

 let rec = "Client XD^X^20855^30000^1001.00^20855.76539"_var;
 let file = "xo_clients", key = "XD001";
 rec.writec(file, key);
 // or
 writec(rec on file, key);
if rec.readc(file, key) "Read cache" Same as "read() but first reads from a memory cache.

1. Tries to read from a memory cache. Returns true if successful.

2a. Tries to read from the actual db file and returns false if unsuccessful.

2b. Writes the record and key to the memory cache and returns true.

Cached db file data lives in exodus process memory and is lost when the process terminates or cleardbcache() is called.

 var rec;
 let file = "xo_clients", key = "XD001";
 if (rec.readc(file, key)) ... ok
 // or
 if (readc(rec from file, key)) ... ok

 // Verify not in actual database file by using read() not readc()
 if (read(rec from file, key)) abort("Error: " ^ key ^ " should not be in the actual database file"); // error
if dbfile.deletec(key) Deletes a record and key from a memory cached "file".

The actual database file is NOT updated.

Returns: False if the key doesnt exist

 var file = "xo_clients", key = "XD001";
 if (file.deletec(key)) ... ok
 // or
 if (deletec(file, key)) ...
cmd conn.cleardbcache() Clears the memory cache of all records for the given connection

All future cache readc() function calls will be forced to obtain records from the actual database and refresh the cache.

 conn.cleardbcache();
 // or
cleardbcache(conn);
var= conn.xlate(filename, fieldno, mode) The xlate ("translate") function is similar to readf() but, when called as an exodus program member function, it can be used efficiently with exodus file dictionaries using column names and functions and multivalued data.

Arguments:

strvar: Used as the primary key to lookup a field in a given file and field no or field name.

filename: The db file in which to look up data.

If var key is multivalued then a multivalued field is returned.

fieldno: Determines which field of the record is returned.

  • Integer returns that field number
  • 0 means return the key unchanged.
  • "" means return the whole record.

mode: Determines what is returned if the record does not exist for the given key and file.

  • "X" returns ""
  • "C" returns the key unconverted.
 let key = "SB001";
 let client_name = key.xlate("xo_clients", 1, "X"); // "Client AAA"
 // or
 let name_and_type = xlate("xo_clients", key, "NAME_AND_TYPE", "X"); // "Client AAA (A)"
Database Sort/Select
Usage Function Description
if dbfile.select(sort_select_command = "") Create an active select list of keys of a database file.

The select(command) function searches and orders database records for subsequent processing given an English language-like command.

The primary job of a database, beyond mere storage and retrieval of information, is to allow rapid searching and ordering of information on demand.

In Exodus, searching and ordering of information is known as "sort/select" and is performed by the select() function.

Executing the select() function creates an "active select list" which can then be consumed by the readnext() function.

dbfile: A opened database file or file name, or an open connection or an empty var for default connections. Subsequent readnext calls must use the same.

sort_select_command: A natural language command using dictionary field names. The command can be blank if a dbfile or filename is given in dbfile or just a file name and all keys will be selected in undefined order.

Example: "select xo_clients with type 'B' and with balance ge 100 by type by name"

Option: "(R)" appended to the sort_select_command acquires the database records as well.

Returns: True if any records are selected or false if none.

Throws: VarDBException in case of any syntax error in the command.

Active select lists created using var.select()'s member function syntax cannot be consumed by the free function form of readnext() and vice versa.

 var clients = "xo_clients";
 if (clients.select("with type 'B' and with balance ge 100 by type by name"))
     while (clients.readnext(ID))
         println("Client code is {}", ID);
 // or
 if (select("xo_clients with type 'B' and with balance ge 100 by type by name"))
     while (readnext(ID))
         println("Client code is {}", ID);
if dbfile.selectkeys(keys) Create an active select list from a string of keys.

Similar to select() but creates the list directly from a var.

keys: An FM separated list of keys or key^VM^valueno pairs.

Returns: True if any keys are provided or false if not.

 var dbfile = "";
 let keys = "A01^B02^C03"_var;
 if (dbfile.selectkeys(keys)) ... ok
 assert(dbfile.readnext(ID) and ID == "A01");
 // or
 if (selectkeys(keys)) ... ok
 assert(readnext(ID) and ID == "A01");
if dbfile.hasnext() Checks if a select list is active.

dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.

Returns: True if a select list is active and false if not.

If it returns true then a call to readnext() will return a database record key, otherwise not.

 var clients = "xo_clients", key;
 if (clients.select()) {
     assert(clients.hasnext());
 }
 // or
 if (select("xo_clients")) {
     assert(hasnext());
 }
if dbfile.readnext(out key) Acquires and consumes one key from an active select list of database record keys.

dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.

key: Returns the first (next) key present in an active select list or "" if no select list is active.

Returns: True if a list is active and a key is available, false if not.

Each call to readnext consumes one key from the list.

Once all the keys in an active select list have been consumed by calls to readnext, the list becomes inactive.

See select() for example code.

if dbfile.readnext(out key, out valueno) Similar to readnext(key) but multivalued.

If the active list was ordered by multivalued database fields then pairs of key and multivalue number will be available to the readnext function.

if dbfile.readnext(out record, out key, out valueno) Similar to readnext(key) but acquires the database record as well.

record: Returns the next database record from the select list assuming that the select list was created with the (R) option otherwise "" if not.

key: Returns the next database record key in the select list.

valueno: The multivalue number if the select list was ordered on multivalued database record fields or 1 if not.

 var clients = "xo_clients";
 if (clients.select("with type 'B' and with balance ge 100 by type by name (R)"))
     while (clients.readnext(RECORD, ID, MV))
         println("Code is {}, Name is {}", ID, RECORD.f(1));
 // or
 DICT = "dict.xo_clients";
 if (select("xo_clients with type 'B' and with balance ge 100 by type by name (R)"))
     while (readnext(RECORD, ID, MV))
         println("Code is {}, Name is {}", calculate("CODE"), calculate("NAME"));
cmd dbfile.clearselect() Deactivates an active select list.

dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.

Returns: Nothing

Has no effect if no select list is active for dbfile.

 var clients = "xo_clients";
 clients.clearselect();
 if (not clients.hasnext()) ... ok
 // or
 clearselect();
 if (not hasnext()) ... ok
if dbfile.savelist(listname) Stores an active select list for later retrieval.

dbfile: A file or connection var used in a prior select, selectkeys or getlist function call.

listname: A suitable name that will be required for later retrieval.

Returns: True if saved successfully or false if there was no active list to be saved.

Any existing list with the same name will be overwritten.

Only the remaining unconsumed part of the active select list is saved.

Saved lists are stand-alone and are not tied to specific database files although they usually hold keys related to specific files.

Saved lists can be created from one file and used to access another.

savelist() merely writes an FM separated string of keys as a record in the "lists" database file using the list name as the key of the record.

If a saved list is very long, additional blocks of keys for the same list may be stored with keys like listname*2, listname*3 etc.

Select lists saved in the lists database file may be created, deleted and listed like database records in any other database file.

 var clients = "xo_clients";
 if (clients.select("with type 'B' by name")) {
 }
 // or
 if (select("xo_clients with type 'B' by name")) {
     if (savelist("mylist")) ... ok
 }
if dbfile.getlist(listname) Retrieve and reactivate a saved select list.

dbfile: A file or connection var to be used by subsequent readnext function calls.

listname: The name of an existing list in the "lists" database file, either created by savelist or manually.

Returns: True if the list was successfully retrieved and activated, or false if the list name doesnt exist.

Any currently active select list is replaced.

Retrieving a list does not delete it and a list can be retrieved more than once until specifically deleted.

 var file = "";
 if (file.getlist("mylist")) {
     while (file.readnext(ID))
         println("Key is {}", ID);
 }
 // or
 if (getlist("mylist")) {
     while (readnext(ID))
         println("Key is {}", ID);
 }
if dbfile.deletelist(listname) Delete a saved select list.

dbfile: A file or connection to the desired database.

listname: The name of an existing list in the "lists" database file.

Returns: True if successful or false if the list name doesnt exist.

 var conn = "";
 if (conn.deletelist("mylist")) ... ok
 // or
 if (deletelist("mylist")) ... ok
OS Time/Date
Usage Function Description
var= var().date() Number of whole days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.

e.g. was 20821 from 2025-01-01 00:00:00 UTC for 24 hours

 let today1 = var().date();
 // or
 let today2 = date();
var= var().time() Number of whole seconds since last 00:00:00 (UTC).

e.g. 43200 if time is 12:00

Range 0 - 86399 since there are 24*60*60 (86400) seconds in a day.

 let now1 = var().time();
 // or
 let now2 = time();
var= var().ostime() Number of fractional seconds since last 00:00:00 (UTC).

A floating point with approx. nanosecond resolution depending on hardware.

e.g. 23343.704387955 approx. 06:29:03 UTC

 let now1 = var().ostime();
 // or
 let now2 = ostime();
var= var().timestamp() Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.

A floating point with approx. nanosecond resolution depending on hardware.

e.g. Was 20821.99998842593 around 2025-01-01 23:59:59 UTC

 let now1 = var().timestamp();
 // or
 let now2 = timestamp();
var= var().timestamp(ostime) Construct a timestamp from a date and time
 let idate = iconv("2025-01-01", "D"), itime = iconv("23:59:59", "MT");
 let ts1 = idate.timestamp(itime); // 20821.99998842593
 // or
 let ts2 = timestamp(idate, itime);
cmd var().ossleep(milliseconds) Sleep/pause/wait for a number of milliseconds

Releases the processor if not needed for a period of time or a delay is required.

 var().ossleep(100); // sleep for 100ms
 // or
 ossleep(100);
var= file_dir_list.oswait(milliseconds) Sleep/pause/wait up to a given number of milliseconds or until any changes occur in an FM delimited list of directories and/or files.

Any terminal input (e.g. a key press) will also terminate the wait.

An FM array of event information is returned. See below.

Multiple events are returned in multivalues.

 let v1 = ".^/etc/hosts"_var.oswait(100); /// e.g. "IN_CLOSE_WRITE^/etc^hosts^f"_var
 // or
 let v2 = oswait(".^/etc/hosts"_var, 100);

Returned array fields

1. Event type codes

2. dirpaths

3. filenames

4. d=dir, f=file

Possible event type codes are as follows:

  • IN_CLOSE_WRITE - A file opened for writing was closed
  • IN_ACCESS - Data was read from file
  • IN_MODIFY - Data was written to file
  • IN_ATTRIB - File attributes changed
  • IN_CLOSE - File was closed (read or write)
  • IN_MOVED_FROM - File was moved away from watched directory
  • IN_MOVED_TO - File was moved into watched directory
  • IN_MOVE - File was moved (in or out of directory)
  • IN_CREATE - A file was created in the directory
  • IN_DELETE - A file was deleted from the directory
  • IN_DELETE_SELF - Directory or file under observation was deleted
  • IN_MOVE_SELF - Directory or file under observation was moved
OS File I/O
Usage Function Description
if osfilevar.osopen(osfilename, utf8 = true) Given the name of an existing os file name including path, initialises an os file handle var that can be used in random access osbread and osbwrite functions.

The utf8 option defaults to true which causes trimming of partial utf-8 unicode byte sequences from the end of osbreads. For raw untrimmed osbreads pass utf8 = false;

File will be opened for writing if possible otherwise for reading.

Returns: True if successful or false if not possible for any reason.

e.g. Target doesnt exist, permissions etc.

 let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 if (oswrite("" on osfilename)) ... ok /// Create an empty os file
 var ostempfile;
 if (ostempfile.osopen(osfilename)) ... ok
 // or
 if (osopen(osfilename to ostempfile)) ... ok
if osfilevar.osbwrite(osfilevar, io offset) Writes data to an existing os file starting at a given byte offset (0 based).

See osbread for more info.

 let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 let text = "aaa=123\nbbb=456\n";
 var offset = osfile(osfilename).f(1); /// Size of file therefore append
 if (text.osbwrite(osfilename, offset)) ... ok // offset -> 16
 // or
 if (not osbwrite(text on osfilename, offset)) ...
if osfilevar.osbread(osfilevar, io offset, length) Reads length bytes from an existing os file starting at a given byte offset (0 based).

The osfilevar file handle may either be initialised by osopen or be just be a normal string variable holding the path and name of the os file.

After reading, the offset is updated to point to the correct offset for a subsequent sequential read.

If reading utf8 data (the default) then the length of data actually returned may be a few bytes shorter than requested in order to be a complete number of UTF-8 code points.

 let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 var text, offset = 0;
 if (text.osbread(osfilename, offset, 8)) ... ok // text -> "aaa=123\n" // offset -> 8
 // or
 if (osbread(text from osfilename, offset, 8)) ... ok // text -> "bbb=456\n" // offset -> 16
cmd osfilevar.osclose() Removes an osfilevar handle from the internal memory cache of os file handles. This frees up both exodus process memory and operating system resources.

It is advisable to osclose any file handles after use, regardless of whether they were specifically opened using osopen or not, especially in long running programs. Exodus performs caching of internal os file handles per thread and os file. If not closed, then the operating system will probably not flush deleted files from storage until the process is terminated. This can potentially create an memory issue or file system resource issue especially if osopening/osreading/oswriting many perhaps temporary files in a long running process.

 osfilevar.osclose();
 // or
 osclose(osfilevar);
if osfilevar.oswrite(osfilename, codepage = "") Create a complete os file from a var.

Any existing os file is removed first.

Returns: True if successful or false if not possible for any reason.

e.g. Path is not writeable, permissions etc.

If codepage is specified then output is converted from utf-8 to that codepage. Otherwise no conversion is done.

 let text = "aaa = 123\nbbb = 456";
 let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 if (text.oswrite(osfilename)) ... ok
 // or
 if (oswrite(text on osfilename)) ... ok
if osfilevar.osread(osfilename, codepage = "") Read a complete os file into a var.

If codepage is specified then input is converted from that codepage to utf-8 otherwise no conversion is done.

Returns: True if successful or false if not possible for any reason.

e.g. File doesnt exist, permissions etc.

 var text;
 let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 if (text.osread(osfilename)) ... ok // text -> "aaa = 123\nbbb = 456"
 // or
 if (osread(text from osfilename)) ... ok
if osfile_or_dirname.osrename(new_dirpath_or_filepath) Renames an os file or dir in the OS file system.

Will not overwrite an existing os file or dir.

Source and target must exist in the same storage device.

Returns: True if successful or false if not possible for any reason.

e.g. Target already exists, path is not writeable, permissions etc.

Uses std::filesystem::rename internally.

 let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 let to_osfilename = from_osfilename ^ ".bak";
 if (not osremove(ostempdirpath() ^ "xo_gendoc_test.conf.bak")) {}; // Cleanup first

 if (from_osfilename.osrename(to_osfilename)) ... ok
 // or
 if (osrename(from_osfilename, to_osfilename)) ...
if osfile_or_dirname.osmove(to_osfilename) "Moves" an os file or dir within the os file system.

Will not overwrite an existing os file or dir.

Returns: True if successful or false if not possible for any reason.

e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions etc.

Attempts osrename first then oscopy followed by osremove original.

 let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf.bak";
 let to_osfilename = from_osfilename.cut(-4);

 if (not osremove(ostempdirpath() ^ "xo_gendoc_test.conf")) {}; // Cleanup first
 if (from_osfilename.osmove(to_osfilename)) ... ok
 // or
 if (osmove(from_osfilename, to_osfilename)) ...
if osfile_or_dirname.oscopy(to_osfilename) Copies an os file or directory recursively within the os file system.

Will overwrite an existing os file or dir.

Uses std::filesystem::copy internally with recursive and overwrite options

 let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 let to_osfilename = from_osfilename ^ ".bak";

 if (from_osfilename.oscopy(to_osfilename)) ... ok;
 // or
 if (oscopy(from_osfilename, to_osfilename)) ... ok
if osfilename.osremove() Removes/deletes an os file from the OS file system given path and name.

Will not remove directories. Use osrmdir() to remove directories

Returns: True if successful or false if not possible for any reason.

e.g. Target doesnt exist, path is not writeable, permissions etc.

 let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
 if (osfilename.osremove()) ... ok
 // or
 if (osremove(osfilename)) ...
OS Directories
Usage Function Description
var= dirpath.oslist(globpattern = "", mode = 0) Returns: A FM delimited string containing all matching dir entries given a dir path

A glob pattern (e.g. *.conf) can be appended to the path or passed as argument.

 var entries1 = "/etc/"_var.oslist("*.cfg"); /// e.g. "adduser.conf^ca-certificates.con^... etc."
 // or
 var entries2 = oslist("/etc/" "*.conf");
var= dirpath.oslistf(globpattern = "") Same as oslist for files only
var= dirpath.oslistd(globpattern = "") Same as oslist for files only
var= osfile_or_dirpath.osinfo(mode = 0) Returns: Dir info for any dir entry or "" if it doesnt exist

A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time

mode 0 default

mode 1 returns "" if not an os file

mode 2 returns "" if not an os dir

See also osfile() and osdir()

 var info1 = "/etc/hosts"_var.osinfo(); /// e.g. "221^20597^78309"_var
 // or
 var info2 = osinfo("/etc/hosts");
var= osfilename.osfile() Returns: Dir info for a os file

A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time

Alias for osinfo(1)

 var fileinfo1 = "/etc/hosts"_var.osfile(); /// e.g. "221^20597^78309"_var
 // or
 var fileinfo2 = osfile("/etc/hosts");
var= dirpath.osdir() Returns: Dir info for a dir.

A short string containing FM ^ modified_time ^ FM ^ modified_time

Alias for osinfo(2)

 var dirinfo1 = "/etc/"_var.osdir(); /// e.g. "^20848^44464"_var
 // or
 var dirinfo2 = osfile("/etc/");
if dirpath.osmkdir() Makes a new directory and returns true if successful.

Including parent dirs if necessary.

 let osdirname = "xo_test/aaa";
 if (osrmdir("xo_test/aaa")) {}; // Cleanup first
 if (osdirname.osmkdir()) ... ok
 // or
 if (osmkdir(osdirname)) ...
if dirpath.oscwd(newpath) Changes the current working dir and returns true if successful.
 let osdirname = "xo_test/aaa";
 if (osdirname.oscwd()) ... ok
 // or
 if (oscwd(osdirname)) ... ok
var= dirpath.oscwd() Returns: The current working directory

e.g. "/root/exodus/cli/src/xo_test/aaa"

 var cwd1 = var().oscwd();
 // or
 var cwd2 = oscwd();
if dirpath.osrmdir(evenifnotempty = false) Removes a os dir and returns true if successful.

Optionally even if not empty. Including subdirs.

 let osdirname = "xo_test/aaa";
 if (oscwd("../..")) ... ok /// Change up before removing because cannot remove dir while it is current
 if (osdirname.osrmdir()) ... ok
 // or
 if (osrmdir(osdirname)) ...
OS Shell/Environment
Usage Function Description
if command.osshell() Execute a shell command.

Returns: True if the process terminates with error status 0 and false otherwise.

Append "&>/dev/null" to the command to suppress terminal output.

 let cmd = "echo $HOME";
 if (cmd.osshell()) ... ok
 // or
 if (osshell(cmd)) ... ok
if instr.osshellread(oscmd) Same as osshell but captures and returns stdout

Returns: The stout of the shell command.

Append "2>&1" to the command to capture stderr/stdlog output as well.

 let cmd = "echo $HOME";
 var text;
 if (text.osshellread(cmd)) ... ok

 // or capturing stdout but ignoring exit status
 text = osshellread(cmd);
if outstr.osshellwrite(oscmd) Same as osshell but provides stdin to the process

Returns: True if the process terminates with error status 0 and false otherwise.

Append "&> somefile" to the command to suppress and/or capture output.

 let outtext = "abc xyz";
 if (outtext.osshellwrite("grep xyz")) ... ok
 // or
 if (osshellwrite(outtext, "grep xyz")) ... ok
var= var().ostempdirpath() Returns: The path of the tmp dir

e.g. "/tmp/"

 let v1 = var().ostempdirpath();
 // or
 let v2 = ostempdirpath();
var= var().ostempfilename() Returns: The name of a new temporary file

e.g. Something like "/tmp/~exoEcLj3C"

 var temposfilename1 = var().ostempfilename();
 // or
 var temposfilename2 = ostempfilename();
cmd envvalue.ossetenv(envcode) Set the value of an environment variable code
 let envcode = "EXO_ABC", envvalue = "XYZ";
 envvalue.ossetenv(envcode);
 // or
 ossetenv(envcode, envvalue);
if envvalue.osgetenv(envcode) Get the value of an environment variable
 var envvalue1;
 if (envvalue1.osgetenv("HOME")) ... ok // e.g. "/home/exodus"
 // or
 var envvalue2 = osgetenv("EXO_ABC"); // "XYZ"
var= var().ospid() Get the os process id
 let pid1 = var().ospid(); /// e.g. 663237
 // or
 let pid2 = ospid();
var= var().ostid() Get the os thread process id
 let tid1 = var().ostid(); /// e.g. 663237
 // or
 let tid2 = ostid();
var= var().version() Get the libexodus build date and time
 let v1 = var().version(); /// e.g. "29 JAN 2025 14:56:52"
if strvar.setxlocale() Sets the current thread's default locale codepage code

True if successful

 if ("en_US.utf8"_var.setxlocale()) ... ok
 // or
 if (setxlocale("en_US.utf8")) ... ok
var= var.getxlocale() Returns: The current thread's default locale codepage code
 let v1 = var().getxlocale(); // "en_US.utf8"
 // or
 let v2 = getxlocale();
Output
Usage Function Description
expr varstr.outputl(prefix = "") Output to stdout with optional prefix.

Appends an NL char.

Is FLUSHED, not buffered.

The raw string bytes are output. No character or byte conversion is performed.

 "abc"_var.outputl("xyz = "); /// Sends "xyz = abc\n" to stdout and flushes.
 // or
 outputl("xyz = ", "abc"); /// Any number of arguments is allowed. All will be output.
expr varstr.output(prefix = "") Same as outputl() but doesnt append an NL char and is BUFFERED, not flushed.
expr varstr.outputt(prefix = "") Same as outputl() but appends a tab char instead of an NL char and is BUFFERED, not flushed.
expr varstr.logputl(prefix = "") Output to stdlog with optional prefix.

Appends an NL char.

Is BUFFERED not flushed.

Any of the six types of field mark characters present are converted to their visible versions,

 "abc"_var.logputl("xyz = "); /// Sends "xyz = abc\n" to stdlog buffer and is not flushed.
 // or
 logputl("xyz = ", "abc");; /// Any number of arguments is allowed. All will be output.
expr varstr.logput(prefix = "") Same as logputl() but doesnt append an NL char.
expr varstr.errputl(prefix = "") Output to stderr with optional prefix.

Appends an NL char.

Is FLUSHED not buffered.

Any of the six types of field mark characters present are converted to their visible versions,

 "abc"_var.errputl("xyz = "); /// Sends "xyz = abc\n" to stderr
 // or
 errputl("xyz = ", "abc"); /// Any number of arguments is allowed. All will be output.
expr varstr.errput(prefix = "") Same as errputl() but doesnt append an NL char and is BUFFERED not flushed.
expr varstr.put(std::ostream& ostream1) Output to a given stream.

Is BUFFERED not flushed.

The raw string bytes are output. No character or byte conversion is performed.

cmd var().osflush() Flush any and all buffered output to stdout and stdlog.
 var().osflush();
 // or
 osflush();
Input
Usage Function Description
expr var.input(prompt = "") Returns one line of input from stdin.

Returns raw bytes up to but excluding the first new line character.

Prompt: Optional. Will be displayed before the input field if provided.

If stdin is a terminal then the initial value of the var, if any, is the default value and can be edited with cursor keys like an OS command line. Pressing Enter or Ctrl+D will complete the input.

 // var v1 = "default"; v1.input("Prompt:");
 // or
 // var v2 = input();
expr var.inputn(nchars) Get raw bytes from standard input.

Any new line characters are treated like any other bytes.

Care must be taken to handle incomplete UTF8 byte sequences at the end of one block and the beginning of the next block.

Returns: The requested number of bytes or fewer if not available.

nchars:

99 : Get up to 99 bytes or fewer if not available. Caution required with UTF8.

⋅0 : Get all bytes presently available.

⋅1 : Same as keypressed(true). Deprecated.

-1 : Same as keypressed(). Deprecated.

expr var.keypressed(wait = false) Return the code of the current terminal key pressed.

wait: Defaults to false. True means wait for a key to be pressed if not already pressed.

Returns: ASCII or key code defined according to terminal protocol.

Returns: "" if stdin is not a terminal.

e.g. The PgDn key if pressed might return an escape sequence like "\x1b[6~"

It only takes a few µsecs to return false if no key is pressed.

 var v1; v1.keypressed();
 // or
 var v2 = keypressed();
if var().isterminal(arg = 1) Checks if one of stdin, stdout, stderr is a terminal or a file/pipe.

arg: 0 - stdin, 1 - stdout (Default), 2 - stderr.

Returns: True if it is a terminal or false if it is a file or pipe.

Note that if the process is at the start or end of a pipeline, then only stdin or stdout will be a terminal.

The type of stdout terminal can be obtained from the TERM environment variable.

 var v1 = var().isterminal(); /// 1 or 0
 // or
 var v2 = isterminal();
if var().hasinput(milliseconds = 0) Checks if stdin has any bytes available for input.

If no bytes are immediately available, the process sleeps for up to the given number of milliseconds, returning true immediately any bytes become available or false if the period expires without any bytes becoming available.

Returns: True if any bytes are available otherwise false.

It only takes a few µsecs to return false if no bytes are available and no wait time has been requested.

if var().eof() True if stdin is at end of file
if var().echo(on_off = true) Sets terminal echo on or off.

"On" causes all stdin characters to be reflected to stdout if stdin is a terminal.

Turning terminal echo off can be used to prevent display of confidential information.

Returns: True if successful.

cmd var().breakon() Install various interrupt handlers.

Automatically called in program/thread initialisation by exodus_main.

SIGINT - Ctrl+C -> "Interrupted. (C)ontinue (Q)uit (B)acktrace (D)ebug (A)bort ?"

SIGHUP - Sets a static variable "RELOAD_req" which may be handled or ignored by the program.

SIGTERM - Sets a static variable "TERMINATE_req" which may be handled or ignored by the program.

cmd var().breakoff() Disable keyboard interrupt.

Ctrl+C becomes inactive in terminal.

Math/Boolean
Usage Function Description
var= varnum.abs() Absolute value
 let v1 = var(-12.34).abs(); // 12.34
 // or
 let v2 = abs(-12.34);
var= varnum.pwr(exponent) Power
 let v1 = var(2).pwr(8); // 256
 // or
 let v2 = pwr(2, 8);
cmd varnum.initrnd() Initialise the seed for rnd()

Allows the stream of pseudo random numbers generated by rnd() to be reproduced.

Seeded from std::chrono::high_resolution_clock::now() if the argument is 0;

 var(123).initrnd(); /// Set seed to 123
 // or
 initrnd(123);
var= varnum.rnd() Pseudo random number generator

Returns: a pseudo random integer between 0 and the provided maximum minus 1.

Uses std::mt19937 and std::uniform_int_distribution<int>

 let v1 = var(100).rnd(); /// Random 0 to 99
 // or
 let v2 = rnd(100);
var= varnum.exp() Power of e
 let v1 = var(1).exp(); // 2.718281828459045
 // or
 let v2 = exp(1);
var= varnum.sqrt() Square root
 let v1 = var(100).sqrt(); // 10
 // or
 let v2 = sqrt(100);
var= varnum.sin() Sine of degrees
 let v1 = var(30).sin(); // 0.5
 // or
 let v2 = sin(30);
var= varnum.cos() Cosine of degrees
 let v1 = var(60).cos(); // 0.5
 // or
 let v2 = cos(60);
var= varnum.tan() Tangent of degrees
 let v1 = var(45).tan(); // 1
 // or
 let v2 = tan(45);
var= varnum.atan() Arctangent of degrees
 let v1 = var(1).atan(); // 45
 // or
 let v2 = atan(1);
var= varnum.loge() Natural logarithm

Returns: Floating point ver (double)

 let v1 = var(2.718281828459045).loge(); // 1
 // or
 let v2 = loge(2.718281828459045);
var= varnum.integer() Truncate decimal numbers towards zero

Returns: An integer var

 let v1 = var(2.9).integer(); // 2
 // or
 let v2 = integer(2.9);

 var v3 = var(-2.9).integer(); // -2
 // or
 var v4 = integer(-2.9);
var= varnum.floor() Truncate decimal numbers towards negative

Returns: An integer var

 let v1 = var(2.9).floor(); // 2
 // or
 let v2 = floor(2.9);

 var v3 = var(-2.9).floor(); // -3
 // or
 var v4 = floor(-2.9);
var= varnum.mod(modulus) Modulus function

Identical to C++ % operator only for positive numbers and modulus

Negative denominators are considered as periodic with positiive numbers

Result is between [0, modulus) if modulus is positive

Result is between (modulus, 0] if modulus is negative (symmetric)

Throws: VarDivideByZero if modulus is zero.

Floating point works.

 let v1 = var(11).mod(5); // 1
 // or
 let v2 = mod(11, 5); // 1
 let v3 = mod(-11, 5); // 4
 let v4 = mod(11, -5); // -4
 let v5 = mod(-11, -5); // -1

I/O Conversion Codes

Usage Function Description
var= vardate.oconv_D(conversion) Date output: Convert internal date format to human readable date or calendar info in text format.

Returns: Human readable date or calendar info, or the original value unconverted if non-numeric.

Flags: See examples below.

Any multifield/multivalue structure is preserved.

 let v1 = 12345;
 assert( v1.oconv( "D"   ) == "18 OCT 2001"  ); // Default
 assert( v1.oconv( "D/"  ) == "10/18/2001"   ); // / separator
 assert( v1.oconv( "D-"  ) == "10-18-2001"   ); // - separator
 assert( v1.oconv( "D2"  ) == "18 OCT 01"    ); // 2 digit year
 assert( v1.oconv( "D/E" ) == "18/10/2001"   ); // International order with /
 assert( v1.oconv( "DS"  ) == "2001 OCT 18"  ); // ISO Year first
 assert( v1.oconv( "DS-" ) == "2001-10-18"   ); // ISO Year first with -
 assert( v1.oconv( "DM"  ) == "10"           ); // Month number
 assert( v1.oconv( "DMA" ) == "OCTOBER"      ); // Month name
 assert( v1.oconv( "DY"  ) == "2001"         ); // Year number
 assert( v1.oconv( "DY2" ) == "01"           ); // Year 2 digits
 assert( v1.oconv( "DD"  ) == "18"           ); // Day number in month (1-31)
 assert( v1.oconv( "DW"  ) == "4"            ); // Weekday number (1-7)
 assert( v1.oconv( "DWA" ) == "THURSDAY"     ); // Weekday name
 assert( v1.oconv( "DQ"  ) == "4"            ); // Quarter number
 assert( v1.oconv( "DJ"  ) == "291"          ); // Day number in year
 assert( v1.oconv( "DL"  ) == "31"           ); // Last day number of month (28-31)

 // Multifield/multivalue
 var v2 = "12345^12346]12347"_var;
 assert(v2.oconv("D") == "18 OCT 2001^19 OCT 2001]20 OCT 2001"_var);

  // or
  assert( oconv(v1, "D"   ) == "18 OCT 2001"  );
var= varstr.iconv_D(conversion) Date input: Convert human readable date to internal date format.

Returns: Internal date or "" if the input is an invalid date.

Internal date format is whole days since 1967-12-31 00:00:00 which is day 0.

Any multifield/multivalue structure is preserved.

 // International order "DE"
 assert(            oconv(19005, "DE") == "12 JAN 2020");
 assert(   "12/1/2020"_var.iconv("DE") == 19005);
 assert(   "12 1 2020"_var.iconv("DE") == 19005);
 assert(   "12-1-2020"_var.iconv("DE") == 19005);
 assert( "12 JAN 2020"_var.iconv("DE") == 19005);
 assert( "jan 12 2020"_var.iconv("DE") == 19005);

 // American order "D"
 assert(            oconv(19329, "D") == "01 DEC 2020");
 assert(   "12/1/2020"_var.iconv("D") == 19329);
 assert(  "DEC 1 2020"_var.iconv("D") == 19329);
 assert(  "1 dec 2020"_var.iconv("D") == 19329);

 // Reverse order
 assert(  "2020/12/1"_var.iconv("DE") == 19329);
 assert(   "2020-12-1"_var.iconv("D") == 19329);
 assert(  "2020 1 dec"_var.iconv("D") == 19329);

 //Invalid date
 assert(   "2/29/2021"_var.iconv("D") == "");
 assert(  "29/2/2021"_var.iconv("DE") == "");

 // or
 assert(iconv("12/1/2020"_var, "DE") == 19005);
var= vartime.oconv_MT(conversion) Time output: Convert internal time format to human readable time e.g. "10:30:59".

Returns: Human readable time or the original value unconverted if non-numeric.

Conversion code (e.g. "MTHS") is "MT" + flags ...

Flags:

"H" - Show AM/PM otherwise 24 hour clock is used.

"S" - Output seconds

"2" = Ignored (used in iconv)

":" - Any other flag is used as the separator character instead of ":"

Any multifield/multivalue structure is preserved.

 var v1 = 234800;
 assert( v1.oconv( "MT"   ) == "17:13"      ); // Default
 assert( v1.oconv( "MTH"  ) == "05:13PM"    ); // 'H' flag for AM/PM
 assert( v1.oconv( "MTS"  ) == "17:13:20"   ); // 'S' flag for seconds
 assert( v1.oconv( "MTHS" ) == "05:13:20PM" ); // Both flags

 var v2 = 0;
 assert( v2.oconv( "MT"   ) == "00:00"      );
 assert( v2.oconv( "MTH"  ) == "12:00AM"    );
 assert( v2.oconv( "MTS"  ) == "00:00:00"   );
 assert( v2.oconv( "MTHS" ) == "12:00:00AM" );

 // Multifield/multivalue
 var v3 = "234800^234860]234920"_var;
 assert(v3.oconv("MT") == "17:13^17:14]17:15"_var);

 // or
 assert( oconv(v1, "MT"   ) == "17:13"      );
var= varstr.iconv_MT(strict) Time input: Convert human readable time (e.g. "10:30:59") to internal time format.

Returns: Internal time or "" if the input is an invalid time.

Internal time format is whole seconds since midnight.

Accepts: Two or three groups of digits surrounded and separated by any non-digits character(s).

Any multifield/multivalue structure is preserved.

 assert(      "17:13"_var.iconv( "MT" ) == 61980);
 assert(    "05:13PM"_var.iconv( "MT" ) == 61980);
 assert(   "17:13:20"_var.iconv( "MT" ) == 62000);
 assert( "05:13:20PM"_var.iconv( "MT" ) == 62000);

 assert(      "00:00"_var.iconv( "MT" ) == 0);
 assert(    "12:00AM"_var.iconv( "MT" ) == 0);     // Midnight
 assert(    "12:00PM"_var.iconv( "MT" ) == 43200); // Noon
 assert(   "00:00:00"_var.iconv( "MT" ) == 0);
 assert( "12:00:00AM"_var.iconv( "MT" ) == 0);

 // Multifield/multivalue
 assert("17:13^05:13PM]17:13:20"_var.iconv("MT") == "61980^61980]62000"_var);

 // or
 assert(iconv("17:13", "MT") == 61980);
var= varnum.oconv_MD(conversion) Number output: Convert internal numbers to external text format after rounding and optional scaling.

Returns: A string or, if the value is not numeric, then no conversion is performed and the original value is returned.

Conversion code (e.g. "MD20") is "MD" or "MC", 1st digit, 2nd digit, flags ...


MD outputs like 123.45 (International)

MC outputs like 123,45 (European)


1st digit = Decimal places to display. Also decimal places to move if 2nd digit not present and no P flag present.

2nd digit = Optional decimal places to move left if P flag not present.


Flags:

"P" - Preserve decimal places. Same as 2nd digit = 0;

"Z" - Zero flag - return "" if zero.

"X" - No conversion - return as is.

"." or "," - Separate thousands depending on MD or MC.

"-" means suffix negatives with "-" and positives with " " (space).

"<" means wrap negatives in "<" and ">" characters.

"C" means suffix negatives with "CR" and positives or zero with "DB".

"D" means suffix negatives with "DB" and positives or zero with "CR".


Any multifield/multivalue structure is preserved.
 var v1 = -1234.567;
 assert( v1.oconv( "MD20"   ) ==  "-1234.57"   );
 assert( v1.oconv( "MD20,"  ) == "-1,234.57"   ); // , flag
 assert( v1.oconv( "MC20,"  ) == "-1.234,57"   ); // MC code
 assert( v1.oconv( "MD20,-" ) ==  "1,234.57-"  ); // - flag
 assert( v1.oconv( "MD20,<" ) == "<1,234.57>"  ); // < flag
 assert( v1.oconv( "MD20,C" ) ==  "1,234.57CR" ); // C flag
 assert( v1.oconv( "MD20,D" ) ==  "1,234.57DB" ); // D flag

 // Multifield/multivalue
 var v2 = "1.1^2.1]2.2"_var;
 assert( v2.oconv( "MD20"   ) == "1.10^2.10]2.20"_var);

 // or
 assert( oconv(v1, "MD20"   ) ==  "-1234.57"   );
var= var.oconv_LRC(format) Text justification: Left, right and center. Padding and truncating. See Procrustes.

e.g. "L#10", "R#10", "C#10"

Useful when outputting to terminal devices where spaces are used for alignment.

Multifield/multivalue structure is preserved.

ASCII only.

 assert(     "abcde"_var.oconv( "L#3" ) == "abc" ); // Truncating
 assert(     "abcde"_var.oconv( "R#3" ) == "cde" );
 assert(     "abcde"_var.oconv( "C#3" ) == "abc" );

 assert(     "ab"_var.oconv( "L#6" ) == "ab␣␣␣␣" ); // Padding
 assert(     "ab"_var.oconv( "R#6" ) == "␣␣␣␣ab" );
 assert(     "ab"_var.oconv( "C#6" ) == "␣␣ab␣␣" );

 assert(      var(42).oconv( "L(0)#5" ) == "42000" ); // Padding character (x)
 assert(      var(42).oconv( "R(0)#5" ) == "00042" );
 assert(      var(42).oconv( "C(0)#5" ) == "04200" );
 assert(      var(42).oconv( "C(0)#5" ) == "04200" );

 // Multifield/multivalue
 assert(      "f1^v1]v2"_var.oconv("L(_)#5") == "f1___^v1___]v2___"_var);

 // Fail for non-ASCII (Should be 5)
 assert(     "🐱"_var.oconv("L#5").textwidth() == 3);

 // or
 assert(     oconv("abcd", "L#3" ) == "abc" );
var= varstr.oconv_T(format) Text folding and justification.

e.g. T#20

Useful when outputting to terminal devices where spaces are used for alignment.

Splits text into multiple fixed length lines by inserting spaces and TM characters.

ASCII only.

 var v1 = "Have a nice day";
 assert(  v1.oconv("T#10") == "Have a␣␣␣␣|nice day␣␣"_var);
 // or
 assert( oconv(v1, "T#10") == "Have a␣␣␣␣|nice day␣␣"_var );
var= varstr.oconv_HEX(ioratio) Convert a string of bytes to a string of hexadecimal digits. The size of the output is precisely double that of the input.

Multifield/multivalue structure is not preserved. Field marks are converted to HEX as for all other bytes.

 assert(     "ab01"_var.oconv( "HEX" ) == "61" "62" "30" "31" );
 assert( "\xff\x00"_var.oconv( "HEX" ) == "FF" "00"           ); // Any bytes are ok.
 assert(        var(10).oconv( "HEX" ) == "31" "30"           ); // Uses ASCII string equivalent of 10 i.e. "10".
 assert(   "\u0393"_var.oconv( "HEX" ) == "CE" "93"           ); // Greek capital Gamma in utf8 bytes.
 assert(     "a^]b"_var.oconv( "HEX" ) == "61" "1E" "1D" "62" ); // Field and value marks.
 // or
 assert(      oconv("ab01"_var, "HEX") == "61" "62" "30" "31");
var= varstr.iconv_HEX(ioratio) Convert a string of hexadecimal digits to a string of bytes. After prefixing a "0" to an odd sized input, the size of the output is precisely half that of the input.

Reverse of oconv("HEX") above.

var= varnum.oconv_MX() Numeric hex format: Convert number to hexadecimal string

If the value is not numeric then no conversion is performed and the original value is returned.

 assert( var("255").oconv("MX") == "FF");
 // or
 assert( oconv(var("255"), "MX") == "FF");
var= varnum.oconv_MB() Numeric binary format: Convert number to strings of 1s and 0s

If the value is not numeric then no conversion is performed and the original value is returned.

 assert( var(255).oconv("MB") == 1111'1111);
 // or
 assert( oconv(var(255), "MB") == 1111'1111);
var= varstr.oconv_TX(conversion) Convert dynamic arrays to standard text format.

Useful for using text editors on dynamic arrays.

FMs -> NL after escaping any embedded NL

   // backslash in text remains backslash
   assert(var(_BS).oconv("TX") == _BS);

   // 1. Double escape any _BS "n" -> _BS _BS "n"
   assert(var(_BS "n").oconv("TX") == _BS _BS "n");

   // 2. Single escape any _NL -> _BS "n"
   assert(var(_NL).oconv("TX") == _BS "n");

   // 3. FMs -> _NL (⏎)
   assert("🌍^🌍"_var.oconv("TX") == "🌍" _NL "🌍");

   // 4. VMs -> _BS _NL (\⏎)
   assert("🌍]🌍"_var.oconv("TX") == "🌍" _BS _NL "🌍");

   // 5. SMs -> _BS _BS _NL (\\⏎)
   assert("🌍}🌍"_var.oconv("TX") == "🌍" _BS _BS _NL "🌍");

   // 6. TMs -> _BS _BS _BS _NL (\\\⏎)
   assert("🌍|🌍"_var.oconv("TX") == "🌍" _BS _BS _BS _NL "🌍");

   // 7. STs -> _BS _BS _BS _BS _NL (\\\\⏎)
   assert("🌍~🌍"_var.oconv("TX") == "🌍" _BS _BS _BS _BS _NL "🌍");
var= varstr.iconv_TX(conversion) Convert standard text format to dynamic array.

Reverse of oconv("TX") above.