Functions wikifmt: Difference between revisions

From NEOSYS Dev Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
==== Complete List of Functions ====
==== Complete List of Functions ====


Generated by cli/gendoc from var.h 08 FEB 2025 14:05:20


===== String Creation =====


{|class="wikitable"
<!-- highlight.js for c++ syntax highlighting -->
!Usage!!Function!!Description
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
|-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|var=||num.<em>round</em>(ndecimals = 0)||<em>Returns:</em> A string representation of a decimal number rounded to a desired number of decimal places</p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
<!-- done below <script>hljs.highlightAll();</script> -->
 
<style>
 
/* Change highlight.js comments from default grey to green */
.hljs-comment,
.hljs-quote {
color: #008000; /* This is green, you can adjust the shade as per your preference */
font-style: italic; /* Optional: You might want to keep comments italicized */
}
 
</style>
 
<script>
//// Extend C++ language definition
//const cppLanguage = hljs.getLanguage('cpp');
//if (cppLanguage) {
// // Adding custom keywords
// cppLanguage.keywords = {
// ...cppLanguage.keywords,
// keyword: cppLanguage.keywords.keyword + ' round chr textchr',
// // You can also add to other categories like 'literal', 'built_in', etc.
// };
// // Register the modified language
// hljs.registerLanguage('cpp', cppLanguage);
//}
 
// Initialize highlight.js
document.addEventListener('DOMContentLoaded', (event) => {
    hljs.highlightAll();
});
</script>
 
 
 
<!-- bootstrap css. Is this necessary? -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
 
<style>
 
body {
margin: 10px;
}
 
pre {
margin: 0px;
white-space: pre-wrap;
word-wrap: break-word;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
overflow-wrap: break-word;
overflow-x: auto;
}
 
table, th, td {
border: 1px solid #a2a9b1;
}
 
th {
background-color: #eaecf0;
font-weight: bold;
text-align: left;
padding: 8px;
}
 
td {
padding: 0.2em 0.4em;
vertical-align: top;
}
 
p {
  margin: 0.4em 0 0.5em 0;
}
 
.toc, .toccolours {
border: 1px solid #a2a9b1;
background-color: #f8f9fa;
padding: 5px;
font-size: 95%;
}
.toc {
display: table;
padding: 7px;
}
 
.wikitable {
background-color: #f8f9fa;
color: #202122;
margin: 1em 0;
border: 1px solid #a2a9b1;
border-collapse: collapse;
}
    img {
        border: 0;
        vertical-align: middle
    }
 
    hr {
        height: 1px;
        background-color: #a2a9b1;
        border: 0;
        margin: 0.2em 0
    }
 
    h1,h2,h3,h4,h5,h6 {
        color: #000;
        margin: 0;
        padding-top: 0.5em;
        padding-bottom: 0.17em;
        overflow: hidden
    }
 
    h1,h2 {
        margin-bottom: 0.6em;
        border-bottom: 1px solid #a2a9b1
    }
 
    h3,h4,h5 {
        margin-bottom: 0.3em
    }
 
    h1 {
        font-size: 188%;
        font-weight: normal
    }
 
    h2 {
        font-size: 150%;
        font-weight: normal
    }
 
    h3 {
        font-size: 128%
    }
 
    h4 {
        font-size: 116%
    }
 
    h5 {
        font-size: 108%
    }
 
    h6 {
        font-size: 100%
    }
 
    p {
        margin: 0.4em 0 0.5em 0
    }
 
    p img {
        margin: 0
    }
 
    ul {
        margin: 0.3em 0 0 1.6em;
        padding: 0
    }
 
    ol {
        margin: 0.3em 0 0 3.2em;
        padding: 0;
        list-style-image: none
    }
 
    li {
        margin-bottom: 0.1em
    }
 
    dt {
        font-weight: bold;
        margin-bottom: 0.1em
    }
 
    dl {
        margin-top: 0.2em;
        margin-bottom: 0.5em
    }
 
    dd {
        margin-left: 1.6em;
        margin-bottom: 0.1em
    }
 
.gendoc_function {
    color: #800;
    font-weight: 700;
}
 
</style>
 
 
<div class=toc>
<h4>Contents:</h4>
<ol>
<li><a href=#String_Creation>String Creation</a></li>
<li><a href=#String_Scanning>String Scanning</a></li>
<li><a href=#String_Conversion_-_Non-Mutating_-_Chainable>String Conversion - Non-Mutating - Chainable</a></li>
<li><a href=#String_Conversion_-_Mutating_-_Standalone_Commands>String Conversion - Mutating - Standalone Commands</a></li>
<li><a href=#I/O_Conversion>I/O Conversion</a></li>
<li><a href=#Dynamic_Array_Functions>Dynamic Array Functions</a></li>
<li><a href=#Dynamic_Array_Filters>Dynamic Array Filters</a></li>
<li><a href=#Dynamic_Array_Mutators_Standalone_Commands>Dynamic Array Mutators Standalone Commands</a></li>
<li><a href=#Dynamic_Array_Search>Dynamic Array Search</a></li>
<li><a href=#Database_Access>Database Access</a></li>
<li><a href=#Database_Management>Database Management</a></li>
<li><a href=#Database_File_I/O>Database File I/O</a></li>
<li><a href=#Database_Sort/Select>Database Sort/Select</a></li>
<li><a href=#OS_Time/Date>OS Time/Date</a></li>
<li><a href=#OS_File_I/O>OS File I/O</a></li>
<li><a href=#OS_Directories>OS Directories</a></li>
<li><a href=#OS_Shell/Environment>OS Shell/Environment</a></li>
<li><a href=#Output>Output</a></li>
<li><a href=#Input>Input</a></li>
<li><a href=#Math/Boolean>Math/Boolean</a></li>
 
</ol>
</div>
Generated by cli/gendoc from var.h 10 FEB 2025 18:41:41
 
<h5 id=String_Creation>String Creation</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>var=</td><td>num.<span class='gendoc_function'>round</span>(ndecimals = 0)</td><td><em>Returns:</em> A string representation of a decimal number rounded to a desired number of decimal places</p>
<em>Returns:</em> A var ASCII string with exact decimal places requested.</p>
<em>Returns:</em> A var ASCII string with exact decimal places requested.</p>
.5 always rounds away from zero.
.5 always rounds away from zero.
<syntaxhighlight lang="c++">
 
let v1 = var(0.295).round(2); // "0.30"
<pre><code class='hljs-ncdecl language-javascript'>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 18: Line 243:
var v3 = var(-0.295).round(2); // "-0.30"
var v3 = var(-0.295).round(2); // "-0.30"
// or
// or
var v4 = round(-1.295, 2); // "-1.30"</syntaxhighlight>
var v4 = round(-1.295, 2); // "-1.30"</code></pre>
|-
</td></tr>
|var=||var().<em>chr</em>(num)||<em>Returns:</em> A string containing a single char (byte) given an integer 0-255.</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>chr</span>(num)</td><td><em>Returns:</em> A string containing a single char (byte) given an integer 0-255.</p>
0-127 -> ASCII, 128-255 -> invalid UTF-8 so cannot be written to database or used various exodus string operations
0-127 -> ASCII, 128-255 -> invalid UTF-8 so cannot be written to database or used various exodus string operations
<syntaxhighlight lang="c++">
 
let v1 = var().chr(0x61); // "a"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var().chr(0x61); // "a"
// or
// or
let v2 = chr(0x61);</syntaxhighlight>
let v2 = chr(0x61);</code></pre>
|-
</td></tr>
|var=||var().<em>textchr</em>(num)||<em>Returns:</em> A string of a single unicode code point in utf8 encoding.</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>textchr</span>(num)</td><td><em>Returns:</em> A string of a single unicode code point in utf8 encoding.</p>
To get utf codepoints > 2^63 you must provide negative ints</p>
To get utf codepoints > 2^63 you must provide negative ints</p>
Not providing implicit constructor from var to unsigned int due to getting ambigious conversions</p>
Not providing implicit constructor from var to unsigned int due to getting ambigious conversions</p>
since int and unsigned int are parallel priority in c++ implicit conversions
since int and unsigned int are parallel priority in c++ implicit conversions
<syntaxhighlight lang="c++">
 
let v1 = var().textchr(171416); // "𩶘" // or "\xF0A9B698"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var().textchr(171416); // "𩶘" // or "\xF0A9B698"
// or
// or
let v2 = textchr(171416);</syntaxhighlight>
let v2 = textchr(171416);</code></pre>
|-
</td></tr>
|var=||var().<em>str</em>(num)||<em>Returns:</em> A string of repeating characters or strings
<tr><td>var=</td><td>var().<span class='gendoc_function'>str</span>(num)</td><td><em>Returns:</em> A string of repeating characters or strings
<syntaxhighlight lang="c++">
 
let v1 = "ab"_var.str(3); // "ababab"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "ab"_var.str(3); // "ababab"
// or
// or
let v2 = str("ab", 3);</syntaxhighlight>
let v2 = str("ab", 3);</code></pre>
|-
</td></tr>
|var=||num.<em>space</em>()||<em>Returns:</em> A string of space characters.
<tr><td>var=</td><td>num.<span class='gendoc_function'>space</span>()</td><td><em>Returns:</em> A string of space characters.
<syntaxhighlight lang="c++">
 
let v1 = var(3).space(); // "␣␣␣"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(3).space(); // "␣␣␣"
// or
// or
let v2 = space(3);</syntaxhighlight>
let v2 = space(3);</code></pre>
|-
</td></tr>
|var=||num.<em>numberinwords</em>(languagename_or_locale_id = "")||<em>Returns:</em> A string representing a given number written in words instead of digits.
<tr><td>var=</td><td>num.<span class='gendoc_function'>numberinwords</span>(languagename_or_locale_id = "")</td><td><em>Returns:</em> A string representing a given number written in words instead of digits.</p>
<syntaxhighlight lang="c++">
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"</syntaxhighlight>
<pre><code class='hljs-ncdecl language-javascript'>let softhyphen = "\xc2\xad";
|}
let v1 = var(123.45).numberinwords("de_DE").replace(softhyphen, " "); // "ein␣hundert␣drei␣und␣zwanzig␣Komma␣vier␣fünf"</code></pre>
===== String Scanning =====
</td></tr>
</table>
<h5 id=String_Scanning>String Scanning</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>seq</span>()</td><td><em>Returns:</em> The character number of the first char.


{|class="wikitable"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.seq(); // 0x61 // decimal 97
!Usage!!Function!!Description
|-
|var=||strvar.<em>seq</em>()||<em>Returns:</em> The character number of the first char.
<syntaxhighlight lang="c++">
let v1 = "abc"_var.seq(); // 0x61 // decimal 97
// or
// or
let v2 = seq("abc");</syntaxhighlight>
let v2 = seq("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>textseq</em>()||<em>Returns:</em> The Unicode character number of the first unicode code point.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>textseq</span>()</td><td><em>Returns:</em> The Unicode character number of the first unicode code point.
<syntaxhighlight lang="c++">
 
let v1 = "Γ"_var.textseq(); // 915 // U+0393: Greek Capital Letter Gamma (Unicode Character)
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "Γ"_var.textseq(); // 915 // U+0393: Greek Capital Letter Gamma (Unicode Character)
// or
// or
let v2 = textseq("Γ");</syntaxhighlight>
let v2 = textseq("Γ");</code></pre>
|-
</td></tr>
|var=||strvar.<em>len</em>()||<em>Returns:</em> The length of a string in number of chars
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>len</span>()</td><td><em>Returns:</em> The length of a string in number of chars
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.len(); // 3
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.len(); // 3
// or
// or
let v2 = len("abc");</syntaxhighlight>
let v2 = len("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>textwidth</em>()||<em>Returns:</em> The number of output columns.</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>textwidth</span>()</td><td><em>Returns:</em> The number of output columns.</p>
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</p>
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++">
 
let v1 = "🤡x🤡"_var.textwidth(); // 5
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "🤡x🤡"_var.textwidth(); // 5
// or
// or
let v2 = textwidth("🤡x🤡");</syntaxhighlight>
let v2 = textwidth("🤡x🤡");</code></pre>
|-
</td></tr>
|var=||strvar.<em>textlen</em>()||<em>Returns:</em> The number of Unicode code points
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>textlen</span>()</td><td><em>Returns:</em> The number of Unicode code points
<syntaxhighlight lang="c++">
 
let v1 = "Γιάννης"_var.textlen(); // 7
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "Γιάννης"_var.textlen(); // 7
// or
// or
let v2 = textlen("Γιάννης");</syntaxhighlight>
let v2 = textlen("Γιάννης");</code></pre>
|-
</td></tr>
|var=||strvar.<em>fcount</em>(sepstr)||<em>Returns:</em> The count of the number of fields separated by a given sepstr.</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>fcount</span>(sepstr)</td><td><em>Returns:</em> The count of the number of fields separated by a given sepstr.</p>
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++">
 
let v1 = "aa**cc"_var.fcount("*"); // 3
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "aa**cc"_var.fcount("*"); // 3
// or
// or
let v2 = fcount("aa**cc", "*");</syntaxhighlight>
let v2 = fcount("aa**cc", "*");</code></pre>
|-
</td></tr>
|var=||strvar.<em>count</em>(sepstr)||<em>Returns:</em> The count of the number of sepstr found.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>count</span>(sepstr)</td><td><em>Returns:</em> The count of the number of sepstr found.
<syntaxhighlight lang="c++">
 
let v1 = "aa**cc"_var.count("*"); // 2
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "aa**cc"_var.count("*"); // 2
// or
// or
let v2 = count("aa**cc", "*");</syntaxhighlight>
let v2 = count("aa**cc", "*");</code></pre>
|-
</td></tr>
|if||strvar.<em>starts</em>(prefix)||<em>Returns:</em> True if starts with prefix
<tr><td>if</td><td>strvar.<span class='gendoc_function'>starts</span>(prefix)</td><td><em>Returns:</em> True if starts with prefix
<syntaxhighlight lang="c++">
 
if ("abc"_var.starts("ab")) ... true
<pre><code class='hljs-ncdecl language-javascript'>if ("abc"_var.starts("ab")) ... true
// or
// or
if (starts("abc", "ab")) ... true</syntaxhighlight>
if (starts("abc", "ab")) ... true</code></pre>
|-
</td></tr>
|if||strvar.<em>ends</em>(suffix)||<em>Returns:</em> True if ends with suffix
<tr><td>if</td><td>strvar.<span class='gendoc_function'>ends</span>(suffix)</td><td><em>Returns:</em> True if ends with suffix
<syntaxhighlight lang="c++">
 
if ("abc"_var.ends("bc")) ... true
<pre><code class='hljs-ncdecl language-javascript'>if ("abc"_var.ends("bc")) ... true
// or
// or
if (ends("abc", "bc")) ... true</syntaxhighlight>
if (ends("abc", "bc")) ... true</code></pre>
|-
</td></tr>
|if||strvar.<em>contains</em>(substr)||<em>Returns:</em> True if starts, ends or contains substr
<tr><td>if</td><td>strvar.<span class='gendoc_function'>contains</span>(substr)</td><td><em>Returns:</em> True if starts, ends or contains substr
<syntaxhighlight lang="c++">
 
if ("abcd"_var.contains("bc")) ... true
<pre><code class='hljs-ncdecl language-javascript'>if ("abcd"_var.contains("bc")) ... true
// or
// or
if (contains("abcd", "bc")) ... true</syntaxhighlight>
if (contains("abcd", "bc")) ... true</code></pre>
|-
</td></tr>
|var=||strvar.<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>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>index</span>(substr, startchar1 = 1)</td><td><em>Returns:</em> The index (1 based position) of a given substr on or after a given starting char number if present</p>
<em>Returns:</em> 0 if not present.
<em>Returns:</em> 0 if not present.
<syntaxhighlight lang="c++">
 
let v1 = "abcd"_var.index("bc"); // 2
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.index("bc"); // 2
// or
// or
let v2 = index("abcd", "bc");</syntaxhighlight>
let v2 = index("abcd", "bc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>indexn</em>(substr, occurrence)||<em>Returns:</em> The index (1 based position) of the nth occurrence of a given substr if present</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>indexn</span>(substr, occurrence)</td><td><em>Returns:</em> The index (1 based position) of the nth occurrence of a given substr if present</p>
<em>Returns:</em> 0 if not present.
<em>Returns:</em> 0 if not present.
<syntaxhighlight lang="c++">
 
let v1 = "abcabc"_var.index("bc", 2); // 2
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcabc"_var.index("bc", 2); // 2
// or
// or
let v2 = index("abcabc", "bc", 2);</syntaxhighlight>
let v2 = index("abcabc", "bc", 2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>indexr</em>(substr, startchar1 = -1)||Reverse substr search.</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>indexr</span>(substr, startchar1 = -1)</td><td>Reverse substr search.</p>
<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</p>
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++">
 
let v1 = "abcabc"_var.indexr("bc"); // 5
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcabc"_var.indexr("bc"); // 5
// or
// or
let v2 = indexr("abcabc", "bc");</syntaxhighlight>
let v2 = indexr("abcabc", "bc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>match</em>(regex_str, regex_options = "")||<em>Returns:</em> All results of regex matching</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>match</span>(regex_str, regex_options = "")</td><td><em>Returns:</em> All results of regex matching</p>
Multiple matches are returns in fields. Groups are in values
Multiple matches are returned separated by FMs. Groups are in VMs.
<syntaxhighlight lang="c++">
 
let v1 = "abc1abc2"_var.match("BC(\\d)", "i"); // "bc1]1^bc2]2"_var
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
 
regex_options:</p>
regex_options:</p>
</p>
</p>
Line 169: Line 396:
f - First only. Only for replace() (not match() or search())</p>
f - First only. Only for replace() (not match() or search())</p>
</p>
</p>
w - Wildcard glob style (e.g. *.cfg) not regex style. Only for match() and search(). Not replace().
w - Wildcard glob style (e.g. *.cfg) not regex style. Only for match() and search(). Not replace().</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>match</span>(regex)</td><td>Ditto</td></tr>
|var=||strvar.<em>match</em>(regex)||Ditto
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>search</span>(regex_str, io startchar1, regex_options = "")</td><td>Search for first match of a regular expression starting at startchar1</p>
|-
|var=||strvar.<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>
Updates startchar1 ready to search for the next match</p>
regex_options as for match()
regex_options as for match()
<syntaxhighlight lang="c++">
 
var startchar1 = 1;
<pre><code class='hljs-ncdecl language-javascript'>var startchar1 = 1;
let v1 = "abc1abc2"_var.search("BC(\\d)", startchar1, "i"); // "bc1]1"_var // startchar1.outputl() -> 5 /// Ready for the next search
let v1 = "abc1abc2"_var.search("BC(\\d)", startchar1, "i"); // "bc1]1"_var // startchar1.outputl() -> 5 /// Ready for the next search
// or
// or
startchar1 = 1;
startchar1 = 1;
let v2 = search("abc1abc2", "BC(\\d)", startchar1, "i");</syntaxhighlight>
let v2 = search("abc1abc2", "BC(\\d)", startchar1, "i");</code></pre>
|-
</td></tr>
|var=||strvar.<em>search</em>(regex_str)||Ditto starting from first char
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>search</span>(regex_str)</td><td>Ditto starting from first char</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>search</span>(regex, io startchar1)</td><td>Ditto given a rex</td></tr>
|var=||strvar.<em>search</em>(regex, io startchar1)||Ditto given a rex
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>search</span>(regex)</td><td>Ditto starting from first char.</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>hash</span>(std::uint64_t modulus = 0)</td><td>Hash by default returns a 64 bit signed integer as a var.</p>
|var=||strvar.<em>search</em>(regex)||Ditto starting from first char.
|-
|var=||strvar.<em>hash</em>(std::uint64_t modulus = 0)||Hash by default returns a 64 bit signed integer as a var.</p>
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)</p>
MurmurHash3 is used.
MurmurHash3 is used.
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.hash(); assert(v1 == var(6'715'211'243'465'481'821));
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|}
</td></tr>
===== String Conversion - Non-Mutating - Chainable =====
</table>
<h5 id=String_Conversion_-_Non-Mutating_-_Chainable>String Conversion - Non-Mutating - Chainable</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>ucase</span>()</td><td>To upper case


{|class="wikitable"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"
!Usage!!Function!!Description
|-
|var=||strvar.<em>ucase</em>()||Upper case
<syntaxhighlight lang="c++">
let v1 = "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"
// or
// or
let v2 = ucase("Γιάννης");</syntaxhighlight>
let v2 = ucase("Γιάννης");</code></pre>
|-
</td></tr>
|var=||strvar.<em>lcase</em>()||Lower case
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>lcase</span>()</td><td>To lower case
<syntaxhighlight lang="c++">
 
let v1 = "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"
// or
// or
let v2 = lcase("ΓΙΆΝΝΗΣ");</syntaxhighlight>
let v2 = lcase("ΓΙΆΝΝΗΣ");</code></pre>
|-
</td></tr>
|var=||strvar.<em>tcase</em>()||Title case (first letters)
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>tcase</span>()</td><td>To title case (first letters are capitalised)
<syntaxhighlight lang="c++">
 
let v1 = "γιάννης"_var.tcase(); // "Γιάννης"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "γιάννης"_var.tcase(); // "Γιάννης"
// or
// or
let v2 = tcase("γιάννης");</syntaxhighlight>
let v2 = tcase("γιάννης");</code></pre>
|-
</td></tr>
|var=||strvar.<em>fcase</em>()||Fold case (lower case and remove accents for indexing)
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>fcase</span>()</td><td>To folded case (lower case and remove accents for indexing)</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>normalize</span>()</td><td>Normalises unicode code points sequences to their standardised NFC form making them binary comparable.</td></tr>
|var=||strvar.<em>normalize</em>()||Normalise Unicode to NFC to eliminate different code combinations of the same character
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>invert</span>()</td><td>Simple reversible disguising of text</p>
|-
invert(invert()) returns to original.</p>
|var=||strvar.<em>invert</em>()||Simple reversible disguising of text
Flips bit 8 of unicode code points. Note that ASCII bytes become multibyte UTF-8 so string sizes change.
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.invert(); // "\xC2" "\x9E" "\xC2" "\x9D" "\xC2" "\x9C"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.invert(); // "\xC2" "\x9E" "\xC2" "\x9D" "\xC2" "\x9C"
// or
// or
let v2 = invert("abc");</syntaxhighlight>
let v2 = invert("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>lower</em>()||Convert all FM to VM, VM to SM etc.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>lower</span>()</td><td>Convert all FM to VM, VM to SM etc.
<syntaxhighlight lang="c++">
 
let v1 = "a1^b2^c3"_var.lower(); // "a1]b2]c3"_var
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>raise</em>()||Convert all VM to FM, SM to VM etc.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>raise</span>()</td><td>Convert all VM to FM, SM to VM etc.
<syntaxhighlight lang="c++">
 
let v1 = "a1]b2]c3"_var.raise(); // "a1^b2^c3"_var
<pre><code class='hljs-ncdecl language-javascript'>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;</code></pre>
|-
</td></tr>
|var=||strvar.<em>crop</em>()||Remove any redundant FM, VM etc. characters (Trailing FM; VM before FM etc.)
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>crop</span>()</td><td>Remove any redundant FM, VM etc. characters (Trailing FM; VM before FM etc.)
<syntaxhighlight lang="c++">
 
let v1 = "a1^b2]]^c3^^"_var.crop(); // "a1^b2^c3"_var
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>quote</em>()||Wrap in double quotes
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>quote</span>()</td><td>Wrap in double quotes
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.quote(); // "\"abc\""
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.quote(); // "\"abc\""
// or
// or
let v2 = quote("abc");</syntaxhighlight>
let v2 = quote("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>squote</em>()||Wrap in single quotes
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>squote</span>()</td><td>Wrap in single quotes
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.squote(); // "'abc'"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.squote(); // "'abc'"
// or
// or
let v2 = squote("abc");</syntaxhighlight>
let v2 = squote("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>unquote</em>()||Remove one pair of double or single quotes
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>unquote</span>()</td><td>Remove one pair of double or single quotes
<syntaxhighlight lang="c++">
 
let v1 = "'abc'"_var.unquote(); // "abc"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "'abc'"_var.unquote(); // "abc"
// or
// or
let v2 = unquote("'abc'");</syntaxhighlight>
let v2 = unquote("'abc'");</code></pre>
|-
</td></tr>
|var=||strvar.<em>trim</em>(trimchars = " ")||Remove leading, trailing and excessive inner bytes
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>trim</span>(trimchars = " ")</td><td>Remove leading, trailing and excessive inner bytes
<syntaxhighlight lang="c++">
 
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trim(); // "a1␣b2␣c3"
<pre><code class='hljs-ncdecl language-javascript'>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␣␣");</code></pre>
|-
</td></tr>
|var=||strvar.<em>trimfirst</em>(trimchars = " ")||Ditto leading
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>trimfirst</span>(trimchars = " ")</td><td>Ditto leading
<syntaxhighlight lang="c++">
 
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimfirst(); // "a1␣␣b2␣c3␣␣"
<pre><code class='hljs-ncdecl language-javascript'>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␣␣");</code></pre>
|-
</td></tr>
|var=||strvar.<em>trimlast</em>(trimchars = " ")||Ditto trailing
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>trimlast</span>(trimchars = " ")</td><td>Ditto trailing
<syntaxhighlight lang="c++">
 
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimlast(); // "␣␣a1␣␣b2␣c3"
<pre><code class='hljs-ncdecl language-javascript'>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␣␣");</code></pre>
|-
</td></tr>
|var=||strvar.<em>trimboth</em>(trimchars = " ")||Ditto leading, trailing but not inner
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>trimboth</span>(trimchars = " ")</td><td>Ditto leading, trailing but not inner
<syntaxhighlight lang="c++">
 
let v1 = "␣␣a1␣␣b2␣c3␣␣"_var.trimboth(); // "a1␣␣b2␣c3"
<pre><code class='hljs-ncdecl language-javascript'>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␣␣");</code></pre>
|-
</td></tr>
|var=||strvar.<em>first</em>()||Extract first char or "" if empty
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>first</span>()</td><td>Extract first char or "" if empty
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.first(); // "a"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.first(); // "a"
// or
// or
let v2 = first("abc");</syntaxhighlight>
let v2 = first("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>last</em>()||Extract last char or "" if empty
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>last</span>()</td><td>Extract last char or "" if empty
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.last(); // "c"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.last(); // "c"
// or
// or
let v2 = last("abc");</syntaxhighlight>
let v2 = last("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>first</em>(std::size_t length)||Extract up to length leading chars
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>first</span>(std::size_t length)</td><td>Extract up to length leading chars
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.first(2); // "ab"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.first(2); // "ab"
// or
// or
let v2 = first("abc", 2);</syntaxhighlight>
let v2 = first("abc", 2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>last</em>(std::size_t length)||Extract up to length trailing chars
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>last</span>(std::size_t length)</td><td>Extract up to length trailing chars
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.last(2); // "bc"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.last(2); // "bc"
// or
// or
let v2 = last("abc", 2);</syntaxhighlight>
let v2 = last("abc", 2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>cut</em>(length)||Remove length leading chars
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>cut</span>(length)</td><td>Remove length leading chars
<syntaxhighlight lang="c++">
 
let v1 = "abcd"_var.cut(2); // "cd"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.cut(2); // "cd"
// or
// or
let v2 = cut("abcd", 2);</syntaxhighlight>
let v2 = cut("abcd", 2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>paste</em>(pos1, length, insertstr)||Insert text at char position overwriting length chars
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>paste</span>(pos1, length, insertstr)</td><td>Insert text at char position overwriting length chars
<syntaxhighlight lang="c++">
 
let v1 = "abcd"_var.paste(2, 2, "XYZ"); // "aXYZd"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||strvar.<em>paste</em>(pos1, insertstr)||Insert text at char position without overwriting any following characters
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>paste</span>(pos1, insertstr)</td><td>Insert text at char position without overwriting any following characters
<syntaxhighlight lang="c++">
 
let v1 = "abcd"_var.paste(2, "XYZ"); // "aXYZbcd"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.paste(2, "XYZ"); // "aXYZbcd"
// or
// or
let v2 = paste("abcd", 2, "XYZ");</syntaxhighlight>
let v2 = paste("abcd", 2, "XYZ");</code></pre>
|-
</td></tr>
|var=||strvar.<em>prefix</em>(insertstr)||Insert text at the beginning
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>prefix</span>(insertstr)</td><td>Insert text at the beginning
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.prefix("XYZ"); // "XYZabc"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.prefix("XYZ"); // "XYZabc"
// or
// or
let v2 = prefix("abc", "XYZ");</syntaxhighlight>
let v2 = prefix("abc", "XYZ");</code></pre>
|-
</td></tr>
|var=||strvar.<em>append</em>(appendable, ...)||Append text at the end
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>append</span>(appendable, ...)</td><td>Append text at the end
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.append(" is ", 10, " ok", '.'); // "abc is 10 ok."
<pre><code class='hljs-ncdecl language-javascript'>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", '.');</code></pre>
|-
</td></tr>
|var=||strvar.<em>pop</em>()||Remove one trailing char
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>pop</span>()</td><td>Remove one trailing char
<syntaxhighlight lang="c++">
 
let v1 = "abc"_var.pop(); // "ab"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.pop(); // "ab"
// or
// or
let v2 = pop("abc");</syntaxhighlight>
let v2 = pop("abc");</code></pre>
|-
</td></tr>
|var=||strvar.<em>field</em>(strx, fieldnx = 1, nfieldsx = 1)||Extract one or more consecutive fields given a delimiter char or substr.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>field</span>(strx, fieldnx = 1, nfieldsx = 1)</td><td>Extract one or more consecutive fields given a delimiter char or substr.
<syntaxhighlight lang="c++">
 
let v1 = "aa*bb*cc"_var.field("*", 2); // "bb"
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<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>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>field2</span>(separator, fieldno, nfields = 1)</td><td>field2 is a version that treats fieldn -1 as the last field, -2 the penultimate field etc. -</p>
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</p>
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++">
 
let v1 = "aa*bb*cc"_var.field2("*", -1); // "cc"
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>fieldstore</em>(separator, fieldno, nfields, replacement)||fieldstore() replaces n fields of subfield(s) in a string.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>fieldstore</span>(separator, fieldno, nfields, replacement)</td><td>fieldstore() replaces n fields of subfield(s) in a string.
<syntaxhighlight lang="c++">
 
let v1 = "aa*bb*cc*dd"_var.fieldstore("*", 2, 3, "X*Y"); // "aa*X*Y*"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
 
If nfields is 0 then insert fields before fieldno
If nfields is 0 then insert fields before fieldno
<syntaxhighlight lang="c++">
 
let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, 0, "X*Y"); // "a1*X*Y*b2*c3*d4"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
 
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++">
 
let v1 = "a1*b2*c3*d4"_var.fieldstore("*", 2, -3, "X*Y"); // "a1*X*Y"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||strvar.<em>substr</em>(pos1, length)||substr version 1. Extract length chars starting at pos1
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>substr</span>(pos1, length)</td><td>substr version 1. Extract length chars starting at pos1
<syntaxhighlight lang="c++">
 
let v1 = "abcd"_var.substr(2, 2); // "bc"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.substr(2, 2); // "bc"
// or
// or
let v2 = substr("abcd", 2, 2);</syntaxhighlight>
let v2 = substr("abcd", 2, 2);</code></pre>
 
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++">
 
let v1 = "abcd"_var.substr(3, -2); // "cb"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.substr(3, -2); // "cb"
// or
// or
let v2 = substr("abcd", 3, -2);</syntaxhighlight>
let v2 = substr("abcd", 3, -2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>b</em>(pos1, length)||Same as substr version 1.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>b</span>(pos1, length)</td><td>Same as substr version 1.</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>substr</span>(pos1)</td><td>substr version 2. Extract all chars from pos1 up to the end
|var=||strvar.<em>substr</em>(pos1)||substr version 2. Extract all chars from pos1 up to the end
 
<syntaxhighlight lang="c++">
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>b</em>(pos1)||Same as substr version 2.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>b</span>(pos1)</td><td>Same as substr version 2.</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>substr</span>(pos1, delimiterchars, io pos2)</td><td>substr version 3.</p>
|var=||strvar.<em>substr</em>(pos1, delimiterchars, io pos2)||substr version 3.</p>
Extract a substr starting from pos1 up to any one of some given delimiter chars</p>
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>
Also returns in pos2 the pos of the following delimiter or one past the end of the string if not found.</p>
Add 1 to pos2 start the next search if continuing.
Add 1 to pos2 start the next search if continuing.
<syntaxhighlight lang="c++">
 
var pos1a = 4, pos2a;
<pre><code class='hljs-ncdecl language-javascript'>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
var pos1b = 4, pos2b;
var pos1b = 4, pos2b;
let v2 = substr("aa,bb,cc", pos1b, ",", pos2b);</syntaxhighlight>
let v2 = substr("aa,bb,cc", pos1b, ",", pos2b);</code></pre>
|-
</td></tr>
|var=||strvar.<em>b</em>(pos1, delimiterchars, io pos2)||Alias of substr version 3.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>b</span>(pos1, delimiterchars, io pos2)</td><td>Alias of substr version 3.</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>substr2</span>(io pos1, out delimiterno)</td><td>substr version 4.</p>
|var=||strvar.<em>substr2</em>(io pos1, out delimiterno)||substr version 4.</p>
<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.</p>
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++">
 
var pos1a = 4, delim1;
<pre><code class='hljs-ncdecl language-javascript'>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
var pos1b = 4, delim2;
var pos1b = 4, delim2;
let v2 = substr2("aa^bb^cc"_var, pos1b, delim2);</syntaxhighlight>
let v2 = substr2("aa^bb^cc"_var, pos1b, delim2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>b2</em>(io pos1, out delimiterno)||Alias of substr version 4
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>b2</span>(io pos1, out delimiterno)</td><td>Alias of substr version 4</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>convert</span>(fromchars, tochars)</td><td>Convert chars to other chars one for one or delete where tochars is shorter.
|var=||strvar.<em>convert</em>(fromchars, tochars)||Convert chars to other chars one for one or delete where tochars is shorter.
 
<syntaxhighlight lang="c++">
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||strvar.<em>textconvert</em>(fromchars, tochars)||Ditto for Unicode code points.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>textconvert</span>(fromchars, tochars)</td><td>Ditto for Unicode code points.
<syntaxhighlight lang="c++">
 
let v1 = "a🤡b😀c🌍d"_var.textconvert("🤡😀", "👋"); // "a👋bc🌍d"
<pre><code class='hljs-ncdecl language-javascript'>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", "🤡😀", "👋");</code></pre>
|-
</td></tr>
|var=||strvar.<em>replace</em>(fromstr, tostr)||Replace all occurrences of a substr with another. Case sensitive
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>replace</span>(fromstr, tostr)</td><td>Replace all occurrences of a substr with another. Case sensitive
<syntaxhighlight lang="c++">
 
let v1 = "Abc.Abc"_var.replace("bc", "X"); // "AX.AX"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||strvar.<em>replace</em>(regex, tostr)||Replace substring(s) using a regular expression.</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>replace</span>(regex, tostr)</td><td>Replace substring(s) using a regular expression.</p>
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++">
 
let v1 = "A a B b"_var.replace("[A-Z]"_rex, "'$0'"); // "'A' a 'B' b"
<pre><code class='hljs-ncdecl language-javascript'>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'");</code></pre>
|-
</td></tr>
|var=||strvar.<em>unique</em>()||Remove duplicate fields in an FM or VM etc. separated list
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>unique</span>()</td><td>Remove duplicate fields in an FM or VM etc. separated list
<syntaxhighlight lang="c++">
 
let v1 = "a1^b2^a1^c2"_var.unique(); // "a1^b2^c2"_var
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>sort</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in ascending order</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>sort</span>(sepchar = FM)</td><td>Reorder fields in an FM or VM etc. separated list in ascending order</p>
Numerical:
Numerical:
<syntaxhighlight lang="c++">
 
let v1 = "20^10^2^1^1.1"_var.sort(); // "1^1.1^2^10^20"_var
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
 
Alphabetical:
Alphabetical:
<syntaxhighlight lang="c++">
 
let v1 = "b1^a1^c20^c10^c2^c1^b2"_var.sort(); // "a1^b1^b2^c1^c10^c2^c20"_var
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>reverse</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in descending order
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>reverse</span>(sepchar = FM)</td><td>Reorder fields in an FM or VM etc. separated list in descending order
<syntaxhighlight lang="c++">
 
let v1 = "20^10^2^1^1.1"_var.reverse(); // "1.1^1^2^10^20"_var
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>shuffle</em>(sepchar = FM)||Randomise the order of fields in an FM, VM separated list
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>shuffle</span>(sepchar = FM)</td><td>Randomise the order of fields in an FM, VM separated list
<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())
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>parse</em>(char sepchar = ' ')||Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes &bsol;" &bsol;'
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>parse</span>(char sepchar = ' ')</td><td>Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes &bsol;" &bsol;'
<syntaxhighlight lang="c++">
 
let v1 = "abc,\"def,\"123\" fgh\",12.34"_var.parse(','); // "abc^\"def,\"123\" fgh\"^12.34"_var
<pre><code class='hljs-ncdecl language-javascript'>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", ',');</code></pre>
|}
</td></tr>
===== String Conversion - Mutating - Standalone Commands =====
</table>
<h5 id=String_Conversion_-_Mutating_-_Standalone_Commands>String Conversion - Mutating - Standalone Commands</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>ucaser</span>()</td><td>Upper case</p>
|cmd||strvar.<em>ucaser</em>()||Upper case</p>
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++">
 
var v1 = "abc";
<pre><code class='hljs-ncdecl language-javascript'>var v1 = "abc";
v1.ucaser(); // "ABC"
v1.ucaser(); // "ABC"
// or
// or
ucaser(v1);</syntaxhighlight>
ucaser(v1);</code></pre>
|-
</td></tr>
|cmd||strvar.<em>lcaser</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>lcaser</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>tcaser</span>()</td><td></td></tr>
|cmd||strvar.<em>tcaser</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>fcaser</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>normalizer</span>()</td><td></td></tr>
|cmd||strvar.<em>fcaser</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>inverter</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>quoter</span>()</td><td></td></tr>
|cmd||strvar.<em>normalizer</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>squoter</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>unquoter</span>()</td><td></td></tr>
|cmd||strvar.<em>inverter</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>lowerer</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>raiser</span>()</td><td></td></tr>
|cmd||strvar.<em>quoter</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>cropper</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>trimmer</span>(trimchars = " ")</td><td></td></tr>
|cmd||strvar.<em>squoter</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>trimmerfirst</span>(trimchars = " ")</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>trimmerlast</span>(trimchars = " ")</td><td></td></tr>
|cmd||strvar.<em>unquoter</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>trimmerboth</span>(trimchars = " ")</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>firster</span>()</td><td></td></tr>
|cmd||strvar.<em>lowerer</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>laster</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>firster</span>(std::size_t length)</td><td></td></tr>
|cmd||strvar.<em>raiser</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>laster</span>(std::size_t length)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>cutter</span>(length)</td><td></td></tr>
|cmd||strvar.<em>cropper</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>paster</span>(pos1, length, insertstr)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>paster</span>(pos1, insertstr)</td><td></td></tr>
|cmd||strvar.<em>trimmer</em>(trimchars = " ")||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>prefixer</span>(insertstr)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>appender</span>(appendable, ...)</td><td></td></tr>
|cmd||strvar.<em>trimmerfirst</em>(trimchars = " ")||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>popper</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>fieldstorer</span>(sepchar, fieldno, nfields, replacement)</td><td></td></tr>
|cmd||strvar.<em>trimmerlast</em>(trimchars = " ")||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>substrer</span>(pos1, length)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>substrer</span>(pos1)</td><td></td></tr>
|cmd||strvar.<em>trimmerboth</em>(trimchars = " ")||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>converter</span>(fromchars, tochars)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>textconverter</span>(fromchars, tochars)</td><td></td></tr>
|cmd||strvar.<em>firster</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>replacer</span>(regex, tostr)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>replacer</span>(fromstr, tostr)</td><td></td></tr>
|cmd||strvar.<em>laster</em>()||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>uniquer</span>()</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>sorter</span>(sepchar = FM)</td><td></td></tr>
|cmd||strvar.<em>firster</em>(std::size_t length)||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>reverser</span>(sepchar = FM)</td><td></td></tr>
|-
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>shuffler</span>(sepchar = FM)</td><td></td></tr>
|cmd||strvar.<em>laster</em>(std::size_t length)||
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>parser</span>(char sepchar = ' ')</td><td></td></tr>
|-
</table>
|cmd||strvar.<em>cutter</em>(length)||
<h5 id=I/O_Conversion>I/O Conversion</h5>
|-
|cmd||strvar.<em>paster</em>(pos1, length, insertstr)||
|-
|cmd||strvar.<em>paster</em>(pos1, insertstr)||
|-
|cmd||strvar.<em>prefixer</em>(insertstr)||
|-
|cmd||strvar.<em>appender</em>(appendable, ...)||
|-
|cmd||strvar.<em>popper</em>()||
|-
|cmd||strvar.<em>fieldstorer</em>(sepchar, fieldno, nfields, replacement)||
|-
|cmd||strvar.<em>substrer</em>(pos1, length)||
|-
|cmd||strvar.<em>substrer</em>(pos1)||
|-
|cmd||strvar.<em>converter</em>(fromchars, tochars)||
|-
|cmd||strvar.<em>textconverter</em>(fromchars, tochars)||
|-
|cmd||strvar.<em>replacer</em>(regex, tostr)||
|-
|cmd||strvar.<em>replacer</em>(fromstr, tostr)||
|-
|cmd||strvar.<em>uniquer</em>()||
|-
|cmd||strvar.<em>sorter</em>(sepchar = FM)||
|-
|cmd||strvar.<em>reverser</em>(sepchar = FM)||
|-
|cmd||strvar.<em>shuffler</em>(sepchar = FM)||
|-
|cmd||strvar.<em>parser</em>(char sepchar = ' ')||
|}
===== I/O Conversion =====


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>var.<span class='gendoc_function'>oconv</span>(convstr)</td><td>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</p>
If the internal data is invalid and cannot be converted then most conversions return the ORIGINAL data unconverted</p>
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>
Throws a runtime error VarNotImplemented if convstr is invalid</p>
See [[#ICONV/OCONV PATTERNS]]
See [[#ICONV/OCONV PATTERNS]]
<syntaxhighlight lang="c++">
 
let v1 = var(30123).oconv("D/E"); // "21/06/2050"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||var.<em>iconv</em>(convstr)||Converts external data to internal format according to a given conversion code or pattern</p>
<tr><td>var=</td><td>var.<span class='gendoc_function'>iconv</span>(convstr)</td><td>Converts external data to internal format according to a given conversion code or pattern</p>
If the external data is invalid and cannot be converted then most conversions return the EMPTY STRING ""</p>
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>
Throws a runtime error VarNotImplemented if convstr is invalid</p>
See [[#ICONV/OCONV PATTERNS]]
See [[#ICONV/OCONV PATTERNS]]
<syntaxhighlight lang="c++">
 
let v1 = "21 JUN 2050"_var.iconv("D/E"); // 30123
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||var.<em>format</em>(fmt_str, args, ...)||Classic format function in printf style</p>
<tr><td>var=</td><td>var.<span class='gendoc_function'>format</span>(fmt_str, args, ...)</td><td>Classic format function in printf style</p>
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}</p>
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++">
 
let v1 = var(12.345).format("'{:_>8.2f}'"); // "'___12.35'"
<pre><code class='hljs-ncdecl language-javascript'>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
var v3 = format("'{:_>8.2f}'", var(12.345)); // "'___12.35'"
var v3 = format("'{:_>8.2f}'", var(12.345)); // "'___12.35'"
var v4 = format("'{::MD20P|R(_)#8}'", var(12.345));</syntaxhighlight>
var v4 = format("'{::MD20P|R(_)#8}'", var(12.345));</code></pre>
|-
</td></tr>
|var=||strvar.<em>from_codepage</em>(codepage)||Converts from codepage encoded text to UTF-8 encoded text</p>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>from_codepage</span>(codepage)</td><td>Converts from codepage encoded text to UTF-8 encoded text</p>
e.g. Codepage "CP1124" (Ukrainian).</p>
e.g. Codepage "CP1124" (Ukrainian).</p>
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++">
 
let v1 = "\xa4"_var.from_codepage("CP1124"); // "Є"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "\xa4"_var.from_codepage("CP1124"); // "Є"
// or
// or
let v2 = from_codepage("\xa4", "CP1124");
let v2 = from_codepage("\xa4", "CP1124");
// U+0404 Cyrillic Capital Letter Ukrainian Ie Unicode Character</syntaxhighlight>
// U+0404 Cyrillic Capital Letter Ukrainian Ie Unicode Character</code></pre>
|-
</td></tr>
|var=||strvar.<em>to_codepage</em>(codepage)||Converts to codepage encoded text from UTF-8 encoded text
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>to_codepage</span>(codepage)</td><td>Converts to codepage encoded text from UTF-8 encoded text
<syntaxhighlight lang="c++">
 
let v1 = "Є"_var.to_codepage("CP1124").oconv("HEX"); // "A4"
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|}
</td></tr>
===== Dynamic Array Functions =====
</table>
<h5 id=Dynamic_Array_Functions>Dynamic Array Functions</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>f</span>(fieldno, valueno = 0, subvalueno = 0)</td><td>f() is a highly abbreviated alias for the PICK OS field/value/subvalue extract() function.</p>
|var=||strvar.<em>f</em>(fieldno, valueno = 0, subvalueno = 0)||f() is a highly abbreviated alias for the PICK OS field/value/subvalue extract() function.</p>
"f()" can be thought of as "field" although the function can extract values and subvalues as well.</p>
"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>
The convenient PICK OS angle bracket syntax for field extraction (e.g. xxx<20>) is not available in C++.</p>
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++">
 
let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
let v2 = v1.f(2, 2); // "f2v2"</syntaxhighlight>
let v2 = v1.f(2, 2); // "f2v2"</code></pre>
|-
</td></tr>
|var=||strvar.<em>extract</em>(fieldno, valueno = 0, subvalueno = 0)||Extract a specific field, value or subvalue from a dynamic array.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>extract</span>(fieldno, valueno = 0, subvalueno = 0)</td><td>Extract a specific field, value or subvalue from a dynamic array.
<syntaxhighlight lang="c++">
 
let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
let v2 = v1.extract(2, 2); // "f2v2"
let v2 = v1.extract(2, 2); // "f2v2"
//
//
// For brevity the function alias "f()" (standing for "field") is normally used instead of "extract()" as follows:
// For brevity the function alias "f()" (standing for "field") is normally used instead of "extract()" as follows:
var v3 = v1.f(2, 2);</syntaxhighlight>
var v3 = v1.f(2, 2);</code></pre>
|-
</td></tr>
|var=||strvar.<em>pickreplace</em>(fieldno, valueno, subvalueno, replacement)||Same as var.r() function but returns a new string instead of updating a variable in place.<br>Rarely used.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>pickreplace</span>(fieldno, valueno, subvalueno, replacement)</td><td>Same as var.r() function but returns a new string instead of updating a variable in place.<br>Rarely used.</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>pickreplace</span>(fieldno, valueno, replacement)</td><td>Ditto for a specific multivalue</td></tr>
|var=||strvar.<em>pickreplace</em>(fieldno, valueno, replacement)||Ditto for a specific multivalue
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>pickreplace</span>(fieldno, replacement)</td><td>Ditto for a specific field</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>insert</span>(fieldno, valueno, subvalueno, insertion)</td><td>Same as var.inserter() function but returns a new string instead of updating a variable in place.</td></tr>
|var=||strvar.<em>pickreplace</em>(fieldno, replacement)||Ditto for a specific field
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>insert</span>(fieldno, valueno, insertion)</td><td>Ditto for a specific multivalue</td></tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>insert</span>(fieldno, insertion)</td><td>Ditto for a specific field</td></tr>
|var=||strvar.<em>insert</em>(fieldno, valueno, subvalueno, insertion)||Same as var.inserter() function but returns a new string instead of updating a variable in place.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>remove</span>(fieldno, valueno = 0, subvalueno = 0)</td><td>Same as var.remover() function but returns a new string instead of updating a variable in place.</p>
|-
"remove" was called "delete" in Pick OS.</td></tr>
|var=||strvar.<em>insert</em>(fieldno, valueno, insertion)||Ditto for a specific multivalue
</table>
|-
<h5 id=Dynamic_Array_Filters>Dynamic Array Filters</h5>
|var=||strvar.<em>insert</em>(fieldno, insertion)||Ditto for a specific field
|-
|var=||strvar.<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>
"remove" was called "delete" in Pick OS.
|}
===== Dynamic Array Filters =====


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>sum</span>()</td><td>Sum up multiple values into one higher level
|var=||strvar.<em>sum</em>()||Sum up multiple values into one higher level
 
<syntaxhighlight lang="c++">
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>sumall</em>()||Sum up all levels into a single figure
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>sumall</span>()</td><td>Sum up all levels into a single figure
<syntaxhighlight lang="c++">
 
let v1 = "1]2]3^4]5]6"_var.sumall(); // 21
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|var=||strvar.<em>sum</em>(sepchar)||Ditto allowing commas etc.
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>sum</span>(sepchar)</td><td>Ditto allowing commas etc.
<syntaxhighlight lang="c++">
 
let v1 = "10,20,30"_var.sum(","); // 60
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "10,20,30"_var.sum(","); // 60
// or
// or
let v2 = sum("10,20,30", ",");</syntaxhighlight>
let v2 = sum("10,20,30", ",");</code></pre>
|-
</td></tr>
|var=||strvar.<em>mv</em>(opcode, var2)||Binary ops (+, -, *, /) in parallel on multiple values
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>mv</span>(opcode, var2)</td><td>Binary ops (+, -, *, /) in parallel on multiple values
<syntaxhighlight lang="c++">
 
let v1 = "10]20]30"_var.mv("+","2]3]4"_var); // "12]23]34"_var</syntaxhighlight>
<pre><code class='hljs-ncdecl language-javascript'>let v1 = "10]20]30"_var.mv("+","2]3]4"_var); // "12]23]34"_var</code></pre>
|}
</td></tr>
===== Dynamic Array Mutators Standalone Commands =====
</table>
<h5 id=Dynamic_Array_Mutators_Standalone_Commands>Dynamic Array Mutators Standalone Commands</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>r</span>(fieldno, replacement)</td><td>Replaces a specific field in a dynamic array
 
<pre><code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, "X"); // "f1^X^f3"_var</code></pre>
</td></tr>
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>r</span>(fieldno, valueno, replacement)</td><td>Ditto for specific value in a specific field.
 
<pre><code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, 2, "X"); // "f1^v1]X^f3"_var</code></pre>
</td></tr>
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>r</span>(fieldno, valueno, subvalueno, replacement)</td><td>Ditto for a specific subvalue in a specific value of a specific field


{|class="wikitable"
<pre><code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
!Usage!!Function!!Description
v1.r(2, 2, 2, "X"); // "f1^v1]v2}X}s3^f3"_var</code></pre>
|-
</td></tr>
|cmd||strvar.<em>r</em>(fieldno, replacement)||Replaces a specific field in a dynamic array
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>inserter</span>(fieldno, insertion)</td><td>Insert a specific field in a dynamic array, moving all other fields up.
<syntaxhighlight lang="c++">
 
var v1 = "f1^v1]v2}s2}s3^f3"_var;
<pre><code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, "X"); // "f1^X^f3"_var</syntaxhighlight>
|-
|cmd||strvar.<em>r</em>(fieldno, valueno, replacement)||Ditto for specific value in a specific field.
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, 2, "X"); // "f1^v1]X^f3"_var</syntaxhighlight>
|-
|cmd||strvar.<em>r</em>(fieldno, valueno, subvalueno, replacement)||Ditto for a specific subvalue in a specific value of a specific field
<syntaxhighlight lang="c++">
var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, 2, 2, "X"); // "f1^v1]v2}X}s3^f3"_var</syntaxhighlight>
|-
|cmd||strvar.<em>inserter</em>(fieldno, insertion)||Insert a specific field in a dynamic array, moving all other fields up.
<syntaxhighlight lang="c++">
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
inserter(v1, 2, "X");</syntaxhighlight>
inserter(v1, 2, "X");</code></pre>
|-
</td></tr>
|cmd||strvar.<em>inserter</em>(fieldno, valueno, insertion)||Ditto for a specific value in a specific field, moving all other values up.
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>inserter</span>(fieldno, valueno, insertion)</td><td>Ditto for a specific value in a specific field, moving all other values up.
<syntaxhighlight lang="c++">
 
var v1 = "f1^v1]v2}s2}s3^f3"_var;
<pre><code class='hljs-ncdecl language-javascript'>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
inserter(v1, 2, 2, "X");</syntaxhighlight>
inserter(v1, 2, 2, "X");</code></pre>
|-
</td></tr>
|cmd||strvar.<em>inserter</em>(fieldno, valueno, subvalueno, insertion)||Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>inserter</span>(fieldno, valueno, subvalueno, insertion)</td><td>Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
<syntaxhighlight lang="c++">
 
var v1 = "f1^v1]v2}s2}s3^f3"_var;
<pre><code class='hljs-ncdecl language-javascript'>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
v1.inserter(2, 2, 2, "X");</syntaxhighlight>
v1.inserter(2, 2, 2, "X");</code></pre>
|-
</td></tr>
|cmd||strvar.<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.
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>remover</span>(fieldno, valueno = 0, subvalueno = 0)</td><td>Remove a specific field (or value, or subvalue) from a dynamic array, moving all other fields (or values, or subvalues) down.
<syntaxhighlight lang="c++">
 
var v1 = "f1^v1]v2}s2}s3^f3"_var;
<pre><code class='hljs-ncdecl language-javascript'>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
remover(v1, 2, 2);</syntaxhighlight>
remover(v1, 2, 2);</code></pre>
|}
</td></tr>
===== Dynamic Array Search =====
</table>
<h5 id=Dynamic_Array_Search>Dynamic Array Search</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>locate</span>(target)</td><td>locate() with only the target substr argument provided searches unordered values separated by any of the field mark chars.</p>
|if||strvar.<em>locate</em>(target)||locate() with only the target substr argument provided searches unordered values separated by VM chars.</p>
<em>Returns:</em> The field, value, subvalue etc. number if found or 0 if not.
<em>Returns:</em> True if found and false if not.
 
<syntaxhighlight lang="c++">
<pre><code class='hljs-ncdecl language-javascript'>if ("UK^US^UA"_var.locate("US")) ... ok // 2
if ("UK]US]UA"_var.locate("US")) ... ok
// or
// or
if (locate("US", "UK]US]UA"_var)) ... ok</syntaxhighlight>
if (locate("US", "UK^US^UA"_var)) ... ok</code></pre>
|-
</td></tr>
|if||strvar.<em>locate</em>(target, out valueno)||locate() with only the target substr and valueno arguments provided searches unordered values separated by VM chars.</p>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locate</span>(target, out valueno)</td><td>locate() with only the target substr provided and setting returned searches unordered values separated by any type of field mark chars.</p>
<em>Returns:</em> True if found and with the value number in valueno.</p>
<em>Returns:</em> True if found</p>
<em>Returns:</em> False if not found and with the max value number + 1 in setting. Suitable for additiom of new values
Setting: Field, value, subvalue etc. number if found or the max number + 1 if not. Suitable for additiom of new values
<syntaxhighlight lang="c++">
 
var valueno;
<pre><code class='hljs-ncdecl language-javascript'>var setting;
if ("UK]US]UA"_var.locate("US", valueno)) ... ok // valueno -> 2</syntaxhighlight>
if ("UK]US]UA"_var.locate("US", setting)) ... ok // setting -> 2
|-
// or
|if||strvar.<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 (locate("US", "UK]US]UA"_var, setting)) ... ok</code></pre>
</td></tr>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locate</span>(target, out setting, fieldno, valueno = 0)</td><td>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>
<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.</p>
<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++">
 
var setting;
<pre><code class='hljs-ncdecl language-javascript'>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</code></pre>
|-
</td></tr>
|if||strvar.<em>locateby</em>(ordercode, target, out valueno)||locateby() without fieldno or valueno arguments searches ordered values separated by VM chars.</p>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locateby</span>(ordercode, target, out valueno)</td><td>locateby() without fieldno or valueno arguments searches ordered values separated by VM chars.</p>
The order code can be AL, DL, AR, DR meaning Ascending Left, Descending Right, Ascending Right, Ascending Left.</p>
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>
Left is used to indicate alphabetic order where 10 < 2.</p>
Line 766: Line 946:
<em>Returns:</em> True if found.</p>
<em>Returns:</em> True if found.</p>
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++">
 
var valueno; if ("aaa]bbb]ccc"_var.locateby("AL", "bb", valueno)) ... // valueno -> 2 // returns false and valueno = where it could be correctly inserted.</syntaxhighlight>
<pre><code class='hljs-ncdecl language-javascript'>var valueno; if ("aaa]bbb]ccc"_var.locateby("AL", "bb", valueno)) ... // valueno -> 2 // returns false and valueno = where it could be correctly inserted.</code></pre>
|-
</td></tr>
|if||strvar.<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.
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locateby</span>(ordercode, target, out setting, fieldno, valueno = 0)</td><td>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++">
 
var setting;
<pre><code class='hljs-ncdecl language-javascript'>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.</code></pre>
|-
</td></tr>
|if||strvar.<em>locateusing</em>(usingchar, target)||locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locateusing</span>(usingchar, target)</td><td>locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
<syntaxhighlight lang="c++">
 
if ("AB,EF,CD"_var.locateusing(",", "EF")) ... ok</syntaxhighlight>
<pre><code class='hljs-ncdecl language-javascript'>if ("AB,EF,CD"_var.locateusing(",", "EF")) ... ok</code></pre>
|-
</td></tr>
|if||strvar.<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>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locateusing</span>(usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)</td><td>locate() the target in a specific field, value or subvalue using a specified delimiter and unordered data</p>
<em>Returns:</em> True If found and returns in setting the number of the delimited field found.</p>
<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> False if not found and returns in setting the maximum number of delimited fields + 1 if not found.</p>
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++">
var setting;
if ("f1^f2^f3c1,f3c2,f3c3^f4"_var.locateusing(",", "f3c2", setting, 3)) ... ok // setting -> 2 // returns true</syntaxhighlight>
|-
|if||strvar.<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>
<em>Returns:</em> True if found.
|}
===== Database Access =====


{|class="wikitable"
<pre><code class='hljs-ncdecl language-javascript'>var setting;
!Usage!!Function!!Description
if ("f1^f2^f3c1,f3c2,f3c3^f4"_var.locateusing(",", "f3c2", setting, 3)) ... ok // setting -> 2 // returns true</code></pre>
|-
</td></tr>
|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>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>locatebyusing</span>(ordercode, usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)</td><td>locatebyusing() supports all the above features in a single function.</p>
<em>Returns:</em> True if found.</td></tr>
</table>
<h5 id=Database_Access>Database Access</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>if</td><td>conn.<span class='gendoc_function'>connect</span>(conninfo = "")</td><td>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>
The db connection string (conninfo) parameters are merged from the following places in descending priority.</p>
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>
1. Provided in connect()'s conninfo argument. See 4. for the complete list of parameters.</p>
Line 801: Line 980:
4. The default conninfo is "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10"</p>
4. The default conninfo is "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10"</p>
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++">
 
let conninfo = "dbname=exodus user=exodus password=somesillysecret";
<pre><code class='hljs-ncdecl language-javascript'>let conninfo = "dbname=exodus user=exodus password=somesillysecret";
if (not conn.connect(conninfo)) ...;
if (not conn.connect(conninfo)) ...;
// or
// or
if (not connect()) ...
if (not connect()) ...
// or
// or
if (not connect("exodus")) ...</syntaxhighlight>
if (not connect("exodus")) ...</code></pre>
|-
</td></tr>
|if||conn.<em>attach</em>(filenames)||Attach (connect) specific files by name to specific connections.</p>
<tr><td>if</td><td>conn.<span class='gendoc_function'>attach</span>(filenames)</td><td>Attach (connect) specific files by name to specific connections.</p>
It is not necessary to attach files before opening them. Attach is meant to control the defaults.</p>
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>
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>
If conn is not specified then filename will be attached to the default connection.</p>
If conn is not specified then filename will be attached to the default connection.</p>
Multiple file names must be separated by FM
Multiple file names must be separated by FM
<syntaxhighlight lang="c++">
 
let filenames = "definitions^dict.definitions"_var, conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>let filenames = "definitions^dict.definitions"_var, conn = "exodus";
if (conn.attach(filenames)) ... ok
if (conn.attach(filenames)) ... ok
// or
// or
if (attach(filenames)) ... ok</syntaxhighlight>
if (attach(filenames)) ... ok</code></pre>
|-
</td></tr>
|cmd||conn.<em>detach</em>(filenames)||Detach (disconnect) files that have been attached using attach().
<tr><td>cmd</td><td>conn.<span class='gendoc_function'>detach</span>(filenames)</td><td>Detach (disconnect) files that have been attached using attach().</td></tr>
|-
<tr><td>if</td><td>conn.<span class='gendoc_function'>begintrans</span>()</td><td>Begin a db transaction.
|if||conn.<em>begintrans</em>()||Begin a db transaction.
 
<syntaxhighlight lang="c++">
<pre><code class='hljs-ncdecl language-javascript'>if (not conn.begintrans()) ...
if (not conn.begintrans()) ...
// or
// or
if (not begintrans()) ...</syntaxhighlight>
if (not begintrans()) ...</code></pre>
|-
</td></tr>
|if||conn.<em>statustrans</em>()||Check if a db transaction is in progress.
<tr><td>if</td><td>conn.<span class='gendoc_function'>statustrans</span>()</td><td>Check if a db transaction is in progress.
<syntaxhighlight lang="c++">
 
if (conn.statustrans()) ... ok
<pre><code class='hljs-ncdecl language-javascript'>if (conn.statustrans()) ... ok
// or
// or
if (statustrans()) ... ok</syntaxhighlight>
if (statustrans()) ... ok</code></pre>
|-
</td></tr>
|if||conn.<em>rollbacktrans</em>()||Rollback a db transaction.
<tr><td>if</td><td>conn.<span class='gendoc_function'>rollbacktrans</span>()</td><td>Rollback a db transaction.
<syntaxhighlight lang="c++">
 
if (conn.rollbacktrans()) ... ok
<pre><code class='hljs-ncdecl language-javascript'>if (conn.rollbacktrans()) ... ok
// or
// or
if (rollbacktrans()) ... ok</syntaxhighlight>
if (rollbacktrans()) ... ok</code></pre>
|-
</td></tr>
|if||conn.<em>committrans</em>()||Commit a db transaction.</p>
<tr><td>if</td><td>conn.<span class='gendoc_function'>committrans</span>()</td><td>Commit a db transaction.</p>
<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++">
 
if (conn.committrans()) ... ok
<pre><code class='hljs-ncdecl language-javascript'>if (conn.committrans()) ... ok
// or
// or
if (committrans()) ... ok</syntaxhighlight>
if (committrans()) ... ok</code></pre>
|-
</td></tr>
|if||conn.<em>sqlexec</em>(sqlcmd)||Execute an sql command.</p>
<tr><td>if</td><td>conn.<span class='gendoc_function'>sqlexec</span>(sqlcmd)</td><td>Execute an sql command.</p>
<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++">
 
if (conn.sqlexec("vacuum")) ... ok
<pre><code class='hljs-ncdecl language-javascript'>if (conn.sqlexec("vacuum")) ... ok
// or
// or
if (sqlexec("vacuum")) ... ok</syntaxhighlight>
if (sqlexec("vacuum")) ... ok</code></pre>
|-
</td></tr>
|if||conn.<em>sqlexec</em>(sqlcmd, io response)||Execute an SQL command and capture the response.</p>
<tr><td>if</td><td>conn.<span class='gendoc_function'>sqlexec</span>(sqlcmd, io response)</td><td>Execute an SQL command and capture the response.</p>
<em>Returns:</em> True if there was no sql error otherwise response contains a detailed error message.</p>
<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>
response: Any rows and columns returned are separated by RM and FM respectively. The first row is the column names.</p>
Recommended: Don't use sql directly unless you must to manage or configure a database.
Recommended: Don't use sql directly unless you must to manage or configure a database.
<syntaxhighlight lang="c++">
 
let sqlcmd = "select 'xxx' as col1, 'yyy' as col2";
<pre><code class='hljs-ncdecl language-javascript'>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.
// or
// or
if (sqlexec(sqlcmd, response)) ... ok</syntaxhighlight>
if (sqlexec(sqlcmd, response)) ... ok</code></pre>
|-
</td></tr>
|cmd||conn.<em>disconnect</em>()||Closes db connection and frees process resources both locally and in the database server.
<tr><td>cmd</td><td>conn.<span class='gendoc_function'>disconnect</span>()</td><td>Closes db connection and frees process resources both locally and in the database server.
<syntaxhighlight lang="c++">
 
conn.disconnect();
<pre><code class='hljs-ncdecl language-javascript'>conn.disconnect();
// or
// or
disconnect();</syntaxhighlight>
disconnect();</code></pre>
|-
</td></tr>
|cmd||conn.<em>disconnectall</em>()||Closes all connections and frees process resources both locally and in the database server(s).</p>
<tr><td>cmd</td><td>conn.<span class='gendoc_function'>disconnectall</span>()</td><td>Closes all connections and frees process resources both locally and in the database server(s).</p>
All connections are closed automatically when a process terminates.
All connections are closed automatically when a process terminates.
<syntaxhighlight lang="c++">
 
conn.disconnectall();
<pre><code class='hljs-ncdecl language-javascript'>conn.disconnectall();
// or
// or
disconnectall();</syntaxhighlight>
disconnectall();</code></pre>
|-
</td></tr>
|var=||conn.<em>lasterror</em>()||<em>Returns:</em> The last os or db error message.
<tr><td>var=</td><td>conn.<span class='gendoc_function'>lasterror</span>()</td><td><em>Returns:</em> The last os or db error message.
<syntaxhighlight lang="c++">
 
var v1 = var().lasterror();
<pre><code class='hljs-ncdecl language-javascript'>var v1 = var().lasterror();
// or
// or
var v2 = lasterror();</syntaxhighlight>
var v2 = lasterror();</code></pre>
|-
</td></tr>
|var=||conn.<em>loglasterror</em>(source = "")||Log the last os or db error message.</p>
<tr><td>var=</td><td>conn.<span class='gendoc_function'>loglasterror</span>(source = "")</td><td>Log the last os or db error message.</p>
Output: to stdlog</p>
Output: to stdlog</p>
Prefixes the output with source if provided.
Prefixes the output with source if provided.
<syntaxhighlight lang="c++">
 
var().loglasterror("main:");
<pre><code class='hljs-ncdecl language-javascript'>var().loglasterror("main:");
// or
// or
loglasterror("main:");</syntaxhighlight>
loglasterror("main:");</code></pre>
|}
</td></tr>
===== Database Management =====
</table>
<h5 id=Database_Management>Database Management</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>if</td><td>conn.<span class='gendoc_function'>dbcreate</span>(new_dbname, old_dbname = "")</td><td>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.</p>
The target database cannot already exist.</p>
The target database cannot already exist.</p>
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++">
 
var conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (dbcreate("xo_gendoc_testdb")) ...</syntaxhighlight>
if (dbcreate("xo_gendoc_testdb")) ...</code></pre>
|-
</td></tr>
|if||conn.<em>dbcopy</em>(from_dbname, to_dbname)||Create a named database as a copy of an existing database.</p>
<tr><td>if</td><td>conn.<span class='gendoc_function'>dbcopy</span>(from_dbname, to_dbname)</td><td>Create a named database as a copy of an existing database.</p>
The target database cannot already exist.</p>
The target database cannot already exist.</p>
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++">
 
var conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ...</syntaxhighlight>
if (dbcopy("xo_gendoc_testdb", "xo_gendoc_testdb2")) ...</code></pre>
|-
</td></tr>
|var=||conn.<em>dblist</em>()||<em>Returns:</em> A list of available databases on a particular connection.
<tr><td>var=</td><td>conn.<span class='gendoc_function'>dblist</span>()</td><td><em>Returns:</em> A list of available databases on a particular connection.
<syntaxhighlight lang="c++">
 
let v1 = conn.dblist();
<pre><code class='hljs-ncdecl language-javascript'>let v1 = conn.dblist();
// or
// or
let v2 = dblist();</syntaxhighlight>
let v2 = dblist();</code></pre>
|-
</td></tr>
|if||conn.<em>dbdelete</em>(dbname)||Delete (drop) a named database.</p>
<tr><td>if</td><td>conn.<span class='gendoc_function'>dbdelete</span>(dbname)</td><td>Delete (drop) a named database.</p>
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++">
 
var conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (conn.dbdelete("xo_gendoc_testdb2")) ... ok
if (conn.dbdelete("xo_gendoc_testdb2")) ... ok
// or
// or
if (dbdelete("xo_gendoc_testdb2")) ...</syntaxhighlight>
if (dbdelete("xo_gendoc_testdb2")) ...</code></pre>
|-
</td></tr>
|if||conn.<em>createfile</em>(filename)||Create a named db file.
<tr><td>if</td><td>conn.<span class='gendoc_function'>createfile</span>(filename)</td><td>Create a named db file.
<syntaxhighlight lang="c++">
 
let filename = "xo_gendoc_temp", conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>let filename = "xo_gendoc_temp", conn = "exodus";
if (conn.createfile(filename)) ... ok
if (conn.createfile(filename)) ... ok
// or
// or
if (createfile(filename)) ...</syntaxhighlight>
if (createfile(filename)) ...</code></pre>
|-
</td></tr>
|if||conn.<em>renamefile</em>(filename, newfilename)||Rename a db file.
<tr><td>if</td><td>conn.<span class='gendoc_function'>renamefile</span>(filename, newfilename)</td><td>Rename a db file.
<syntaxhighlight lang="c++">
 
let conn = "exodus", filename = "xo_gendoc_temp", new_filename = "xo_gendoc_temp2";
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|var=||conn.<em>listfiles</em>()||<em>Returns:</em> A list of all files in a database
<tr><td>var=</td><td>conn.<span class='gendoc_function'>listfiles</span>()</td><td><em>Returns:</em> A list of all files in a database
<syntaxhighlight lang="c++">
 
var conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (not conn.listfiles()) ...
if (not conn.listfiles()) ...
// or
// or
if (not listfiles()) ...</syntaxhighlight>
if (not listfiles()) ...</code></pre>
|-
</td></tr>
|if||conn.<em>clearfile</em>(filename)||Delete all records in a db file
<tr><td>if</td><td>conn.<span class='gendoc_function'>clearfile</span>(filename)</td><td>Delete all records in a db file
<syntaxhighlight lang="c++">
 
let conn = "exodus", filename = "xo_gendoc_temp2";
<pre><code class='hljs-ncdecl language-javascript'>let conn = "exodus", filename = "xo_gendoc_temp2";
if (not conn.clearfile(filename)) ...
if (not conn.clearfile(filename)) ...
// or
// or
if (not clearfile(filename)) ...</syntaxhighlight>
if (not clearfile(filename)) ...</code></pre>
|-
</td></tr>
|if||conn.<em>deletefile</em>(filename)||Delete a db file
<tr><td>if</td><td>conn.<span class='gendoc_function'>deletefile</span>(filename)</td><td>Delete a db file
<syntaxhighlight lang="c++">
 
let conn = "exodus", filename = "xo_gendoc_temp2";
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|var=||conn_or_file.<em>reccount</em>(filename = "")||<em>Returns:</em> The approx. number of records in a db file
<tr><td>var=</td><td>conn_or_file.<span class='gendoc_function'>reccount</span>(filename = "")</td><td><em>Returns:</em> The approx. number of records in a db file
<syntaxhighlight lang="c++">
 
let conn = "exodus", filename = "xo_clients";
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|if||conn_or_file.<em>flushindex</em>(filename = "")||Calls db maintenance function (vacuum)</p>
<tr><td>if</td><td>conn_or_file.<span class='gendoc_function'>flushindex</span>(filename = "")</td><td>Calls db maintenance function (vacuum)</p>
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.</td></tr>
|}
</table>
===== Database File I/O =====
<h5 id=Database_File_I/O>Database File I/O</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>open</span>(dbfilename, connection = "")</td><td>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++">
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|cmd||file.<em>close</em>()||Closes db file var</p>
<tr><td>cmd</td><td>file.<span class='gendoc_function'>close</span>()</td><td>Closes db file var</p>
Does nothing currently since database file vars consume no resources
Does nothing currently since database file vars consume no resources
<syntaxhighlight lang="c++">
 
var file = "definitions";
<pre><code class='hljs-ncdecl language-javascript'>var file = "definitions";
file.close();
file.close();
// or
// or
close(file);</syntaxhighlight>
close(file);</code></pre>
|-
</td></tr>
|if||file.<em>createindex</em>(fieldname, dictfile = "")||Creates a secondary index for a given db file and field name.</p>
<tr><td>if</td><td>file.<span class='gendoc_function'>createindex</span>(fieldname, dictfile = "")</td><td>Creates a secondary index for a given db file and field name.</p>
The fieldname must exist in a dictionary file. The default dictionary is "dict." ^ filename.</p>
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>
<em>Returns:</em> False if the index cannot be created for any reason.</p>
Line 1,004: Line 1,181:
* The dictionary file does not exist. Default is "dict." ^ filename.</p>
* The dictionary file does not exist. Default is "dict." ^ filename.</p>
* 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++">
 
var filename = "definitions", fieldname = "DATE_TIME";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (createindex(filename, fieldname)) ...</syntaxhighlight>
if (createindex(filename, fieldname)) ...</code></pre>
|-
</td></tr>
|var=||file|conn.<em>listindex</em>(file_or_filename = "", fieldname = "")||Lists secondary indexes in a database or for a db file</p>
<tr><td>var=</td><td>file|conn.<span class='gendoc_function'>listindex</span>(file_or_filename = "", fieldname = "")</td><td>Lists secondary indexes in a database or for a db file</p>
<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++">
 
var conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>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</code></pre>
|-
</td></tr>
|if||file.<em>deleteindex</em>(fieldname)||Deletes a secondary index for a db file and field name.</p>
<tr><td>if</td><td>file.<span class='gendoc_function'>deleteindex</span>(fieldname)</td><td>Deletes a secondary index for a db file and field name.</p>
<em>Returns:</em> False if the index cannot be deleted for any reason</p>
<em>Returns:</em> False if the index cannot be deleted for any reason</p>
* File does not exist</p>
* File does not exist</p>
* Index does not already exists
* Index does not already exists
<syntaxhighlight lang="c++">
 
var file = "definitions", fieldname = "DATE_TIME";
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|var=||file.<em>lock</em>(key)||Places a metaphorical db lock on a particular record given a db file and key.</p>
<tr><td>var=</td><td>file.<span class='gendoc_function'>lock</span>(key)</td><td>Places a metaphorical db lock on a particular record given a db file and key.</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.</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.</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>
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>
Line 1,041: Line 1,218:
* 1: Success: A new lock has been placed.</p>
* 1: Success: A new lock has been placed.</p>
* 2: Success: The lock has already been placed and the connection is in a transaction.
* 2: Success: The lock has already been placed and the connection is in a transaction.
<syntaxhighlight lang="c++">
 
var file = "xo_clients", key = "1000";
<pre><code class='hljs-ncdecl language-javascript'>var file = "xo_clients", key = "1000";
if (file.lock(key)) ... ok
if (file.lock(key)) ... ok
// or
// or
if (lock(file, key)) ...</syntaxhighlight>
if (lock(file, key)) ...</code></pre>
|-
</td></tr>
|if||file.<em>unlock</em>(key)||Removes a db lock placed by the lock function.</p>
<tr><td>if</td><td>file.<span class='gendoc_function'>unlock</span>(key)</td><td>Removes a db lock placed by the lock function.</p>
Only locks placed on the specified connection can be removed.</p>
Only locks placed on the specified connection can be removed.</p>
Locks cannot be removed while a connection is in a transaction.</p>
Locks cannot be removed while a connection is in a transaction.</p>
<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++">
 
var file = "xo_clients", key = "1000";
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|if||file.<em>unlockall</em>()||Removes all db locks placed by the lock function in the specified connection.</p>
<tr><td>if</td><td>file.<span class='gendoc_function'>unlockall</span>()</td><td>Removes all db locks placed by the lock function in the specified connection.</p>
Locks cannot be removed while in a transaction.
Locks cannot be removed while in a transaction.
<syntaxhighlight lang="c++">
 
var conn = "exodus";
<pre><code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (not conn.unlockall()) ...
if (not conn.unlockall()) ...
// or
// or
if (not unlockall(conn)) ...</syntaxhighlight>
if (not unlockall(conn)) ...</code></pre>
|-
</td></tr>
|cmd||rec.<em>write</em>(file, key)||Writes a record into a db file given a unique primary key.</p>
<tr><td>cmd</td><td>rec.<span class='gendoc_function'>write</span>(file, key)</td><td>Writes a record into a db file given a unique primary key.</p>
Either inserts a new record or updates an existing record.</p>
Either inserts a new record or updates an existing record.</p>
It always succeeds so no result code is returned.</p>
It always succeeds so no result code is returned.</p>
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
 
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
<pre><code class='hljs-ncdecl language-javascript'>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
rec.write(file, key);
rec.write(file, key);
// or
// or
write(rec on file, key);</syntaxhighlight>
write(rec on file, key);</code></pre>
|-
</td></tr>
|if||rec.<em>read</em>(file, key)||Reads a record from a db file for a given key.</p>
<tr><td>if</td><td>rec.<span class='gendoc_function'>read</span>(file, key)</td><td>Reads a record from a db file for a given key.</p>
<em>Returns:</em> False if the key doesnt exist
<em>Returns:</em> False if the key doesnt exist
<syntaxhighlight lang="c++">
 
var rec;
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (not read(rec from file, key)) ...</syntaxhighlight>
if (not read(rec from file, key)) ...</code></pre>
|-
</td></tr>
|if||file.<em>deleterecord</em>(key)||Deletes a record from a db file given a key.</p>
<tr><td>if</td><td>file.<span class='gendoc_function'>deleterecord</span>(key)</td><td>Deletes a record from a db file given a key.</p>
<em>Returns:</em> False if the key doesnt exist</p>
<em>Returns:</em> False if the key doesnt exist</p>
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
 
let file = "xo_clients", key = "GD001";
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|if||rec.<em>insertrecord</em>(file, key)||Inserts a new record in a db file.</p>
<tr><td>if</td><td>rec.<span class='gendoc_function'>insertrecord</span>(file, key)</td><td>Inserts a new record in a db file.</p>
<em>Returns:</em> False if the key already exists</p>
<em>Returns:</em> False if the key already exists</p>
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
 
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (insertrecord(rec on file, key)) ...</syntaxhighlight>
if (insertrecord(rec on file, key)) ...</code></pre>
|-
</td></tr>
|if||rec.<em>updaterecord</em>(file, key)||Updates an existing record in a db file.</p>
<tr><td>if</td><td>rec.<span class='gendoc_function'>updaterecord</span>(file, key)</td><td>Updates an existing record in a db file.</p>
<em>Returns:</em> False if the key doesnt already exist</p>
<em>Returns:</em> False if the key doesnt already exist</p>
Any memory cached record is deleted.
Any memory cached record is deleted.
<syntaxhighlight lang="c++">
 
let rec = "Client GD^G^20855^30000^1001.00^20855.76539"_var;
<pre><code class='hljs-ncdecl language-javascript'>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)) ...
// or
// or
if (not updaterecord(rec on file, key)) ...</syntaxhighlight>
if (not updaterecord(rec on file, key)) ...</code></pre>
|-
</td></tr>
|if||strvar.<em>readf</em>(file, key, fieldno)||"Read field" Same as read() but only returns a specific field from the record
<tr><td>if</td><td>strvar.<span class='gendoc_function'>readf</span>(file, key, fieldno)</td><td>"Read field" Same as read() but only returns a specific field from the record
<syntaxhighlight lang="c++">
 
var field, file = "xo_clients", key = "GD001", fieldno = 2;
<pre><code class='hljs-ncdecl language-javascript'>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
if (not readf(field from file, key, fieldno)) ...</syntaxhighlight>
if (not readf(field from file, key, fieldno)) ...</code></pre>
|-
</td></tr>
|cmd||strvar.<em>writef</em>(file, key, fieldno)||"write field" Same as write() but only writes to a specific field in the record
<tr><td>cmd</td><td>strvar.<span class='gendoc_function'>writef</span>(file, key, fieldno)</td><td>"write field" Same as write() but only writes to a specific field in the record
<syntaxhighlight lang="c++">
 
var field = "f3", file = "definitions", key = "1000", fieldno = 3;
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|cmd||rec.<em>writec</em>(file, key)||"Write cache" Writes a record and key into a memory cached "db file".</p>
<tr><td>cmd</td><td>rec.<span class='gendoc_function'>writec</span>(file, key)</td><td>"Write cache" Writes a record and key into a memory cached "db file".</p>
The actual file is NOT updated.</p>
The actual 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>
writec() either updates an existing cache record if the key already exists or otherwise inserts a new record into the cache.</p>
It always succeeds so no result code is returned.</p>
It always succeeds so no result code is returned.</p>
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++">
 
let rec = "Client XD^X^20855^30000^1001.00^20855.76539"_var;
<pre><code class='hljs-ncdecl language-javascript'>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);
// or
// or
writec(rec on file, key);</syntaxhighlight>
writec(rec on file, key);</code></pre>
|-
</td></tr>
|if||rec.<em>readc</em>(file, key)||"Read cache" Same as "read() but first reads from a memory cache.</p>
<tr><td>if</td><td>rec.<span class='gendoc_function'>readc</span>(file, key)</td><td>"Read cache" Same as "read() but first reads from a memory cache.</p>
1. Tries to read from a memory cache. Returns true if successful.</p>
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>
2a. Tries to read from the actual db file and returns false if unsuccessful.</p>
2b. Writes the record and key to the memory cache and returns true.</p>
2b. Writes the record and key to the memory cache and returns true.</p>
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++">
 
var rec;
<pre><code class='hljs-ncdecl language-javascript'>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,154: Line 1,331:


// Verify not in actual file by using read() not readc()
// Verify not in actual file by using read() not readc()
if (read(rec from file, key)) abort("Error: " ^ key ^ " should not be in the actual file"); // error</syntaxhighlight>
if (read(rec from file, key)) abort("Error: " ^ key ^ " should not be in the actual file"); // error</code></pre>
|-
</td></tr>
|if||dbfile.<em>deletec</em>(key)||Deletes a record and key from a memory cached "file".</p>
<tr><td>if</td><td>dbfile.<span class='gendoc_function'>deletec</span>(key)</td><td>Deletes a record and key from a memory cached "file".</p>
The actual file is NOT updated.</p>
The actual file is NOT updated.</p>
<em>Returns:</em> False if the key doesnt exist
<em>Returns:</em> False if the key doesnt exist
<syntaxhighlight lang="c++">
 
var file = "xo_clients", key = "XD001";
<pre><code class='hljs-ncdecl language-javascript'>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)) ...</code></pre>
|-
</td></tr>
|cmd||conn.<em>cleardbcache</em>()||Clears the memory cache of all records for the given connection</p>
<tr><td>cmd</td><td>conn.<span class='gendoc_function'>cleardbcache</span>()</td><td>Clears the memory cache of all records for the given connection</p>
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++">
 
conn.cleardbcache();
<pre><code class='hljs-ncdecl language-javascript'>conn.cleardbcache();
// or
// or
cleardbcache(conn);</syntaxhighlight>
cleardbcache(conn);</code></pre>
|-
</td></tr>
|var=||strvar.<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>
<tr><td>var=</td><td>strvar.<span class='gendoc_function'>xlate</span>(filename, fieldno, mode)</td><td>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>
Arguments:</p>
Arguments:</p>
str: Used as the primary key to lookup a field in a given file and field no or field name.</p>
str: Used as the primary key to lookup a field in a given file and field no or field name.</p>
Line 1,184: Line 1,361:
* "X" returns ""</p>
* "X" returns ""</p>
* "C" returns the key unconverted.
* "C" returns the key unconverted.
<syntaxhighlight lang="c++">
 
let key = "SB001";
<pre><code class='hljs-ncdecl language-javascript'>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
let name_and_type = xlate("xo_clients", key, "NAME_AND_TYPE", "X"); // "Client AAA (A)"</syntaxhighlight>
let name_and_type = xlate("xo_clients", key, "NAME_AND_TYPE", "X"); // "Client AAA (A)"</code></pre>
|}
</td></tr>
===== Database Sort/Select =====
</table>
<h5 id=Database_Sort/Select>Database Sort/Select</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>select</span>(sortselectclause = "")</td><td></td></tr>
|if||file.<em>select</em>(sortselectclause = "")||
<tr><td>cmd</td><td>file.<span class='gendoc_function'>clearselect</span>()</td><td></td></tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>hasnext</span>()</td><td></td></tr>
|cmd||file.<em>clearselect</em>()||
<tr><td>if</td><td>file.<span class='gendoc_function'>readnext</span>(out key)</td><td></td></tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>readnext</span>(out key, out valueno)</td><td></td></tr>
|if||file.<em>hasnext</em>()||
<tr><td>if</td><td>file.<span class='gendoc_function'>readnext</span>(out record, out key, out valueno)</td><td></td></tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>savelist</span>(listname)</td><td></td></tr>
|if||file.<em>readnext</em>(out key)||
<tr><td>if</td><td>file.<span class='gendoc_function'>getlist</span>(listname)</td><td></td></tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>makelist</span>(listname, keys)</td><td></td></tr>
|if||file.<em>readnext</em>(out key, out valueno)||
<tr><td>if</td><td>file.<span class='gendoc_function'>deletelist</span>(listname)</td><td></td></tr>
|-
<tr><td>if</td><td>file.<span class='gendoc_function'>formlist</span>(keys, fieldno = 0)</td><td></td></tr>
|if||file.<em>readnext</em>(out record, out key, out valueno)||
</table>
|-
<h5 id=OS_Time/Date>OS Time/Date</h5>
|if||file.<em>savelist</em>(listname)||
|-
|if||file.<em>getlist</em>(listname)||
|-
|if||file.<em>makelist</em>(listname, keys)||
|-
|if||file.<em>deletelist</em>(listname)||
|-
|if||file.<em>formlist</em>(keys, fieldno = 0)||
|}
===== OS Time/Date =====


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>var().<span class='gendoc_function'>date</span>()</td><td>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.</p>
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++">
 
let today1 = var().date();
<pre><code class='hljs-ncdecl language-javascript'>let today1 = var().date();
// or
// or
let today2 = date();</syntaxhighlight>
let today2 = date();</code></pre>
|-
</td></tr>
|var=||var().<em>time</em>()||Number of whole seconds since last 00:00:00 (UTC).</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>time</span>()</td><td>Number of whole seconds since last 00:00:00 (UTC).</p>
e.g. 43200 if time is 12:00</p>
e.g. 43200 if time is 12:00</p>
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++">
 
let now1 = var().time();
<pre><code class='hljs-ncdecl language-javascript'>let now1 = var().time();
// or
// or
let now2 = time();</syntaxhighlight>
let now2 = time();</code></pre>
|-
</td></tr>
|var=||var().<em>ostime</em>()||Number of fractional seconds since last 00:00:00 (UTC).</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>ostime</span>()</td><td>Number of fractional seconds since last 00:00:00 (UTC).</p>
A floating point with approx. nanosecond resolution depending on hardware.</p>
A floating point with approx. nanosecond resolution depending on hardware.</p>
e.g. 23343.704387955 approx. 06:29:03 UTC
e.g. 23343.704387955 approx. 06:29:03 UTC
<syntaxhighlight lang="c++">
 
let now1 = var().ostime();
<pre><code class='hljs-ncdecl language-javascript'>let now1 = var().ostime();
// or
// or
let now2 = ostime();</syntaxhighlight>
let now2 = ostime();</code></pre>
|-
</td></tr>
|var=||var().<em>timestamp</em>()||Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>timestamp</span>()</td><td>Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.</p>
A floating point with approx. nanosecond resolution depending on hardware.</p>
A floating point with approx. nanosecond resolution depending on hardware.</p>
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++">
 
let now1 = var().timestamp();
<pre><code class='hljs-ncdecl language-javascript'>let now1 = var().timestamp();
// or
// or
let now2 = timestamp();</syntaxhighlight>
let now2 = timestamp();</code></pre>
|-
</td></tr>
|var=||var().<em>timestamp</em>(ostime)||Construct a timestamp from a date and time
<tr><td>var=</td><td>var().<span class='gendoc_function'>timestamp</span>(ostime)</td><td>Construct a timestamp from a date and time
<syntaxhighlight lang="c++">
 
let idate = iconv("2025-01-01", "D"), itime = iconv("23:59:59", "MT");
<pre><code class='hljs-ncdecl language-javascript'>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);</code></pre>
|-
</td></tr>
|cmd||var().<em>ossleep</em>(milliseconds)||Sleep/pause/wait for a number of milliseconds</p>
<tr><td>cmd</td><td>var().<span class='gendoc_function'>ossleep</span>(milliseconds)</td><td>Sleep/pause/wait for a number of milliseconds</p>
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++">
 
var().ossleep(500); // sleep for 500ms
<pre><code class='hljs-ncdecl language-javascript'>var().ossleep(500); // sleep for 500ms
// or
// or
ossleep(500);</syntaxhighlight>
ossleep(500);</code></pre>
|-
</td></tr>
|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>
<tr><td>var=</td><td>file_dir_list.<span class='gendoc_function'>oswait</span>(milliseconds)</td><td>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>
Any terminal input (e.g. a key press) will also terminate the wait.</p>
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>
An FM array of event information is returned. See below.</p>
Multiple events are returned in multivalues.
Multiple events are returned in multivalues.
<syntaxhighlight lang="c++">
 
let v1 = ".^/etc/hosts"_var.oswait(500); /// e.g. "IN_CLOSE_WRITE^/etc^hosts^f"_var
<pre><code class='hljs-ncdecl language-javascript'>let v1 = ".^/etc/hosts"_var.oswait(500); /// e.g. "IN_CLOSE_WRITE^/etc^hosts^f"_var
// or
// or
let v2 = oswait(".^/etc/hosts"_var, 500);</syntaxhighlight>
let v2 = oswait(".^/etc/hosts"_var, 500);</code></pre>
 
Returned array fields</p>
Returned array fields</p>
1. Event type codes</p>
1. Event type codes</p>
Line 1,293: Line 1,460:
* IN_DELETE - A file was deleted from the directory</p>
* IN_DELETE - A file was deleted from the directory</p>
* IN_DELETE_SELF - Directory or file under observation was deleted</p>
* IN_DELETE_SELF - Directory or file under observation was deleted</p>
* IN_MOVE_SELF - Directory or file under observation was moved
* IN_MOVE_SELF - Directory or file under observation was moved</td></tr>
|}
</table>
===== OS File I/O =====
<h5 id=OS_File_I/O>OS File I/O</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>if</td><td>osfilevar.<span class='gendoc_function'>osopen</span>(osfilename, utf8 = true)</td><td>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.</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;</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;</p>
File will be opened for writing if possible otherwise for reading.</p>
File will be opened for writing if possible otherwise for reading.</p>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
e.g. Target doesnt exist, permissions etc.
e.g. Target doesnt exist, permissions etc.
<syntaxhighlight lang="c++">
 
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
<pre><code class='hljs-ncdecl language-javascript'>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;
if (ostempfile.osopen(osfilename)) ... ok
if (ostempfile.osopen(osfilename)) ... ok
// or
// or
if (osopen(osfilename to ostempfile)) ... ok</syntaxhighlight>
if (osopen(osfilename to ostempfile)) ... ok</code></pre>
|-
</td></tr>
|if||osfilevar.<em>osbwrite</em>(osfilevar, io offset)||Writes data to an existing os file starting at a given byte offset (0 based).</p>
<tr><td>if</td><td>osfilevar.<span class='gendoc_function'>osbwrite</span>(osfilevar, io offset)</td><td>Writes data to an existing os file starting at a given byte offset (0 based).</p>
See osbread for more info.
See osbread for more info.
<syntaxhighlight lang="c++">
 
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
<pre><code class='hljs-ncdecl language-javascript'>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
if (text.osbwrite(osfilename, offset)) ... ok // offset -> 16
if (text.osbwrite(osfilename, offset)) ... ok // offset -> 16
// or
// or
if (not osbwrite(text on osfilename, offset)) ...</syntaxhighlight>
if (not osbwrite(text on osfilename, offset)) ...</code></pre>
|-
</td></tr>
|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>
<tr><td>if</td><td>osfilevar.<span class='gendoc_function'>osbread</span>(osfilevar, io offset, length)</td><td>Reads length bytes from an existing os file starting at a given byte offset (0 based).</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.</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.</p>
After reading, the offset is updated to point to the correct offset for a subsequent sequential read.</p>
After reading, the offset is updated to point to the correct offset for a subsequent sequential read.</p>
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++">
 
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
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</code></pre>
|-
</td></tr>
|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>
<tr><td>cmd</td><td>osfilevar.<span class='gendoc_function'>osclose</span>()</td><td>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>
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++">
 
osfilevar.osclose();
<pre><code class='hljs-ncdecl language-javascript'>osfilevar.osclose();
// or
// or
osclose(osfilevar);</syntaxhighlight>
osclose(osfilevar);</code></pre>
|-
</td></tr>
|if||strvar.<em>oswrite</em>(osfilename, codepage = "")||Create a complete os file from a var.</p>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>oswrite</span>(osfilename, codepage = "")</td><td>Create a complete os file from a var.</p>
Any existing os file is removed first.</p>
Any existing os file is removed first.</p>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
e.g. Path is not writeable, permissions etc.</p>
e.g. Path is not writeable, permissions etc.</p>
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++">
 
let text = "aaa = 123\nbbb = 456";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (oswrite(text on osfilename)) ... ok</syntaxhighlight>
if (oswrite(text on osfilename)) ... ok</code></pre>
|-
</td></tr>
|if||strvar.<em>osread</em>(osfilename, codepage = "")||Read a complete os file into a var.</p>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>osread</span>(osfilename, codepage = "")</td><td>Read a complete os file into a var.</p>
If codepage is specified then input is converted from that codepage to utf-8 otherwise no conversion is done.</p>
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>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
e.g. File doesnt exist, permissions etc.
e.g. File doesnt exist, permissions etc.
<syntaxhighlight lang="c++">
 
var text;
<pre><code class='hljs-ncdecl language-javascript'>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"
// or
// or
if (osread(text from osfilename)) ... ok</syntaxhighlight>
if (osread(text from osfilename)) ... ok</code></pre>
|-
</td></tr>
|if||osfile_or_dirname.<em>osrename</em>(new_dirpath_or_filepath)||Renames an os file or dir in the OS file system.</p>
<tr><td>if</td><td>osfile_or_dirname.<span class='gendoc_function'>osrename</span>(new_dirpath_or_filepath)</td><td>Renames an os file or dir in the OS file system.</p>
Will not overwrite an existing os file or dir.</p>
Will not overwrite an existing os file or dir.</p>
Source and target must exist in the same storage device.</p>
Source and target must exist in the same storage device.</p>
Line 1,370: Line 1,536:
e.g. Target already exists, path is not writeable, permissions etc.</p>
e.g. Target already exists, path is not writeable, permissions etc.</p>
Uses std::filesystem::rename internally.
Uses std::filesystem::rename internally.
<syntaxhighlight lang="c++">
 
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
<pre><code class='hljs-ncdecl language-javascript'>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,377: Line 1,543:
if (from_osfilename.osrename(to_osfilename)) ... ok
if (from_osfilename.osrename(to_osfilename)) ... ok
// or
// or
if (osrename(from_osfilename, to_osfilename)) ...</syntaxhighlight>
if (osrename(from_osfilename, to_osfilename)) ...</code></pre>
|-
</td></tr>
|if||osfile_or_dirname.<em>osmove</em>(to_osfilename)||"Moves" an os file or dir within the os file system.</p>
<tr><td>if</td><td>osfile_or_dirname.<span class='gendoc_function'>osmove</span>(to_osfilename)</td><td>"Moves" an os file or dir within the os file system.</p>
Will not overwrite an existing os file or dir.</p>
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>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions etc.</p>
e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions etc.</p>
Attempts osrename first then oscopy followed by osremove original.
Attempts osrename first then oscopy followed by osremove original.
<syntaxhighlight lang="c++">
 
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf.bak";
<pre><code class='hljs-ncdecl language-javascript'>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,391: Line 1,557:
if (from_osfilename.osmove(to_osfilename)) ... ok
if (from_osfilename.osmove(to_osfilename)) ... ok
// or
// or
if (osmove(from_osfilename, to_osfilename)) ...</syntaxhighlight>
if (osmove(from_osfilename, to_osfilename)) ...</code></pre>
|-
</td></tr>
|if||osfile_or_dirname.<em>oscopy</em>(to_osfilename)||Copies an os file or directory recursively within the os file system.</p>
<tr><td>if</td><td>osfile_or_dirname.<span class='gendoc_function'>oscopy</span>(to_osfilename)</td><td>Copies an os file or directory recursively within the os file system.</p>
Will overwrite an existing os file or dir.</p>
Will overwrite an existing os file or dir.</p>
Uses std::filesystem::copy internally with recursive and overwrite options
Uses std::filesystem::copy internally with recursive and overwrite options
<syntaxhighlight lang="c++">
 
let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
<pre><code class='hljs-ncdecl language-javascript'>let from_osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
let to_osfilename = from_osfilename ^ ".bak";
let to_osfilename = from_osfilename ^ ".bak";


if (from_osfilename.oscopy(to_osfilename)) ... ok;
if (from_osfilename.oscopy(to_osfilename)) ... ok;
// or
// or
if (oscopy(from_osfilename, to_osfilename)) ... ok</syntaxhighlight>
if (oscopy(from_osfilename, to_osfilename)) ... ok</code></pre>
|-
</td></tr>
|if||osfilename.<em>osremove</em>()||Removes/deletes an os file from the OS file system given path and name.</p>
<tr><td>if</td><td>osfilename.<span class='gendoc_function'>osremove</span>()</td><td>Removes/deletes an os file from the OS file system given path and name.</p>
Will not remove directories. Use osrmdir() to remove directories</p>
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>
<em>Returns:</em> True if successful or false if not possible for any reason.</p>
e.g. Target doesnt exist, path is not writeable, permissions etc.
e.g. Target doesnt exist, path is not writeable, permissions etc.
<syntaxhighlight lang="c++">
 
let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
<pre><code class='hljs-ncdecl language-javascript'>let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
if (osfilename.osremove()) ... ok
if (osfilename.osremove()) ... ok
// or
// or
if (osremove(osfilename)) ...</syntaxhighlight>
if (osremove(osfilename)) ...</code></pre>
|}
</td></tr>
===== OS Directories =====
</table>
<h5 id=OS_Directories>OS Directories</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>dirpath.<span class='gendoc_function'>oslist</span>(globpattern = "", mode = 0)</td><td><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)||<em>Returns:</em> A FM delimited string containing all matching dir entries given a dir path</p>
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++">
 
var entries1 = "/etc/"_var.oslist("*.cfg"); /// e.g. "adduser.conf^ca-certificates.con^... etc."
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||dirpath.<em>oslistf</em>(globpattern = "")||Same as oslist for files only
<tr><td>var=</td><td>dirpath.<span class='gendoc_function'>oslistf</span>(globpattern = "")</td><td>Same as oslist for files only</td></tr>
|-
<tr><td>var=</td><td>dirpath.<span class='gendoc_function'>oslistd</span>(globpattern = "")</td><td>Same as oslist for files only</td></tr>
|var=||dirpath.<em>oslistd</em>(globpattern = "")||Same as oslist for files only
<tr><td>var=</td><td>osfile_or_dirpath.<span class='gendoc_function'>osinfo</span>(mode = 0)</td><td><em>Returns:</em> Dir info for any dir entry or "" if it doesnt exist</p>
|-
|var=||osfile_or_dirpath.<em>osinfo</em>(mode = 0)||<em>Returns:</em> Dir info for any dir entry or "" if it doesnt exist</p>
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time</p>
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time</p>
mode 0 default</p>
mode 0 default</p>
Line 1,436: Line 1,600:
mode 2 returns "" if not an os dir</p>
mode 2 returns "" if not an os dir</p>
See also osfile() and osdir()
See also osfile() and osdir()
<syntaxhighlight lang="c++">
 
var info1 = "/etc/hosts"_var.osinfo(); /// e.g. "221^20597^78309"_var
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||osfilename.<em>osfile</em>()||<em>Returns:</em> Dir info for a os file</p>
<tr><td>var=</td><td>osfilename.<span class='gendoc_function'>osfile</span>()</td><td><em>Returns:</em> Dir info for a os file</p>
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time</p>
A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time</p>
Alias for osinfo(1)
Alias for osinfo(1)
<syntaxhighlight lang="c++">
 
var fileinfo1 = "/etc/hosts"_var.osfile(); /// e.g. "221^20597^78309"_var
<pre><code class='hljs-ncdecl language-javascript'>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");</code></pre>
|-
</td></tr>
|var=||dirpath.<em>osdir</em>()||<em>Returns:</em> Dir info for a dir.</p>
<tr><td>var=</td><td>dirpath.<span class='gendoc_function'>osdir</span>()</td><td><em>Returns:</em> Dir info for a dir.</p>
A short string containing FM ^ modified_time ^ FM ^ modified_time</p>
A short string containing FM ^ modified_time ^ FM ^ modified_time</p>
Alias for osinfo(2)
Alias for osinfo(2)
<syntaxhighlight lang="c++">
 
var dirinfo1 = "/etc/"_var.osdir(); /// e.g. "^20848^44464"_var
<pre><code class='hljs-ncdecl language-javascript'>var dirinfo1 = "/etc/"_var.osdir(); /// e.g. "^20848^44464"_var
// or
// or
var dirinfo2 = osfile("/etc/");</syntaxhighlight>
var dirinfo2 = osfile("/etc/");</code></pre>
|-
</td></tr>
|if||dirpath.<em>osmkdir</em>()||Makes a new directory and returns true if successful.</p>
<tr><td>if</td><td>dirpath.<span class='gendoc_function'>osmkdir</span>()</td><td>Makes a new directory and returns true if successful.</p>
Including parent dirs if necessary.
Including parent dirs if necessary.
<syntaxhighlight lang="c++">
 
let osdirname = "xo_test/aaa";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (osmkdir(osdirname)) ...</syntaxhighlight>
if (osmkdir(osdirname)) ...</code></pre>
|-
</td></tr>
|if||dirpath.<em>oscwd</em>(newpath)||Changes the current working dir and returns true if successful.
<tr><td>if</td><td>dirpath.<span class='gendoc_function'>oscwd</span>(newpath)</td><td>Changes the current working dir and returns true if successful.
<syntaxhighlight lang="c++">
 
let osdirname = "xo_test/aaa";
<pre><code class='hljs-ncdecl language-javascript'>let osdirname = "xo_test/aaa";
if (osdirname.oscwd()) ... ok
if (osdirname.oscwd()) ... ok
// or
// or
if (oscwd(osdirname)) ... ok</syntaxhighlight>
if (oscwd(osdirname)) ... ok</code></pre>
|-
</td></tr>
|var=||dirpath.<em>oscwd</em>()||<em>Returns:</em> The current working directory</p>
<tr><td>var=</td><td>dirpath.<span class='gendoc_function'>oscwd</span>()</td><td><em>Returns:</em> The current working directory</p>
e.g. "/root/exodus/cli/src/xo_test/aaa"
e.g. "/root/exodus/cli/src/xo_test/aaa"
<syntaxhighlight lang="c++">
 
var cwd1 = var().oscwd();
<pre><code class='hljs-ncdecl language-javascript'>var cwd1 = var().oscwd();
// or
// or
var cwd2 = oscwd();</syntaxhighlight>
var cwd2 = oscwd();</code></pre>
|-
</td></tr>
|if||dirpath.<em>osrmdir</em>(evenifnotempty = false)||Removes a os dir and returns true if successful.</p>
<tr><td>if</td><td>dirpath.<span class='gendoc_function'>osrmdir</span>(evenifnotempty = false)</td><td>Removes a os dir and returns true if successful.</p>
Optionally even if not empty. Including subdirs.
Optionally even if not empty. Including subdirs.
<syntaxhighlight lang="c++">
 
let osdirname = "xo_test/aaa";
<pre><code class='hljs-ncdecl language-javascript'>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
// or
// or
if (osrmdir(osdirname)) ...</syntaxhighlight>
if (osrmdir(osdirname)) ...</code></pre>
|}
</td></tr>
===== OS Shell/Environment =====
</table>
<h5 id=OS_Shell/Environment>OS Shell/Environment</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>if</td><td>command.<span class='gendoc_function'>osshell</span>()</td><td>Execute a shell command.</p>
|if||command.<em>osshell</em>()||Execute a shell command.</p>
<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.</p>
Append "&>/dev/null" to the command to suppress terminal output.
Append "&>/dev/null" to the command to suppress terminal output.
<syntaxhighlight lang="c++">
 
let cmd = "echo $HOME";
<pre><code class='hljs-ncdecl language-javascript'>let cmd = "echo $HOME";
if (cmd.osshell()) ... ok
if (cmd.osshell()) ... ok
// or
// or
if (osshell(cmd)) ... ok</syntaxhighlight>
if (osshell(cmd)) ... ok</code></pre>
|-
</td></tr>
|if||instr.<em>osshellread</em>(oscmd)||Same as osshell but captures and returns stdout</p>
<tr><td>if</td><td>instr.<span class='gendoc_function'>osshellread</span>(oscmd)</td><td>Same as osshell but captures and returns stdout</p>
<em>Returns:</em> The stout of the shell command.</p>
<em>Returns:</em> The stout of the shell command.</p>
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++">
 
let cmd = "echo $HOME";
<pre><code class='hljs-ncdecl language-javascript'>let cmd = "echo $HOME";
var text;
var text;
if (text.osshellread(cmd)) ... ok
if (text.osshellread(cmd)) ... ok


// or capturing stdout but ignoring exit status
// or capturing stdout but ignoring exit status
text = osshellread(cmd);</syntaxhighlight>
text = osshellread(cmd);</code></pre>
|-
</td></tr>
|if||outstr.<em>osshellwrite</em>(oscmd)||Same as osshell but provides stdin to the process</p>
<tr><td>if</td><td>outstr.<span class='gendoc_function'>osshellwrite</span>(oscmd)</td><td>Same as osshell but provides stdin to the process</p>
<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.</p>
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++">
 
let outtext = "abc xyz";
<pre><code class='hljs-ncdecl language-javascript'>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</code></pre>
|-
</td></tr>
|var=||var().<em>ostempdirpath</em>()||<em>Returns:</em> The path of the tmp dir</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>ostempdirpath</span>()</td><td><em>Returns:</em> The path of the tmp dir</p>
e.g. "/tmp/"
e.g. "/tmp/"
<syntaxhighlight lang="c++">
 
let v1 = var().ostempdirpath();
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var().ostempdirpath();
// or
// or
let v2 = ostempdirpath();</syntaxhighlight>
let v2 = ostempdirpath();</code></pre>
|-
</td></tr>
|var=||var().<em>ostempfilename</em>()||<em>Returns:</em> The name of a new temporary file</p>
<tr><td>var=</td><td>var().<span class='gendoc_function'>ostempfilename</span>()</td><td><em>Returns:</em> The name of a new temporary file</p>
e.g. Something like "/tmp/~exoEcLj3C"
e.g. Something like "/tmp/~exoEcLj3C"
<syntaxhighlight lang="c++">
 
var temposfilename1 = var().ostempfilename();
<pre><code class='hljs-ncdecl language-javascript'>var temposfilename1 = var().ostempfilename();
// or
// or
var temposfilename2 = ostempfilename();</syntaxhighlight>
var temposfilename2 = ostempfilename();</code></pre>
|-
</td></tr>
|cmd||envvalue.<em>ossetenv</em>(envcode)||Set the value of an environment variable code
<tr><td>cmd</td><td>envvalue.<span class='gendoc_function'>ossetenv</span>(envcode)</td><td>Set the value of an environment variable code
<syntaxhighlight lang="c++">
 
let envcode = "EXO_ABC", envvalue = "XYZ";
<pre><code class='hljs-ncdecl language-javascript'>let envcode = "EXO_ABC", envvalue = "XYZ";
envvalue.ossetenv(envcode);
envvalue.ossetenv(envcode);
// or
// or
ossetenv(envcode, envvalue);</syntaxhighlight>
ossetenv(envcode, envvalue);</code></pre>
|-
</td></tr>
|if||envvalue.<em>osgetenv</em>(envcode)||Get the value of an environment variable
<tr><td>if</td><td>envvalue.<span class='gendoc_function'>osgetenv</span>(envcode)</td><td>Get the value of an environment variable
<syntaxhighlight lang="c++">
 
var envvalue1;
<pre><code class='hljs-ncdecl language-javascript'>var envvalue1;
if (envvalue1.osgetenv("HOME")) ... ok // e.g. "/home/exodus"
if (envvalue1.osgetenv("HOME")) ... ok // e.g. "/home/exodus"
// or
// or
var envvalue2 = osgetenv("EXO_ABC"); // "XYZ"</syntaxhighlight>
var envvalue2 = osgetenv("EXO_ABC"); // "XYZ"</code></pre>
|-
</td></tr>
|var=||var().<em>ospid</em>()||Get the os process id
<tr><td>var=</td><td>var().<span class='gendoc_function'>ospid</span>()</td><td>Get the os process id
<syntaxhighlight lang="c++">
 
let pid1 = var().ospid(); /// e.g. 663237
<pre><code class='hljs-ncdecl language-javascript'>let pid1 = var().ospid(); /// e.g. 663237
// or
// or
let pid2 = ospid();</syntaxhighlight>
let pid2 = ospid();</code></pre>
|-
</td></tr>
|var=||var().<em>ostid</em>()||Get the os thread process id
<tr><td>var=</td><td>var().<span class='gendoc_function'>ostid</span>()</td><td>Get the os thread process id
<syntaxhighlight lang="c++">
 
let tid1 = var().ostid(); /// e.g. 663237
<pre><code class='hljs-ncdecl language-javascript'>let tid1 = var().ostid(); /// e.g. 663237
// or
// or
let tid2 = ostid();</syntaxhighlight>
let tid2 = ostid();</code></pre>
|-
</td></tr>
|var=||var().<em>version</em>()||Get the libexodus build date and time
<tr><td>var=</td><td>var().<span class='gendoc_function'>version</span>()</td><td>Get the libexodus build date and time
<syntaxhighlight lang="c++">
 
let v1 = var().version(); /// e.g. "29 JAN 2025 14:56:52"</syntaxhighlight>
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var().version(); /// e.g. "29 JAN 2025 14:56:52"</code></pre>
|-
</td></tr>
|if||strvar.<em>setxlocale</em>()||Sets the current thread's default locale codepage code</p>
<tr><td>if</td><td>strvar.<span class='gendoc_function'>setxlocale</span>()</td><td>Sets the current thread's default locale codepage code</p>
True if successful
True if successful
<syntaxhighlight lang="c++">
 
if ("en_US.utf8"_var.setxlocale()) ... ok
<pre><code class='hljs-ncdecl language-javascript'>if ("en_US.utf8"_var.setxlocale()) ... ok
// or
// or
if (setxlocale("en_US.utf8")) ... ok</syntaxhighlight>
if (setxlocale("en_US.utf8")) ... ok</code></pre>
|-
</td></tr>
|expr||var.<em>getxlocale</em>()||<em>Returns:</em> The current thread's default locale codepage code
<tr><td>var=</td><td>var.<span class='gendoc_function'>getxlocale</span>()</td><td><em>Returns:</em> The current thread's default locale codepage code
<syntaxhighlight lang="c++">
 
let v1 = var().getxlocale(); // "en_US.utf8"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var().getxlocale(); // "en_US.utf8"
// or
// or
let v2 = getxlocale();</syntaxhighlight>
let v2 = getxlocale();</code></pre>
|}
</td></tr>
===== Output =====
</table>
<h5 id=Output>Output</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>output</span>()</td><td>To stdout. No new line. Buffered.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>outputl</span>()</td><td>To stdout. Starts a new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>outputt</span>()</td><td>To stdout. Adds a tab. Buffered.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>logput</span>()</td><td>To stdlog. No new line. Buffered.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>logputl</span>()</td><td>To stdlog. Starts a new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>errput</span>()</td><td>To stderr. No new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>errputl</span>()</td><td>To stderr. Starts a new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>output</span>(prefix)</td><td>To stdout. With a prefix. No new line. Buffered.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>outputl</span>(prefix)</td><td>To stdout. With a prefix. Starts a new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>outputt</span>(prefix)</td><td>To stdout. With a prefix. Adds a tab. Buffered.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>logput</span>(prefix)</td><td>To stdlog. With a prefix. No new line. Buffered.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>logputl</span>(prefix)</td><td>To stdlog. With a prefix. Starts a new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>errput</span>(prefix)</td><td>To stderr. With a prefix. No new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>errputl</span>(prefix)</td><td>To stderr. With a prefix. Starts a new line. Flushed.</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>put</span>(std::ostream& ostream1)</td><td>Output to a given stream</td></tr>
<tr><td>cmd</td><td>var().<span class='gendoc_function'>osflush</span>()</td><td>Flushes any buffered output to stdout/cout


{|class="wikitable"
<pre><code class='hljs-ncdecl language-javascript'>var().osflush();
!Usage!!Function!!Description
|-
|expr||var.<em>output</em>()||To stdout. No new line. Buffered.
|-
|expr||var.<em>outputl</em>()||To stdout. Starts a new line. Flushed.
|-
|expr||var.<em>outputt</em>()||To stdout. Adds a tab. Buffered.
|-
|expr||var.<em>logput</em>()||To stdlog. No new line. Buffered.
|-
|expr||var.<em>logputl</em>()||To stdlog. Starts a new line. Flushed.
|-
|expr||var.<em>errput</em>()||To stderr. No new line. Flushed.
|-
|expr||var.<em>errputl</em>()||To stderr. Starts a new line. Flushed.
|-
|expr||var.<em>output</em>(prefix)||To stdout. With a prefix. No new line. Buffered.
|-
|expr||var.<em>outputl</em>(prefix)||To stdout. With a prefix. Starts a new line. Flushed.
|-
|expr||var.<em>outputt</em>(prefix)||To stdout. With a prefix. Adds a tab. Buffered.
|-
|expr||var.<em>logput</em>(prefix)||To stdlog. With a prefix. No new line. Buffered.
|-
|expr||var.<em>logputl</em>(prefix)||To stdlog. With a prefix. Starts a new line. Flushed.
|-
|expr||var.<em>errput</em>(prefix)||To stderr. With a prefix. No new line. Flushed.
|-
|expr||var.<em>errputl</em>(prefix)||To stderr. With a prefix. Starts a new line. Flushed.
|-
|expr||var.<em>put</em>(std::ostream& ostream1)||Output to a given stream
|-
|cmd||var().<em>osflush</em>()||Flushes any buffered output to stdout/cout
<syntaxhighlight lang="c++">
var().osflush();
// or
// or
osflush();</syntaxhighlight>
osflush();</code></pre>
|}
</td></tr>
===== Input =====
</table>
<h5 id=Input>Input</h5>
 
<table class=wikitable>
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>input</span>()</td><td>Wait for stdin until cr or eof</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>input</span>(prompt)</td><td>Ditto after outputting prompt to stdout</td></tr>
<tr><td>expr</td><td>var.<span class='gendoc_function'>inputn</span>(nchars)</td><td>Wait for nbytes from stdin</td></tr>
<tr><td>if</td><td>var.<span class='gendoc_function'>isterminal</span>()</td><td>True if terminal is available</td></tr>
<tr><td>if</td><td>var.<span class='gendoc_function'>hasinput</span>(milliseconds = 0)</td><td>True if stdin bytes available within milliseconds</td></tr>
<tr><td>if</td><td>var.<span class='gendoc_function'>eof</span>()</td><td>True if stdin is at end of file</td></tr>
<tr><td>if</td><td>var.<span class='gendoc_function'>echo</span>(on_off)</td><td>Reflect all stdin to stdout if terminal available</td></tr>
<tr><td>cmd</td><td>var.<span class='gendoc_function'>breakon</span>()</td><td>Allow interrupt Ctrl+C</td></tr>
<tr><td>cmd</td><td>var.<span class='gendoc_function'>breakoff</span>()</td><td>Prevent interrupt Ctr+C</td></tr>
</table>
<h5 id=Math/Boolean>Math/Boolean</h5>


{|class="wikitable"
<table class=wikitable>
!Usage!!Function!!Description
<tr> <th>Usage</th> <th>Function</th> <th>Description</th> </tr>
|-
<tr><td>var=</td><td>num.<span class='gendoc_function'>abs</span>()</td><td>Absolute value
|expr||var.<em>input</em>()||Wait for stdin until cr or eof
|-
|expr||var.<em>input</em>(prompt)||Ditto after outputting prompt to stdout
|-
|expr||var.<em>inputn</em>(nchars)||Wait for nbytes from stdin
|-
|if||var.<em>isterminal</em>()||True if terminal is available
|-
|if||var.<em>hasinput</em>(milliseconds = 0)||True if stdin bytes available within milliseconds
|-
|if||var.<em>eof</em>()||True if stdin is at end of file
|-
|if||var.<em>echo</em>(on_off)||Reflect all stdin to stdout if terminal available
|-
|cmd||var.<em>breakon</em>()||Allow interrupt Ctrl+C
|-
|cmd||var.<em>breakoff</em>()||Prevent interrupt Ctr+C
|}
===== Math/Boolean =====


{|class="wikitable"
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(-12.34).abs(); // 12.34
!Usage!!Function!!Description
|-
|var=||num.<em>abs</em>()||Absolute value
<syntaxhighlight lang="c++">
let v1 = var(-12.34).abs(); // 12.34
// or
// or
let v2 = abs(-12.34);</syntaxhighlight>
let v2 = abs(-12.34);</code></pre>
|-
</td></tr>
|var=||num.<em>pwr</em>(exponent)||Power
<tr><td>var=</td><td>num.<span class='gendoc_function'>pwr</span>(exponent)</td><td>Power
<syntaxhighlight lang="c++">
 
let v1 = var(2).pwr(8); // 256
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(2).pwr(8); // 256
// or
// or
let v2 = pwr(2, 8);</syntaxhighlight>
let v2 = pwr(2, 8);</code></pre>
|-
</td></tr>
|cmd||num.<em>initrnd</em>()||Initialise the seed for rnd()</p>
<tr><td>cmd</td><td>num.<span class='gendoc_function'>initrnd</span>()</td><td>Initialise the seed for rnd()</p>
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.</p>
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++">
 
var(123).initrnd(); /// Set seed to 123
<pre><code class='hljs-ncdecl language-javascript'>var(123).initrnd(); /// Set seed to 123
// or
// or
initrnd(123);</syntaxhighlight>
initrnd(123);</code></pre>
|-
</td></tr>
|var=||num.<em>rnd</em>()||Pseudo random number generator</p>
<tr><td>var=</td><td>num.<span class='gendoc_function'>rnd</span>()</td><td>Pseudo random number generator</p>
<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.</p>
Uses std::mt19937 and std::uniform_int_distribution<int>
Uses std::mt19937 and std::uniform_int_distribution<int>
<syntaxhighlight lang="c++">
 
let v1 = var(100).rnd().outputl();
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(100).rnd().outputl();
// or
// or
let v2 = rnd(100);</syntaxhighlight>
let v2 = rnd(100);</code></pre>
|-
</td></tr>
|var=||num.<em>exp</em>()||Power of e
<tr><td>var=</td><td>num.<span class='gendoc_function'>exp</span>()</td><td>Power of e
<syntaxhighlight lang="c++">
 
let v1 = var(1).exp(); // 2.718281828459045
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(1).exp(); // 2.718281828459045
// or
// or
let v2 = exp(1);</syntaxhighlight>
let v2 = exp(1);</code></pre>
|-
</td></tr>
|var=||num.<em>sqrt</em>()||Square root
<tr><td>var=</td><td>num.<span class='gendoc_function'>sqrt</span>()</td><td>Square root
<syntaxhighlight lang="c++">
 
let v1 = var(100).sqrt(); // 10
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(100).sqrt(); // 10
// or
// or
let v2 = sqrt(100);</syntaxhighlight>
let v2 = sqrt(100);</code></pre>
|-
</td></tr>
|var=||num.<em>sin</em>()||Sine of degrees
<tr><td>var=</td><td>num.<span class='gendoc_function'>sin</span>()</td><td>Sine of degrees
<syntaxhighlight lang="c++">
 
let v1 = var(30).sin(); // 0.5
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(30).sin(); // 0.5
// or
// or
let v2 = sin(30);</syntaxhighlight>
let v2 = sin(30);</code></pre>
|-
</td></tr>
|var=||num.<em>cos</em>()||Cosine of degrees
<tr><td>var=</td><td>num.<span class='gendoc_function'>cos</span>()</td><td>Cosine of degrees
<syntaxhighlight lang="c++">
 
let v1 = var(60).cos(); // 0.5
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(60).cos(); // 0.5
// or
// or
let v2 = cos(60);</syntaxhighlight>
let v2 = cos(60);</code></pre>
|-
</td></tr>
|var=||num.<em>tan</em>()||Tangent of degrees
<tr><td>var=</td><td>num.<span class='gendoc_function'>tan</span>()</td><td>Tangent of degrees
<syntaxhighlight lang="c++">
 
let v1 = var(45).tan(); // 1
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(45).tan(); // 1
// or
// or
let v2 = tan(45);</syntaxhighlight>
let v2 = tan(45);</code></pre>
|-
</td></tr>
|var=||num.<em>atan</em>()||Arctangent of degrees
<tr><td>var=</td><td>num.<span class='gendoc_function'>atan</span>()</td><td>Arctangent of degrees
<syntaxhighlight lang="c++">
 
let v1 = var(1).atan(); // 45
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(1).atan(); // 45
// or
// or
let v2 = atan(1);</syntaxhighlight>
let v2 = atan(1);</code></pre>
|-
</td></tr>
|var=||num.<em>loge</em>()||Natural logarithm</p>
<tr><td>var=</td><td>num.<span class='gendoc_function'>loge</span>()</td><td>Natural logarithm</p>
<em>Returns:</em> Floating point ver (double)
<em>Returns:</em> Floating point ver (double)
<syntaxhighlight lang="c++">
 
let v1 = var(2.718281828459045).loge(); // 1
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(2.718281828459045).loge(); // 1
// or
// or
let v2 = loge(2.718281828459045);</syntaxhighlight>
let v2 = loge(2.718281828459045);</code></pre>
|-
</td></tr>
|var=||num.<em>integer</em>()||Truncate decimal numbers towards zero</p>
<tr><td>var=</td><td>num.<span class='gendoc_function'>integer</span>()</td><td>Truncate decimal numbers towards zero</p>
<em>Returns:</em> A var integer
<em>Returns:</em> A var integer
<syntaxhighlight lang="c++">
 
let v1 = var(2.9).integer(); // 2
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(2.9).integer(); // 2
// or
// or
let v2 = integer(2.9);
let v2 = integer(2.9);
Line 1,729: Line 1,869:
var v3 = var(-2.9).integer(); // -2
var v3 = var(-2.9).integer(); // -2
// or
// or
var v4 = integer(-2.9);</syntaxhighlight>
var v4 = integer(-2.9);</code></pre>
|-
</td></tr>
|var=||num.<em>floor</em>()||Truncate decimal numbers towards negative</p>
<tr><td>var=</td><td>num.<span class='gendoc_function'>floor</span>()</td><td>Truncate decimal numbers towards negative</p>
<em>Returns:</em> A var integer
<em>Returns:</em> A var integer
<syntaxhighlight lang="c++">
 
let v1 = var(2.9).floor(); // 2
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(2.9).floor(); // 2
// or
// or
let v2 = floor(2.9);
let v2 = floor(2.9);
Line 1,740: Line 1,880:
var v3 = var(-2.9).floor(); // -3
var v3 = var(-2.9).floor(); // -3
// or
// or
var v4 = floor(-2.9);</syntaxhighlight>
var v4 = floor(-2.9);</code></pre>
|-
</td></tr>
|var=||num.<em>mod</em>(modulus)||Modulus function</p>
<tr><td>var=</td><td>num.<span class='gendoc_function'>mod</span>(modulus)</td><td>Modulus function</p>
Identical to C++ % operator only for positive numbers and modulus</p>
Identical to C++ % operator only for positive numbers and modulus</p>
Negative denominators are considered as periodic with positiive numbers</p>
Negative denominators are considered as periodic with positiive numbers</p>
Line 1,748: Line 1,888:
Result is between (modulus, 0] if modulus is negative (symmetric)</p>
Result is between (modulus, 0] if modulus is negative (symmetric)</p>
Throws: VarDivideByZero if modulus is zero.</p>
Throws: VarDivideByZero if modulus is zero.</p>
Floating point works.</p>
Floating point works.
mod(11, 5); // 1</p>
 
mod(-11, 5); // 4</p>
<pre><code class='hljs-ncdecl language-javascript'>let v1 = var(11).mod(5); // 1
mod(11, -5); // -4</p>
mod(-11, -5); // -1
<syntaxhighlight lang="c++">
let v1 = var(11).mod(5); // 1
// or
// or
let v2 = mod(11, 5);</syntaxhighlight>
let v2 = mod(11, 5); // 1
|}
let v3 = mod(-11, 5); // 4
let v4 = mod(11, -5); // -4
let v5 = mod(-11, -5); // -1</code></pre>
</td></tr>
</table>

Revision as of 18:42, 10 February 2025

Complete List of Functions

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>

<style>

/* Change highlight.js comments from default grey to green */ .hljs-comment, .hljs-quote { color: #008000; /* This is green, you can adjust the shade as per your preference */ font-style: italic; /* Optional: You might want to keep comments italicized */ }

</style>

<script> //// Extend C++ language definition //const cppLanguage = hljs.getLanguage('cpp'); //if (cppLanguage) { // // Adding custom keywords // cppLanguage.keywords = { // ...cppLanguage.keywords, // keyword: cppLanguage.keywords.keyword + ' round chr textchr', // // You can also add to other categories like 'literal', 'built_in', etc. // }; // // Register the modified language // hljs.registerLanguage('cpp', cppLanguage); //}

// Initialize highlight.js document.addEventListener('DOMContentLoaded', (event) => { hljs.highlightAll(); }); </script>


<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">

<style>

body { margin: 10px; }

pre { margin: 0px; white-space: pre-wrap; word-wrap: break-word; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; overflow-wrap: break-word; overflow-x: auto; }

table, th, td { border: 1px solid #a2a9b1; }

th { background-color: #eaecf0; font-weight: bold; text-align: left; padding: 8px; }

td { padding: 0.2em 0.4em; vertical-align: top; }

p {

 margin: 0.4em 0 0.5em 0;

}

.toc, .toccolours { border: 1px solid #a2a9b1; background-color: #f8f9fa; padding: 5px; font-size: 95%; } .toc { display: table; padding: 7px; }

.wikitable { background-color: #f8f9fa; color: #202122; margin: 1em 0; border: 1px solid #a2a9b1; border-collapse: collapse; }

   img {
       border: 0;
       vertical-align: middle
   }
   hr {
       height: 1px;
       background-color: #a2a9b1;
       border: 0;
       margin: 0.2em 0
   }
   h1,h2,h3,h4,h5,h6 {
       color: #000;
       margin: 0;
       padding-top: 0.5em;
       padding-bottom: 0.17em;
       overflow: hidden
   }
   h1,h2 {
       margin-bottom: 0.6em;
       border-bottom: 1px solid #a2a9b1
   }
   h3,h4,h5 {
       margin-bottom: 0.3em
   }
   h1 {
       font-size: 188%;
       font-weight: normal
   }
   h2 {
       font-size: 150%;
       font-weight: normal
   }
   h3 {
       font-size: 128%
   }
   h4 {
       font-size: 116%
   }
   h5 {
       font-size: 108%
   }
   h6 {
       font-size: 100%
   }
   p {
       margin: 0.4em 0 0.5em 0
   }
   p img {
       margin: 0
   }
   ul {
       margin: 0.3em 0 0 1.6em;
       padding: 0
   }
   ol {
       margin: 0.3em 0 0 3.2em;
       padding: 0;
       list-style-image: none
   }
   li {
       margin-bottom: 0.1em
   }
   dt {
       font-weight: bold;
       margin-bottom: 0.1em
   }
   dl {
       margin-top: 0.2em;
       margin-bottom: 0.5em
   }
   dd {
       margin-left: 1.6em;
       margin-bottom: 0.1em
   }

.gendoc_function {

   color: #800;
   font-weight: 700;

}

</style>


Contents:

  1. <a href=#String_Creation>String Creation</a>
  2. <a href=#String_Scanning>String Scanning</a>
  3. <a href=#String_Conversion_-_Non-Mutating_-_Chainable>String Conversion - Non-Mutating - Chainable</a>
  4. <a href=#String_Conversion_-_Mutating_-_Standalone_Commands>String Conversion - Mutating - Standalone Commands</a>
  5. <a href=#I/O_Conversion>I/O Conversion</a>
  6. <a href=#Dynamic_Array_Functions>Dynamic Array Functions</a>
  7. <a href=#Dynamic_Array_Filters>Dynamic Array Filters</a>
  8. <a href=#Dynamic_Array_Mutators_Standalone_Commands>Dynamic Array Mutators Standalone Commands</a>
  9. <a href=#Dynamic_Array_Search>Dynamic Array Search</a>
  10. <a href=#Database_Access>Database Access</a>
  11. <a href=#Database_Management>Database Management</a>
  12. <a href=#Database_File_I/O>Database File I/O</a>
  13. <a href=#Database_Sort/Select>Database Sort/Select</a>
  14. <a href=#OS_Time/Date>OS Time/Date</a>
  15. <a href=#OS_File_I/O>OS File I/O</a>
  16. <a href=#OS_Directories>OS Directories</a>
  17. <a href=#OS_Shell/Environment>OS Shell/Environment</a>
  18. <a href=#Output>Output</a>
  19. <a href=#Input>Input</a>
  20. <a href=#Math/Boolean>Math/Boolean</a>

Generated by cli/gendoc from var.h 10 FEB 2025 18:41:41

String Creation
Usage Function Description
var=num.round(ndecimals = 0)Returns: A string representation of a decimal number rounded to a desired number of decimal places

Returns: A var ASCII string with exact decimal places requested.

.5 always rounds away from zero.

<code class='hljs-ncdecl language-javascript'>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"</code>
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 so cannot be written to database or used various exodus string operations

<code class='hljs-ncdecl language-javascript'>let v1 = var().chr(0x61); // "a"
// or
let v2 = chr(0x61);</code>
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

Not providing implicit constructor from var to unsigned int due to getting ambigious conversions

since int and unsigned int are parallel priority in c++ implicit conversions

<code class='hljs-ncdecl language-javascript'>let v1 = var().textchr(171416); // "𩶘" // or "\xF0A9B698"
// or
let v2 = textchr(171416);</code>
var=var().str(num)Returns: A string of repeating characters or strings
<code class='hljs-ncdecl language-javascript'>let v1 = "ab"_var.str(3); // "ababab"
// or
let v2 = str("ab", 3);</code>
var=num.space()Returns: A string of space characters.
<code class='hljs-ncdecl language-javascript'>let v1 = var(3).space(); // "␣␣␣"
// or
let v2 = space(3);</code>
var=num.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.

<code class='hljs-ncdecl language-javascript'>let softhyphen = "\xc2\xad";
let v1 = var(123.45).numberinwords("de_DE").replace(softhyphen, " "); // "ein␣hundert␣drei␣und␣zwanzig␣Komma␣vier␣fünf"</code>
String Scanning
Usage Function Description
var=strvar.seq()Returns: The character number of the first char.
<code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.seq(); // 0x61 // decimal 97
// or
let v2 = seq("abc");</code>
var=strvar.textseq()Returns: The Unicode character number of the first unicode code point.
<code class='hljs-ncdecl language-javascript'>let v1 = "Γ"_var.textseq(); // 915 // U+0393: Greek Capital Letter Gamma (Unicode Character)
// or
let v2 = textseq("Γ");</code>
var=strvar.len()Returns: The length of a string in number of chars
<code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.len(); // 3
// or
let v2 = len("abc");</code>
var=strvar.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

<code class='hljs-ncdecl language-javascript'>let v1 = "🤡x🤡"_var.textwidth(); // 5
// or
let v2 = textwidth("🤡x🤡");</code>
var=strvar.textlen()Returns: The number of Unicode code points
<code class='hljs-ncdecl language-javascript'>let v1 = "Γιάννης"_var.textlen(); // 7
// or
let v2 = textlen("Γιάννης");</code>
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>let v1 = "aa**cc"_var.fcount("*"); // 3
// or
let v2 = fcount("aa**cc", "*");</code>
var=strvar.count(sepstr)Returns: The count of the number of sepstr found.
<code class='hljs-ncdecl language-javascript'>let v1 = "aa**cc"_var.count("*"); // 2
// or
let v2 = count("aa**cc", "*");</code>
ifstrvar.starts(prefix)Returns: True if starts with prefix
<code class='hljs-ncdecl language-javascript'>if ("abc"_var.starts("ab")) ... true
// or
if (starts("abc", "ab")) ... true</code>
ifstrvar.ends(suffix)Returns: True if ends with suffix
<code class='hljs-ncdecl language-javascript'>if ("abc"_var.ends("bc")) ... true
// or
if (ends("abc", "bc")) ... true</code>
ifstrvar.contains(substr)Returns: True if starts, ends or contains substr
<code class='hljs-ncdecl language-javascript'>if ("abcd"_var.contains("bc")) ... true
// or
if (contains("abcd", "bc")) ... true</code>
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.index("bc"); // 2
// or
let v2 = index("abcd", "bc");</code>
var=strvar.indexn(substr, occurrence)Returns: The index (1 based position) of the nth occurrence of a given substr if present

Returns: 0 if not present.

<code class='hljs-ncdecl language-javascript'>let v1 = "abcabc"_var.index("bc", 2); // 2
// or
let v2 = index("abcabc", "bc", 2);</code>
var=strvar.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).

<code class='hljs-ncdecl language-javascript'>let v1 = "abcabc"_var.indexr("bc"); // 5
// or
let v2 = indexr("abcabc", "bc");</code>
var=strvar.match(regex_str, regex_options = "")Returns: All results of regex matching

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

<code class='hljs-ncdecl language-javascript'>let v1 = "abc1abc2"_var.match("BC(\\d)", "i"); // "bc1]1^bc2]2"_var
// or
let v2 = match("abc1abc2", "BC(\\d)", "i");</code>
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=strvar.match(regex)Ditto
var=strvar.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()

<code class='hljs-ncdecl language-javascript'>var startchar1 = 1;
let v1 = "abc1abc2"_var.search("BC(\\d)", startchar1, "i"); // "bc1]1"_var // startchar1.outputl() -> 5 /// Ready for the next search
// or
startchar1 = 1;
let v2 = search("abc1abc2", "BC(\\d)", startchar1, "i");</code>
var=strvar.search(regex_str)Ditto starting from first char
var=strvar.search(regex, io startchar1)Ditto given a rex
var=strvar.search(regex)Ditto starting from first char.
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>let v1 = "abc"_var.hash(); assert(v1 == var(6'715'211'243'465'481'821));
// or
let v2 = hash("abc");</code>
String Conversion - Non-Mutating - Chainable
Usage Function Description
var=strvar.ucase()To upper case
<code class='hljs-ncdecl language-javascript'>let v1 = "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"
// or
let v2 = ucase("Γιάννης");</code>
var=strvar.lcase()To lower case
<code class='hljs-ncdecl language-javascript'>let v1 = "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"
// or
let v2 = lcase("ΓΙΆΝΝΗΣ");</code>
var=strvar.tcase()To title case (first letters are capitalised)
<code class='hljs-ncdecl language-javascript'>let v1 = "γιάννης"_var.tcase(); // "Γιάννης"
// or
let v2 = tcase("γιάννης");</code>
var=strvar.fcase()To folded case (lower case and remove accents for indexing)
var=strvar.normalize()Normalises unicode code points sequences to their standardised NFC form making them binary comparable.
var=strvar.invert()Simple reversible disguising of text

invert(invert()) returns to original.

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

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

<code class='hljs-ncdecl language-javascript'>let v1 = "aa*bb*cc"_var.field2("*", -1); // "cc"
// or
let v2 = field2("aa*bb*cc", "*", -1);</code>
var=strvar.fieldstore(separator, fieldno, nfields, replacement)fieldstore() replaces n fields of subfield(s) in a string.
<code class='hljs-ncdecl language-javascript'>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");</code>

If nfields is 0 then insert fields before fieldno

<code class='hljs-ncdecl language-javascript'>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");</code>

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

<code class='hljs-ncdecl language-javascript'>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");</code>
var=strvar.substr(pos1, length)substr version 1. Extract length chars starting at pos1
<code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.substr(2, 2); // "bc"
// or
let v2 = substr("abcd", 2, 2);</code>

If length is negative then work backwards and return chars reversed

<code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.substr(3, -2); // "cb"
// or
let v2 = substr("abcd", 3, -2);</code>
var=strvar.b(pos1, length)Same as substr version 1.
var=strvar.substr(pos1)substr version 2. Extract all chars from pos1 up to the end
<code class='hljs-ncdecl language-javascript'>let v1 = "abcd"_var.substr(2); // "bcd"
// or
let v2 = substr("abcd", 2);</code>
var=strvar.b(pos1)Same as substr version 2.
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>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);</code>
var=strvar.b(pos1, delimiterchars, io pos2)Alias of substr version 3.
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>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);</code>
var=strvar.b2(io pos1, out delimiterno)Alias of substr version 4
var=strvar.convert(fromchars, tochars)Convert chars to other chars one for one or delete where tochars is shorter.
<code class='hljs-ncdecl language-javascript'>let v1 = "abcde"_var.convert("aZd", "XY"); // "Xbce" // a is replaced and d is removed
// or
let v2 = convert("abcde", "aZd", "XY");</code>
var=strvar.textconvert(fromchars, tochars)Ditto for Unicode code points.
<code class='hljs-ncdecl language-javascript'>let v1 = "a🤡b😀c🌍d"_var.textconvert("🤡😀", "👋"); // "a👋bc🌍d"
// or
let v2 = textconvert("a🤡b😀c🌍d", "🤡😀", "👋");</code>
var=strvar.replace(fromstr, tostr)Replace all occurrences of a substr with another. Case sensitive
<code class='hljs-ncdecl language-javascript'>let v1 = "Abc.Abc"_var.replace("bc", "X"); // "AX.AX"
// or
let v2 = replace("Abc Abc", "bc", "X");</code>
var=strvar.replace(regex, tostr)Replace substring(s) using a regular expression.

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

<code class='hljs-ncdecl language-javascript'>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'");</code>
var=strvar.unique()Remove duplicate fields in an FM or VM etc. separated list
<code class='hljs-ncdecl language-javascript'>let v1 = "a1^b2^a1^c2"_var.unique(); // "a1^b2^c2"_var
// or
let v2 = unique("a1^b2^a1^c2"_var);</code>
var=strvar.sort(sepchar = FM)Reorder fields in an FM or VM etc. separated list in ascending order

Numerical:

<code class='hljs-ncdecl language-javascript'>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);</code>

Alphabetical:

<code class='hljs-ncdecl language-javascript'>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);</code>
var=strvar.reverse(sepchar = FM)Reorder fields in an FM or VM etc. separated list in descending order
<code class='hljs-ncdecl language-javascript'>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);</code>
var=strvar.shuffle(sepchar = FM)Randomise the order of fields in an FM, VM separated list
<code class='hljs-ncdecl language-javascript'>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);</code>
var=strvar.parse(char sepchar = ' ')Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes \" \'
<code class='hljs-ncdecl language-javascript'>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", ',');</code>
String Conversion - Mutating - Standalone Commands
Usage Function Description
cmdstrvar.ucaser()Upper case

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

<code class='hljs-ncdecl language-javascript'>var v1 = "abc";
v1.ucaser(); // "ABC"
// or
ucaser(v1);</code>
cmdstrvar.lcaser()
cmdstrvar.tcaser()
cmdstrvar.fcaser()
cmdstrvar.normalizer()
cmdstrvar.inverter()
cmdstrvar.quoter()
cmdstrvar.squoter()
cmdstrvar.unquoter()
cmdstrvar.lowerer()
cmdstrvar.raiser()
cmdstrvar.cropper()
cmdstrvar.trimmer(trimchars = " ")
cmdstrvar.trimmerfirst(trimchars = " ")
cmdstrvar.trimmerlast(trimchars = " ")
cmdstrvar.trimmerboth(trimchars = " ")
cmdstrvar.firster()
cmdstrvar.laster()
cmdstrvar.firster(std::size_t length)
cmdstrvar.laster(std::size_t length)
cmdstrvar.cutter(length)
cmdstrvar.paster(pos1, length, insertstr)
cmdstrvar.paster(pos1, insertstr)
cmdstrvar.prefixer(insertstr)
cmdstrvar.appender(appendable, ...)
cmdstrvar.popper()
cmdstrvar.fieldstorer(sepchar, fieldno, nfields, replacement)
cmdstrvar.substrer(pos1, length)
cmdstrvar.substrer(pos1)
cmdstrvar.converter(fromchars, tochars)
cmdstrvar.textconverter(fromchars, tochars)
cmdstrvar.replacer(regex, tostr)
cmdstrvar.replacer(fromstr, tostr)
cmdstrvar.uniquer()
cmdstrvar.sorter(sepchar = FM)
cmdstrvar.reverser(sepchar = FM)
cmdstrvar.shuffler(sepchar = FM)
cmdstrvar.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

<code class='hljs-ncdecl language-javascript'>let v1 = var(30123).oconv("D/E"); // "21/06/2050"
// or
let v2 = oconv(30123, "D/E");</code>
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

<code class='hljs-ncdecl language-javascript'>let v1 = "21 JUN 2050"_var.iconv("D/E"); // 30123
// or
let v2 = iconv("21 JUN 2050", "D/E");</code>
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.

<code class='hljs-ncdecl language-javascript'>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));</code>
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>let v1 = "\xa4"_var.from_codepage("CP1124"); // "Є"
// or
let v2 = from_codepage("\xa4", "CP1124");
// U+0404 Cyrillic Capital Letter Ukrainian Ie Unicode Character</code>
var=strvar.to_codepage(codepage)Converts to codepage encoded text from UTF-8 encoded text
<code class='hljs-ncdecl language-javascript'>let v1 = "Є"_var.to_codepage("CP1124").oconv("HEX"); // "A4"
// or
let v2 = to_codepage("Є", "CP1124").oconv("HEX");</code>
Dynamic Array Functions
Usage Function Description
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>let v1 = "f1^f2v1]f2v2]f2v3^f2"_var;
let v2 = v1.f(2, 2); // "f2v2"</code>
var=strvar.extract(fieldno, valueno = 0, subvalueno = 0)Extract a specific field, value or subvalue from a dynamic array.
<code class='hljs-ncdecl language-javascript'>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);</code>
var=strvar.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=strvar.pickreplace(fieldno, valueno, replacement)Ditto for a specific multivalue
var=strvar.pickreplace(fieldno, replacement)Ditto for a specific field
var=strvar.insert(fieldno, valueno, subvalueno, insertion)Same as var.inserter() function but returns a new string instead of updating a variable in place.
var=strvar.insert(fieldno, valueno, insertion)Ditto for a specific multivalue
var=strvar.insert(fieldno, insertion)Ditto for a specific field
var=strvar.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=strvar.sum()Sum up multiple values into one higher level
<code class='hljs-ncdecl language-javascript'>let v1 = "1]2]3^4]5]6"_var.sum(); // "6^15"_var
// or
let v2 = sum("1]2]3^4]5]6"_var);</code>
var=strvar.sumall()Sum up all levels into a single figure
<code class='hljs-ncdecl language-javascript'>let v1 = "1]2]3^4]5]6"_var.sumall(); // 21
// or
let v2 = sumall("1]2]3^4]5]6"_var);</code>
var=strvar.sum(sepchar)Ditto allowing commas etc.
<code class='hljs-ncdecl language-javascript'>let v1 = "10,20,30"_var.sum(","); // 60
// or
let v2 = sum("10,20,30", ",");</code>
var=strvar.mv(opcode, var2)Binary ops (+, -, *, /) in parallel on multiple values
<code class='hljs-ncdecl language-javascript'>let v1 = "10]20]30"_var.mv("+","2]3]4"_var); // "12]23]34"_var</code>
Dynamic Array Mutators Standalone Commands
Usage Function Description
cmdstrvar.r(fieldno, replacement)Replaces a specific field in a dynamic array
<code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, "X"); // "f1^X^f3"_var</code>
cmdstrvar.r(fieldno, valueno, replacement)Ditto for specific value in a specific field.
<code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, 2, "X"); // "f1^v1]X^f3"_var</code>
cmdstrvar.r(fieldno, valueno, subvalueno, replacement)Ditto for a specific subvalue in a specific value of a specific field
<code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.r(2, 2, 2, "X"); // "f1^v1]v2}X}s3^f3"_var</code>
cmdstrvar.inserter(fieldno, insertion)Insert a specific field in a dynamic array, moving all other fields up.
<code class='hljs-ncdecl language-javascript'>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");</code>
cmdstrvar.inserter(fieldno, valueno, insertion)Ditto for a specific value in a specific field, moving all other values up.
<code class='hljs-ncdecl language-javascript'>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");</code>
cmdstrvar.inserter(fieldno, valueno, subvalueno, insertion)Ditto for a specific subvalue in a dynamic array, moving all other subvalues up.
<code class='hljs-ncdecl language-javascript'>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");</code>
cmdstrvar.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.
<code class='hljs-ncdecl language-javascript'>var v1 = "f1^v1]v2}s2}s3^f3"_var;
v1.remover(2, 2); // "f1^v1^f3"_var
// or
remover(v1, 2, 2);</code>
Usage Function Description
var=strvar.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.

<code class='hljs-ncdecl language-javascript'>if ("UK^US^UA"_var.locate("US")) ... ok // 2
// or
if (locate("US", "UK^US^UA"_var)) ... ok</code>
ifstrvar.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

<code class='hljs-ncdecl language-javascript'>var setting;
if ("UK]US]UA"_var.locate("US", setting)) ... ok // setting -> 2
// or
if (locate("US", "UK]US]UA"_var, setting)) ... ok</code>
ifstrvar.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.

<code class='hljs-ncdecl language-javascript'>var setting;
if ("f1^f2v1]f2v2]s1}s2}s3}s4^f3^f4"_var.locate("s4", setting, 2, 3)) ... ok // setting -> 4 // returns true</code>
ifstrvar.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.

<code class='hljs-ncdecl language-javascript'>var valueno; if ("aaa]bbb]ccc"_var.locateby("AL", "bb", valueno)) ... // valueno -> 2 // returns false and valueno = where it could be correctly inserted.</code>
ifstrvar.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.
<code class='hljs-ncdecl language-javascript'>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.</code>
ifstrvar.locateusing(usingchar, target)locate() a target substr in the whole unordered string using a given delimiter char returning true if found.
<code class='hljs-ncdecl language-javascript'>if ("AB,EF,CD"_var.locateusing(",", "EF")) ... ok</code>
ifstrvar.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.

<code class='hljs-ncdecl language-javascript'>var setting;
if ("f1^f2^f3c1,f3c2,f3c3^f4"_var.locateusing(",", "f3c2", setting, 3)) ... ok // setting -> 2 // returns true</code>
ifstrvar.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
ifconn.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.

<code class='hljs-ncdecl language-javascript'>let conninfo = "dbname=exodus user=exodus password=somesillysecret";
if (not conn.connect(conninfo)) ...;
// or
if (not connect()) ...
// or
if (not connect("exodus")) ...</code>
ifconn.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

<code class='hljs-ncdecl language-javascript'>let filenames = "definitions^dict.definitions"_var, conn = "exodus";
if (conn.attach(filenames)) ... ok
// or
if (attach(filenames)) ... ok</code>
cmdconn.detach(filenames)Detach (disconnect) files that have been attached using attach().
ifconn.begintrans()Begin a db transaction.
<code class='hljs-ncdecl language-javascript'>if (not conn.begintrans()) ...
// or
if (not begintrans()) ...</code>
ifconn.statustrans()Check if a db transaction is in progress.
<code class='hljs-ncdecl language-javascript'>if (conn.statustrans()) ... ok
// or
if (statustrans()) ... ok</code>
ifconn.rollbacktrans()Rollback a db transaction.
<code class='hljs-ncdecl language-javascript'>if (conn.rollbacktrans()) ... ok
// or
if (rollbacktrans()) ... ok</code>
ifconn.committrans()Commit a db transaction.

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

<code class='hljs-ncdecl language-javascript'>if (conn.committrans()) ... ok
// or
if (committrans()) ... ok</code>
ifconn.sqlexec(sqlcmd)Execute an sql command.

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

<code class='hljs-ncdecl language-javascript'>if (conn.sqlexec("vacuum")) ... ok
// or
if (sqlexec("vacuum")) ... ok</code>
ifconn.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.

<code class='hljs-ncdecl language-javascript'>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</code>
cmdconn.disconnect()Closes db connection and frees process resources both locally and in the database server.
<code class='hljs-ncdecl language-javascript'>conn.disconnect();
// or
disconnect();</code>
cmdconn.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.

<code class='hljs-ncdecl language-javascript'>conn.disconnectall();
// or
disconnectall();</code>
var=conn.lasterror()Returns: The last os or db error message.
<code class='hljs-ncdecl language-javascript'>var v1 = var().lasterror();
// or
var v2 = lasterror();</code>
var=conn.loglasterror(source = "")Log the last os or db error message.

Output: to stdlog

Prefixes the output with source if provided.

<code class='hljs-ncdecl language-javascript'>var().loglasterror("main:");
// or
loglasterror("main:");</code>
Database Management
Usage Function Description
ifconn.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.

<code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (not dbdelete("xo_gendoc_testdb")) {}; // Cleanup first
if (conn.dbcreate("xo_gendoc_testdb")) ... ok
// or
if (dbcreate("xo_gendoc_testdb")) ...</code>
ifconn.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.

<code class='hljs-ncdecl language-javascript'>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")) ...</code>
var=conn.dblist()Returns: A list of available databases on a particular connection.
<code class='hljs-ncdecl language-javascript'>let v1 = conn.dblist();
// or
let v2 = dblist();</code>
ifconn.dbdelete(dbname)Delete (drop) a named database.

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

<code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (conn.dbdelete("xo_gendoc_testdb2")) ... ok
// or
if (dbdelete("xo_gendoc_testdb2")) ...</code>
ifconn.createfile(filename)Create a named db file.
<code class='hljs-ncdecl language-javascript'>let filename = "xo_gendoc_temp", conn = "exodus";
if (conn.createfile(filename)) ... ok
// or
if (createfile(filename)) ...</code>
ifconn.renamefile(filename, newfilename)Rename a db file.
<code class='hljs-ncdecl language-javascript'>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)) ...</code>
var=conn.listfiles()Returns: A list of all files in a database
<code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (not conn.listfiles()) ...
// or
if (not listfiles()) ...</code>
ifconn.clearfile(filename)Delete all records in a db file
<code class='hljs-ncdecl language-javascript'>let conn = "exodus", filename = "xo_gendoc_temp2";
if (not conn.clearfile(filename)) ...
// or
if (not clearfile(filename)) ...</code>
ifconn.deletefile(filename)Delete a db file
<code class='hljs-ncdecl language-javascript'>let conn = "exodus", filename = "xo_gendoc_temp2";
if (conn.deletefile(filename)) ... ok
// or
if (deletefile(filename)) ...</code>
var=conn_or_file.reccount(filename = "")Returns: The approx. number of records in a db file
<code class='hljs-ncdecl language-javascript'>let conn = "exodus", filename = "xo_clients";
var nrecs1 = conn.reccount(filename);
// or
var nrecs2 = reccount(filename);</code>
ifconn_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
iffile.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.
<code class='hljs-ncdecl language-javascript'>var file, filename = "definitions";
if (not file.open(filename)) ...
// or
if (not open(filename to file)) ...</code>
cmdfile.close()Closes db file var

Does nothing currently since database file vars consume no resources

<code class='hljs-ncdecl language-javascript'>var file = "definitions";
file.close();
// or
close(file);</code>
iffile.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.
<code class='hljs-ncdecl language-javascript'>var filename = "definitions", fieldname = "DATE_TIME";
if (not deleteindex("definitions", "DATE_TIME")) {}; // Cleanup first
if (filename.createindex(fieldname)) ... ok
// or
if (createindex(filename, fieldname)) ...</code>
var=file|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

<code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (conn.listindex()) ... ok // includes "xo_clients__date_time"
// or
if (listindex()) ... ok</code>
iffile.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
<code class='hljs-ncdecl language-javascript'>var file = "definitions", fieldname = "DATE_TIME";
if (file.deleteindex(fieldname)) ... ok
// or
if (deleteindex(file, fieldname)) ...</code>
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.
<code class='hljs-ncdecl language-javascript'>var file = "xo_clients", key = "1000";
if (file.lock(key)) ... ok
// or
if (lock(file, key)) ...</code>
iffile.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.

<code class='hljs-ncdecl language-javascript'>var file = "xo_clients", key = "1000";
if (file.unlock(key)) ... ok
// or
if (unlock(file, key)) ...</code>
iffile.unlockall()Removes all db locks placed by the lock function in the specified connection.

Locks cannot be removed while in a transaction.

<code class='hljs-ncdecl language-javascript'>var conn = "exodus";
if (not conn.unlockall()) ...
// or
if (not unlockall(conn)) ...</code>
cmdrec.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.

<code class='hljs-ncdecl language-javascript'>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);</code>
ifrec.read(file, key)Reads a record from a db file for a given key.

Returns: False if the key doesnt exist

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
iffile.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.

<code class='hljs-ncdecl language-javascript'>let file = "xo_clients", key = "GD001";
if (file.deleterecord(key)) ... ok
// or
if (deleterecord(file, key)) ...</code>
ifrec.insertrecord(file, key)Inserts a new record in a db file.

Returns: False if the key already exists

Any memory cached record is deleted.

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
ifrec.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.

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
ifstrvar.readf(file, key, fieldno)"Read field" Same as read() but only returns a specific field from the record
<code class='hljs-ncdecl language-javascript'>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)) ...</code>
cmdstrvar.writef(file, key, fieldno)"write field" Same as write() but only writes to a specific field in the record
<code class='hljs-ncdecl language-javascript'>var field = "f3", file = "definitions", key = "1000", fieldno = 3;
field.writef(file, key, fieldno);
// or
writef(field on file, key, fieldno);</code>
cmdrec.writec(file, key)"Write cache" Writes a record and key into a memory cached "db file".

The actual 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.

<code class='hljs-ncdecl language-javascript'>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);</code>
ifrec.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.

<code class='hljs-ncdecl language-javascript'>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 file by using read() not readc()
if (read(rec from file, key)) abort("Error: " ^ key ^ " should not be in the actual file"); // error</code>
ifdbfile.deletec(key)Deletes a record and key from a memory cached "file".

The actual file is NOT updated.

Returns: False if the key doesnt exist

<code class='hljs-ncdecl language-javascript'>var file = "xo_clients", key = "XD001";
if (file.deletec(key)) ... ok
// or
if (deletec(file, key)) ...</code>
cmdconn.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.

<code class='hljs-ncdecl language-javascript'>conn.cleardbcache();
// or
cleardbcache(conn);</code>
var=strvar.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:

str: 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.
<code class='hljs-ncdecl language-javascript'>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)"</code>
Database Sort/Select
Usage Function Description
iffile.select(sortselectclause = "")
cmdfile.clearselect()
iffile.hasnext()
iffile.readnext(out key)
iffile.readnext(out key, out valueno)
iffile.readnext(out record, out key, out valueno)
iffile.savelist(listname)
iffile.getlist(listname)
iffile.makelist(listname, keys)
iffile.deletelist(listname)
iffile.formlist(keys, fieldno = 0)
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

<code class='hljs-ncdecl language-javascript'>let today1 = var().date();
// or
let today2 = date();</code>
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.

<code class='hljs-ncdecl language-javascript'>let now1 = var().time();
// or
let now2 = time();</code>
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

<code class='hljs-ncdecl language-javascript'>let now1 = var().ostime();
// or
let now2 = ostime();</code>
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

<code class='hljs-ncdecl language-javascript'>let now1 = var().timestamp();
// or
let now2 = timestamp();</code>
var=var().timestamp(ostime)Construct a timestamp from a date and time
<code class='hljs-ncdecl language-javascript'>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);</code>
cmdvar().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.

<code class='hljs-ncdecl language-javascript'>var().ossleep(500); // sleep for 500ms
// or
ossleep(500);</code>
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.

<code class='hljs-ncdecl language-javascript'>let v1 = ".^/etc/hosts"_var.oswait(500); /// e.g. "IN_CLOSE_WRITE^/etc^hosts^f"_var
// or
let v2 = oswait(".^/etc/hosts"_var, 500);</code>
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
ifosfilevar.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.

<code class='hljs-ncdecl language-javascript'>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</code>
ifosfilevar.osbwrite(osfilevar, io offset)Writes data to an existing os file starting at a given byte offset (0 based).

See osbread for more info.

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
ifosfilevar.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.

<code class='hljs-ncdecl language-javascript'>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</code>
cmdosfilevar.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.

<code class='hljs-ncdecl language-javascript'>osfilevar.osclose();
// or
osclose(osfilevar);</code>
ifstrvar.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.

<code class='hljs-ncdecl language-javascript'>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</code>
ifstrvar.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.

<code class='hljs-ncdecl language-javascript'>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</code>
ifosfile_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.

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
ifosfile_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.

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
ifosfile_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

<code class='hljs-ncdecl language-javascript'>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</code>
ifosfilename.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.

<code class='hljs-ncdecl language-javascript'>let osfilename = ostempdirpath() ^ "xo_gendoc_test.conf";
if (osfilename.osremove()) ... ok
// or
if (osremove(osfilename)) ...</code>
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.

<code class='hljs-ncdecl language-javascript'>var entries1 = "/etc/"_var.oslist("*.cfg"); /// e.g. "adduser.conf^ca-certificates.con^... etc."
// or
var entries2 = oslist("/etc/" "*.conf");</code>
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()

<code class='hljs-ncdecl language-javascript'>var info1 = "/etc/hosts"_var.osinfo(); /// e.g. "221^20597^78309"_var
// or
var info2 = osinfo("/etc/hosts");</code>
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)

<code class='hljs-ncdecl language-javascript'>var fileinfo1 = "/etc/hosts"_var.osfile(); /// e.g. "221^20597^78309"_var
// or
var fileinfo2 = osfile("/etc/hosts");</code>
var=dirpath.osdir()Returns: Dir info for a dir.

A short string containing FM ^ modified_time ^ FM ^ modified_time

Alias for osinfo(2)

<code class='hljs-ncdecl language-javascript'>var dirinfo1 = "/etc/"_var.osdir(); /// e.g. "^20848^44464"_var
// or
var dirinfo2 = osfile("/etc/");</code>
ifdirpath.osmkdir()Makes a new directory and returns true if successful.

Including parent dirs if necessary.

<code class='hljs-ncdecl language-javascript'>let osdirname = "xo_test/aaa";
if (osrmdir("xo_test/aaa")) {}; // Cleanup first
if (osdirname.osmkdir()) ... ok
// or
if (osmkdir(osdirname)) ...</code>
ifdirpath.oscwd(newpath)Changes the current working dir and returns true if successful.
<code class='hljs-ncdecl language-javascript'>let osdirname = "xo_test/aaa";
if (osdirname.oscwd()) ... ok
// or
if (oscwd(osdirname)) ... ok</code>
var=dirpath.oscwd()Returns: The current working directory

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

<code class='hljs-ncdecl language-javascript'>var cwd1 = var().oscwd();
// or
var cwd2 = oscwd();</code>
ifdirpath.osrmdir(evenifnotempty = false)Removes a os dir and returns true if successful.

Optionally even if not empty. Including subdirs.

<code class='hljs-ncdecl language-javascript'>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)) ...</code>
OS Shell/Environment
Usage Function Description
ifcommand.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.

<code class='hljs-ncdecl language-javascript'>let cmd = "echo $HOME";
if (cmd.osshell()) ... ok
// or
if (osshell(cmd)) ... ok</code>
ifinstr.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.

<code class='hljs-ncdecl language-javascript'>let cmd = "echo $HOME";
var text;
if (text.osshellread(cmd)) ... ok

// or capturing stdout but ignoring exit status
text = osshellread(cmd);</code>
ifoutstr.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.

<code class='hljs-ncdecl language-javascript'>let outtext = "abc xyz";
if (outtext.osshellwrite("grep xyz")) ... ok
// or
if (osshellwrite(outtext, "grep xyz")) ... ok</code>
var=var().ostempdirpath()Returns: The path of the tmp dir

e.g. "/tmp/"

<code class='hljs-ncdecl language-javascript'>let v1 = var().ostempdirpath();
// or
let v2 = ostempdirpath();</code>
var=var().ostempfilename()Returns: The name of a new temporary file

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

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

True if successful

<code class='hljs-ncdecl language-javascript'>if ("en_US.utf8"_var.setxlocale()) ... ok
// or
if (setxlocale("en_US.utf8")) ... ok</code>
var=var.getxlocale()Returns: The current thread's default locale codepage code
<code class='hljs-ncdecl language-javascript'>let v1 = var().getxlocale(); // "en_US.utf8"
// or
let v2 = getxlocale();</code>
Output
Usage Function Description
exprvar.output()To stdout. No new line. Buffered.
exprvar.outputl()To stdout. Starts a new line. Flushed.
exprvar.outputt()To stdout. Adds a tab. Buffered.
exprvar.logput()To stdlog. No new line. Buffered.
exprvar.logputl()To stdlog. Starts a new line. Flushed.
exprvar.errput()To stderr. No new line. Flushed.
exprvar.errputl()To stderr. Starts a new line. Flushed.
exprvar.output(prefix)To stdout. With a prefix. No new line. Buffered.
exprvar.outputl(prefix)To stdout. With a prefix. Starts a new line. Flushed.
exprvar.outputt(prefix)To stdout. With a prefix. Adds a tab. Buffered.
exprvar.logput(prefix)To stdlog. With a prefix. No new line. Buffered.
exprvar.logputl(prefix)To stdlog. With a prefix. Starts a new line. Flushed.
exprvar.errput(prefix)To stderr. With a prefix. No new line. Flushed.
exprvar.errputl(prefix)To stderr. With a prefix. Starts a new line. Flushed.
exprvar.put(std::ostream& ostream1)Output to a given stream
cmdvar().osflush()Flushes any buffered output to stdout/cout
<code class='hljs-ncdecl language-javascript'>var().osflush();
// or
osflush();</code>
Input
Usage Function Description
exprvar.input()Wait for stdin until cr or eof
exprvar.input(prompt)Ditto after outputting prompt to stdout
exprvar.inputn(nchars)Wait for nbytes from stdin
ifvar.isterminal()True if terminal is available
ifvar.hasinput(milliseconds = 0)True if stdin bytes available within milliseconds
ifvar.eof()True if stdin is at end of file
ifvar.echo(on_off)Reflect all stdin to stdout if terminal available
cmdvar.breakon()Allow interrupt Ctrl+C
cmdvar.breakoff()Prevent interrupt Ctr+C
Math/Boolean
Usage Function Description
var=num.abs()Absolute value
<code class='hljs-ncdecl language-javascript'>let v1 = var(-12.34).abs(); // 12.34
// or
let v2 = abs(-12.34);</code>
var=num.pwr(exponent)Power
<code class='hljs-ncdecl language-javascript'>let v1 = var(2).pwr(8); // 256
// or
let v2 = pwr(2, 8);</code>
cmdnum.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;

<code class='hljs-ncdecl language-javascript'>var(123).initrnd(); /// Set seed to 123
// or
initrnd(123);</code>
var=num.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>

<code class='hljs-ncdecl language-javascript'>let v1 = var(100).rnd().outputl();
// or
let v2 = rnd(100);</code>
var=num.exp()Power of e
<code class='hljs-ncdecl language-javascript'>let v1 = var(1).exp(); // 2.718281828459045
// or
let v2 = exp(1);</code>
var=num.sqrt()Square root
<code class='hljs-ncdecl language-javascript'>let v1 = var(100).sqrt(); // 10
// or
let v2 = sqrt(100);</code>
var=num.sin()Sine of degrees
<code class='hljs-ncdecl language-javascript'>let v1 = var(30).sin(); // 0.5
// or
let v2 = sin(30);</code>
var=num.cos()Cosine of degrees
<code class='hljs-ncdecl language-javascript'>let v1 = var(60).cos(); // 0.5
// or
let v2 = cos(60);</code>
var=num.tan()Tangent of degrees
<code class='hljs-ncdecl language-javascript'>let v1 = var(45).tan(); // 1
// or
let v2 = tan(45);</code>
var=num.atan()Arctangent of degrees
<code class='hljs-ncdecl language-javascript'>let v1 = var(1).atan(); // 45
// or
let v2 = atan(1);</code>
var=num.loge()Natural logarithm

Returns: Floating point ver (double)

<code class='hljs-ncdecl language-javascript'>let v1 = var(2.718281828459045).loge(); // 1
// or
let v2 = loge(2.718281828459045);</code>
var=num.integer()Truncate decimal numbers towards zero

Returns: A var integer

<code class='hljs-ncdecl language-javascript'>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);</code>
var=num.floor()Truncate decimal numbers towards negative

Returns: A var integer

<code class='hljs-ncdecl language-javascript'>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);</code>
var=num.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.

<code class='hljs-ncdecl language-javascript'>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</code>