|
|
Line 327: |
Line 327: |
| ==== Complete List of Functions ==== | | ==== Complete List of Functions ==== |
|
| |
|
| | | [[Functions|Complete List of Functions]] |
| Generated by cli/gendoc from var.h at 29JAN2025 8:13PM
| |
| | |
| ===== Math/Boolean =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||num.<em>abs</em>()||Absolute value
| |
| <syntaxhighlight lang="c++">
| |
| var(-12.34).abs(); // 12.34</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>pwr</em>(exponent)||Power
| |
| <syntaxhighlight lang="c++">
| |
| var(2).pwr(8); // 256</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>rnd</em>()||Pseudo random number generator
| |
| <syntaxhighlight lang="c++">
| |
| var(100).rnd(); // 0 to 99 pseudo random</syntaxhighlight>
| |
| |-
| |
| |cmd||num.<em>initrnd</em>()||Initialise the seed for rnd()
| |
| <syntaxhighlight lang="c++">
| |
| var(123).initrnd(); // Set seed to 123</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>exp</em>()||Power of e
| |
| <syntaxhighlight lang="c++">
| |
| var(1).exp(); // 2.718281828459045</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>sqrt</em>()||Square root
| |
| <syntaxhighlight lang="c++">
| |
| var(100).sqrt(); // 10</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>sin</em>()||Sine of degrees
| |
| <syntaxhighlight lang="c++">
| |
| var(30).sin(); // 0.5</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>cos</em>()||Cosine of degrees
| |
| <syntaxhighlight lang="c++">
| |
| var(60).cos(); // 0.5</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>tan</em>()||Tangent of degrees
| |
| <syntaxhighlight lang="c++">
| |
| var(45).tan(); // 1</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>atan</em>()||Arctangent of degrees
| |
| <syntaxhighlight lang="c++">
| |
| var(1).atan(); // 45</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>loge</em>()||Natural logarithm
| |
| <syntaxhighlight lang="c++">
| |
| var(2.718281828459045).loge(); // 1</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>integer</em>()||Truncate decimal numbers towards zero.
| |
| <syntaxhighlight lang="c++">
| |
| var(2.9).integer(); // 2
| |
| var(-2.9).integer(); // -2</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>floor</em>()||Truncate decimal numbers towards negative
| |
| <syntaxhighlight lang="c++">
| |
| var(2.9).floor(); // 2
| |
| var(-2.9).floor(); // -3</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>round</em>(ndecimals = 0)||Round decimal numbers to a desired number of decimal places<br>
| |
| .5 always rounds away from zero.
| |
| <syntaxhighlight lang="c++">
| |
| var(0.455).round(2); // "0.46"
| |
| var(-0.455).round(2); // "-0.46"
| |
| var(1.455).round(2); // "1.46"
| |
| var(-1.455).round(2); // "-1.46"</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>mod</em>(divisor)||
| |
| |}
| |
| | |
| | |
| ===== Locale =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |expr||var.<em>getxlocale</em>()||Gets the current thread's default locale codepage code
| |
| <syntaxhighlight lang="c++">
| |
| var().getxlocale(); // e.g. "en_US.utf8"
| |
| getxlocale(); // ditto</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>setxlocale</em>()||Sets the current thread's default locale codepage code<br>
| |
| <syntaxhighlight lang="c++">
| |
| if (not "de_DE.utf8"_var.setxlocale()) ... // true if successful
| |
| if (setxlocale("de_DE.utf8")) ... // ditto</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== String Creation =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||var.<em>chr</em>(num)||Create a string of a single char (byte) given an integer 0-255.<br>
| |
| 0-127 -> ASCII, 128-255 -> invalid UTF-8 so cannot be written to database or used various exodus string operations
| |
| <syntaxhighlight lang="c++">
| |
| var().chr(0x61); // "a"
| |
| chr(0x61); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>textchr</em>(num)||Create a string of a single unicode code point in utf8 encoding.<br>
| |
| To get utf codepoints > 2^63 you must provide negative ints<br>
| |
| Not providing implicit constructor from var to unsigned int due to getting ambigious conversions<br>
| |
| since int and unsigned int are parallel priority in c++ implicit conversions
| |
| <syntaxhighlight lang="c++">
| |
| var().textchr(171416); // "𩶘" or "\xF0A9B698"
| |
| textchr(171416); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>str</em>(num)||Create a string by repeating a given character or string
| |
| <syntaxhighlight lang="c++">
| |
| "ab"_var.str(3); // "ababab"
| |
| str("ab"_var, 3); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>space</em>()||Create string of space characters.<br>
| |
| <syntaxhighlight lang="c++">
| |
| var(3).space(); // "␣␣␣"
| |
| space(3); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||num.<em>numberinwords</em>(languagename_or_locale_id = "")||Create a string describing a given number in words<br>
| |
| <syntaxhighlight lang="c++">
| |
| var(123.45).numberinwords("de_DE");
| |
| //"einhundertdreiundzwanzig Komma vier fünf"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== String Scanning =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||str.<em>seq</em>()||Returns the character number of the first char.
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.seq(); // 0x61 97
| |
| seq("abc"_var); // 0x61 97</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>textseq</em>()||Returns the Unicode character number of the first unicode code point.
| |
| <syntaxhighlight lang="c++">
| |
| "Γ"_var.textseq(); // 915 U+0393: Greek Capital Letter Gamma (Unicode Character)
| |
| textseq("Γ"); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>len</em>()||Returns the length of a string in number of chars
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.len(); // 3
| |
| len("abc"_var); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>textwidth</em>()||Returns the number of output columns.<br>
| |
| Allows multi column unicode and reduces combining characters etc. like e followed by grave accent<br>
| |
| Possibly does not properly calculate combining sequences of graphemes e.g. face followed by colour
| |
| <syntaxhighlight lang="c++">
| |
| "🤡x🤡"_var.textwidth(); // 5
| |
| textwidth("🤡x🤡"_var); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>textlen</em>()||Returns the number of Unicode code points
| |
| <syntaxhighlight lang="c++">
| |
| "Γιάννης"_var.textlen(); // 7
| |
| textlen("Γιάννης"_var); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>fcount</em>(sepstr)||Returns the number of fields separated by sepstr present.<br>
| |
| It is the same as var.count(sepstr) + 1 except that and empty string returns 0
| |
| <syntaxhighlight lang="c++">
| |
| "a1**c3"_var.fcount("*"); // 3
| |
| fcount("a1**c3"_var, "*"); // ditto</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>count</em>(sepstr)||Return the number of sepstr found
| |
| <syntaxhighlight lang="c++">
| |
| "a1*b2*c3"_var.count("*"); // 3
| |
| count("a1*b2*c3"_var, "*"); // ditto</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>starts</em>(prefix)||Returns true if starts with prefix
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.starts("ab"); // true</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>ends</em>(suffix)||Returns true if ends with suffix
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.ends("bc"); // true</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>contains</em>(substr)||Returns true if starts, ends or contains substr
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.contains("bc"); // true</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>index</em>(substr, startchar1 = 1)||Returns char no if found or 0 if not. startchar1 is byte no to start at.
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.index("bc"); // 2</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>indexn</em>(substr, occurrence)||ditto. Occurrence 1 = find first occurrence
| |
| <syntaxhighlight lang="c++">
| |
| "abcabc"_var.index("bc", 2); // 5</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>indexr</em>(substr, startchar1 = -1)||ditto. Reverse search.<br>
| |
| startchar1 defaults to -1 meaning start searching from the last byte
| |
| <syntaxhighlight lang="c++">
| |
| "abcabc"_var.indexr("bc"); // 5</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>match</em>(regex, regex_options = "")||Returns all results of regex matching<br>
| |
| Multiple matches are in fields. Groups are in values
| |
| <syntaxhighlight lang="c++">
| |
| "abc1abc2"_var.match("bc(\\d)"); // "bc1]1^bc2]2"</syntaxhighlight>
| |
| regex_options:<br>
| |
| <br>
| |
| l - Literal (any regex chars are treated as normal chars)<br>
| |
| <br>
| |
| i - Case insensitive<br>
| |
| <br>
| |
| p - ECMAScript/Perl (the default)<br>
| |
| b - Basic POSIX (same as sed)<br>
| |
| e - Extended POSIX<br>
| |
| a - awk<br>
| |
| g - grep<br>
| |
| eg - egrep or grep -E<br>
| |
| <br>
| |
| char ranges like a-z are locale sensitive if ECMAScript<br>
| |
| <br>
| |
| m - Multiline. Default in boost (and therefore exodus)<br>
| |
| s - Single line. Default in std::regex<br>
| |
| <br>
| |
| f - First only. Only for replace() (not match() or search())<br>
| |
| <br>
| |
| w - Wildcard glob style (e.g. *.cfg) not regex style. Only for match() and search(). Not replace().
| |
| |-
| |
| |var=||str.<em>match</em>(regex)||Ditto
| |
| |-
| |
| |var=||str.<em>search</em>(regex, io startchar1, regex_options = "")||Search for first match of a regular expression starting at startchar1<br>
| |
| Updates startchar1 ready to search for the next match<br>
| |
| regex_options as for match()
| |
| <syntaxhighlight lang="c++">
| |
| var startchar1 = 1;
| |
| "abc1abc2"_var.search("bc(\\d)", startchar1); // returns "bc1]1"
| |
| // startchar1 becomes 5 ready for the next search</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>search</em>(regex)||Ditto starting from first char
| |
| |-
| |
| |var=||str.<em>search</em>(regex, io startchar1)||Ditto given a rex
| |
| |-
| |
| |var=||str.<em>search</em>(regex)||Ditto starting from first char.
| |
| |}
| |
| | |
| | |
| ===== String Conversion - Chainable. Non-Mutating =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||str.<em>ucase</em>()||Upper case
| |
| <syntaxhighlight lang="c++">
| |
| "Γιάννης"_var.ucase(); // "ΓΙΆΝΝΗΣ"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>lcase</em>()||Lower case
| |
| <syntaxhighlight lang="c++">
| |
| "ΓΙΆΝΝΗΣ"_var.lcase(); // "γιάννης"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>tcase</em>()||Title case (first letters)
| |
| <syntaxhighlight lang="c++">
| |
| "γιάννης"_var.tcase(); // "Γιάννης"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>fcase</em>()||Fold case (lower case and remove accents for indexing)
| |
| |-
| |
| |var=||str.<em>normalize</em>()||Normalise Unicode to NFC to eliminate different code combinations of the same character
| |
| |-
| |
| |var=||str.<em>invert</em>()||Simple reversible disguising of text
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.invert(); // "\x{C29EC29DC29C}"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>lower</em>()||Convert all FM to VM, VM to SM etc.
| |
| <syntaxhighlight lang="c++">
| |
| "a1^b2^c3"_var.lower(); // "a1]b2]c3"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>raise</em>()||Convert all VM to FM, SM to VM etc.
| |
| <syntaxhighlight lang="c++">
| |
| "a1]b2]c3"_var.raise(); // "a1^b2^c3"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>crop</em>()||Remove any redundant FM, VM etc. characters (Trailing FM; VM before FM etc.)
| |
| <syntaxhighlight lang="c++">
| |
| "a1^b2]]^c3^^"_var.crop(); // "a1^b2^c3"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>quote</em>()||Wrap in double quotes
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.quote(); // ""abc""</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>squote</em>()||Wrap in single quotes
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.squote(); // "'abc'"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>unquote</em>()||Remove one pair of double or single quotes
| |
| <syntaxhighlight lang="c++">
| |
| "'abc'"_var.unquote(); // "abc"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>trim</em>(trimchars = " ")||Remove leading, trailing and excessive inner bytes
| |
| <syntaxhighlight lang="c++">
| |
| "␣␣a1␣␣b2␣c3␣␣"_var.trim(); // "a1␣b2␣c3"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>trimfirst</em>(trimchars = " ")||Ditto leading
| |
| <syntaxhighlight lang="c++">
| |
| "␣␣a1␣␣b2␣c3␣␣"_var.trimfirst(); // "a1␣␣b2␣c3␣␣"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>trimlast</em>(trimchars = " ")||Ditto trailing
| |
| <syntaxhighlight lang="c++">
| |
| "␣␣a1␣␣b2␣c3␣␣"_var.trimlast(); // "␣␣a1␣␣b2␣c3"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>trimboth</em>(trimchars = " ")||Ditto leading, trailing but not inner
| |
| <syntaxhighlight lang="c++">
| |
| "␣␣a1␣␣b2␣c3␣␣"_var.trimboth(); // "a1␣␣b2␣c3"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>first</em>()||Extract first char or "" if empty
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.first(); // "a"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>last</em>()||Extract last char or "" if empty
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.last(); // "c"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>first</em>(std::size_t length)||Extract up to length leading chars
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.first(2); // "ab"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>last</em>(std::size_t length)||Extract up to length trailing chars
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.last(2); // "bc"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>cut</em>(length)||Remove length leading chars
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.cut(2); // "cd"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>paste</em>(pos1, length, insertstr)||Insert text at char position overwriting length chars
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.paste(2, 2, "XYZ"); // "aXYZd"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>paste</em>(pos1, insertstr)||Insert text at char position without overwriting any following characters
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.paste(2, "XYZ"); // "aXYbcd"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>prefix</em>(insertstr)||Insert text at the beginning
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.prefix("XY"); // "XYabc"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>pop</em>()||Remove one trailing char
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.pop(); // "ab"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>fieldstore</em>(separator, fieldno, nfields, replacement)||fieldstore() replaces nfields of subfield(s) in a string.
| |
| <syntaxhighlight lang="c++">
| |
| "aa*bb*cc*dd"_var.fieldstore("*", 2, 3, "X*Y"); // "aa*X*Y*"</syntaxhighlight>
| |
| If nfields is 0 then insert fields before fieldno
| |
| <syntaxhighlight lang="c++">
| |
| "a1*b2*c3*d4"_var.fieldstore("*", 2, 0, "X*Y"); // "a1*X*Y*b2*c3*d4"</syntaxhighlight>
| |
| If nfields is negative then delete nfields before inserting.
| |
| <syntaxhighlight lang="c++">
| |
| "a1*b2*c3*d4"_var.fieldstore("*", 2, -3, "X*Y"); // "a1*X*Y"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>substr</em>(pos1, length)||substr version 1. Extract length chars starting at pos1
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.substr(2, 2); // "bc"</syntaxhighlight>
| |
| If length is negative then work backwards and return chars reversed
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.substr(3, -2); // "cb"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>substr</em>(pos1)||substr version 2. Extract all chars from pos1 up to the end
| |
| <syntaxhighlight lang="c++">
| |
| "abcd"_var.substr(2); // "bcd"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>b</em>(pos1, length)||Same as substr version 1.
| |
| |-
| |
| |var=||str.<em>b</em>(pos1)||Same as substr version 2.
| |
| |-
| |
| |var=||str.<em>convert</em>(fromchars, tochars)||Convert chars to other chars one for one or delete where tochars is shorter.
| |
| <syntaxhighlight lang="c++">
| |
| "abcde"_var.convert("aZd", "XY"); // "Xbce" (a is replaced and d is removed)</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>textconvert</em>(fromchars, tochars)||Ditto for Unicode code points.
| |
| <syntaxhighlight lang="c++">
| |
| "a🤡b😀c🌍d"_var.textconvert("🤡😀", "👋"); // "a👋bc🌍d"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>replace</em>(fromstr, tostr)||Replace all occurrences of a substr with another. Case sensitive
| |
| <syntaxhighlight lang="c++">
| |
| "Abc Abc"_var.replace("bc", "X"); // "AX AX"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>replace</em>(regex, tostr)||Replace substring(s) using a regular expression.<br>
| |
| Use $0, $1, $2 in tostr to refer to groups defined in the regex.
| |
| <syntaxhighlight lang="c++">
| |
| "A a B b"_var.replace("[A-Z]"_rex, "'$0'"); // "'A' a 'B' b"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>unique</em>()||Remove duplicate fields in an FM or VM etc. separated list
| |
| <syntaxhighlight lang="c++">
| |
| "a1^b2^a1^c2"_var.unique(); // "a1^b2^c2"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>sort</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in ascending order
| |
| <syntaxhighlight lang="c++">
| |
| "20^10^2^1^1.1"_var.sort(); // "1^1.1^2^10^20"</syntaxhighlight>
| |
| <syntaxhighlight lang="c++">
| |
| "b1^a1^c20^c10^c2^c1^b2"_var.sort(); // "a1^b1^b2^c1^c10^c2^c20"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>reverse</em>(sepchar = FM)||Reorder fields in an FM or VM etc. separated list in descending order
| |
| <syntaxhighlight lang="c++">
| |
| "20^10^2^1^1.1"_var.reverse(); // "1.1^1^2^10^20"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>shuffle</em>(sepchar = FM)||Randomise the order of fields in an FM, VM separated list
| |
| <syntaxhighlight lang="c++">
| |
| "20^10^2^1^1.1"_var.shuffle(); // "2^1^20^1.1^10" (random order depending on initrand())</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>parse</em>(char sepchar = ' ')||Replace separator characters with FM char except inside double or single quotes ignoring escaped quotes \\" \&squot;
| |
| <syntaxhighlight lang="c++">
| |
| "abc,\"def,\"123\" fgh\",12.34"_var.parse(','); // "abc^"def,"123" fgh"^12.34"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== String Mutators Not Chainable. All Similar To Non-Mutators =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |cmd||str.<em>ucaser</em>()||
| |
| |-
| |
| |cmd||str.<em>lcaser</em>()||
| |
| |-
| |
| |cmd||str.<em>tcaser</em>()||
| |
| |-
| |
| |cmd||str.<em>fcaser</em>()||
| |
| |-
| |
| |cmd||str.<em>normalizer</em>()||
| |
| |-
| |
| |cmd||str.<em>inverter</em>()||
| |
| |-
| |
| |cmd||str.<em>quoter</em>()||
| |
| |-
| |
| |cmd||str.<em>squoter</em>()||
| |
| |-
| |
| |cmd||str.<em>unquoter</em>()||
| |
| |-
| |
| |cmd||str.<em>lowerer</em>()||
| |
| |-
| |
| |cmd||str.<em>raiser</em>()||
| |
| |-
| |
| |cmd||str.<em>cropper</em>()||
| |
| |-
| |
| |cmd||str.<em>trimmer</em>(trimchars = " ")||
| |
| |-
| |
| |cmd||str.<em>trimmerfirst</em>(trimchars = " ")||
| |
| |-
| |
| |cmd||str.<em>trimmerlast</em>(trimchars = " ")||
| |
| |-
| |
| |cmd||str.<em>trimmerboth</em>(trimchars = " ")||
| |
| |-
| |
| |cmd||str.<em>firster</em>()||
| |
| |-
| |
| |cmd||str.<em>laster</em>()||
| |
| |-
| |
| |cmd||str.<em>firster</em>(std::size_t length)||
| |
| |-
| |
| |cmd||str.<em>laster</em>(std::size_t length)||
| |
| |-
| |
| |cmd||str.<em>cutter</em>(length)||
| |
| |-
| |
| |cmd||str.<em>paster</em>(pos1, length, insertstr)||
| |
| |-
| |
| |cmd||str.<em>paster</em>(pos1, insertstr)||
| |
| |-
| |
| |cmd||str.<em>prefixer</em>(insertstr)||
| |
| |-
| |
| |cmd||str.<em>popper</em>()||
| |
| |-
| |
| |cmd||str.<em>fieldstorer</em>(sepchar, fieldno, nfields, replacement)||
| |
| |-
| |
| |cmd||str.<em>substrer</em>(pos1, length)||
| |
| |-
| |
| |cmd||str.<em>substrer</em>(pos1)||
| |
| |-
| |
| |cmd||str.<em>converter</em>(fromchars, tochars)||
| |
| |-
| |
| |cmd||str.<em>textconverter</em>(fromchars, tochars)||
| |
| |-
| |
| |cmd||str.<em>replacer</em>(regex, tostr)||
| |
| |-
| |
| |cmd||str.<em>replacer</em>(fromstr, tostr)||
| |
| |-
| |
| |cmd||str.<em>uniquer</em>()||
| |
| |-
| |
| |cmd||str.<em>sorter</em>(sepchar = FM)||
| |
| |-
| |
| |cmd||str.<em>reverser</em>(sepchar = FM)||
| |
| |-
| |
| |cmd||str.<em>shuffler</em>(sepchar = FM)||
| |
| |-
| |
| |cmd||str.<em>parser</em>(char sepchar = ' ')||
| |
| |}
| |
| | |
| | |
| ===== Other String Access =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||str.<em>hash</em>(std::uint64_t modulus = 0)||MurmurHash3 hashing.
| |
| <syntaxhighlight lang="c++">
| |
| "abc"_var.hash(); // 6715211243465481821</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>substr</em>(pos1, delimiterchars, out pos2)||substr version 3.<br>
| |
| Extract a substr starting from pos1 up to any one of the given delimiter chars also returning the next pos1 after the delimiter found
| |
| |-
| |
| |var=||str.<em>b</em>(pos1, delimiterchars, out pos2)||Alias of substr version 3.
| |
| |-
| |
| |var=||str.<em>substr2</em>(io pos1, io delimiterno)||substr version 4.<br>
| |
| Returns a substr from a given pos1 up to the next RM/FM/VM/SM/TM/STM delimiter char. Also returns the next index/offset and the delimiter no. found 1-6 or 0 if not found.
| |
| |-
| |
| |var=||str.<em>b2</em>(io pos1, io delimiterno)||Alias of substr version 4
| |
| |-
| |
| |var=||str.<em>field</em>(strx, fieldnx = 1, nfieldsx = 1)||Extract one or more consecutive fields given a delimiter char or substr.
| |
| <syntaxhighlight lang="c++">
| |
| "aa*bb*cc"_var.field("*", 2);m // "bb"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>field2</em>(separator, fieldno, nfields = 1)||field2 is a version that treats fieldn -1 as the last field, -2 the penultimate field etc. -<br>
| |
| TODO Should probably make field() do this (since -1 is basically an erroneous call) and remove field2<br>
| |
| Same as var.field() but negative fieldnos work backwards from the last field.
| |
| <syntaxhighlight lang="c++">
| |
| "aa*bb*cc"_var.field("*", -1); // "cc"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== I/O Conversion =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||var.<em>oconv</em>(convstr)||Converts internal data to output external display format according to a given conversion code or pattern<br>
| |
| If the internal data is invalid and cannot be converted then most conversions return the ORIGINAL data unconverted<br>
| |
| Throws a runtime error VarNotImplemented if convstr is invalid<br>
| |
| See [[#ICONV/OCONV PATTERNS]]
| |
| <syntaxhighlight lang="c++">
| |
| var(30123).oconv("D/E"); // "21/06/2050"</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>iconv</em>(convstr)||Converts external data to internal format according to a given conversion code or pattern<br>
| |
| If the external data is invalid and cannot be converted then most conversions return the EMPTY STRING ""<br>
| |
| Throws a runtime error VarNotImplemented if convstr is invalid<br>
| |
| See [[#ICONV/OCONV PATTERNS]]
| |
| <syntaxhighlight lang="c++">
| |
| "21 JUN 2050"_var.iconv("D/E"); // 30123</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>format</em>(fmt_str, Args&&... args)||Classic format function in printf style<br>
| |
| vars can be formatted either with C++ format codes e.g. {:_>8.2f}<br>
| |
| or with exodus oconv codes e.g. {::MD20P|R(_)#8} as in the below example.
| |
| <syntaxhighlight lang="c++">
| |
| var(12.345).format("'{:_>8.2f}' should match '{::MD20P|R(_)#8}'", var(12.345));
| |
| // -> "'___12.35' should match '___12.35'"
| |
| | |
| // or
| |
| format("'{:_>8.2f}' should match '{::MD20P|R(_)#8}'", var(12.345), var(12.345));</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>from_codepage</em>(codepage)||Converts from codepage encoded text to UTF-8 encoded text<br>
| |
| e.g. Codepage "CP1124" (Ukrainian).<br>
| |
| Use Linux command "iconv -l" for complete list of code pages and encodings.
| |
| <syntaxhighlight lang="c++">
| |
| "\xa4"_var.from_codepage("CP1124"); // "Є"
| |
| // U+0404 Cyrillic Capital Letter Ukrainian Ie Unicode Character</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>to_codepage</em>(codepage)||Converts to codepage encoded text from UTF-8 encoded text
| |
| <syntaxhighlight lang="c++">
| |
| "Є"_var.to_codepage("CP1124").oconv("HEX"); // "A4"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== Basic Dynamic Array Functions =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||str.<em>f</em>(fieldno, valueno = 0, subvalueno = 0)||f() is a highly abbreviated alias for the PICK OS field/value/subvalue extract() function.<br>
| |
| "f()" can be thought of as "field" although the function can extract values and subvalues as well.<br>
| |
| The convenient PICK OS angle bracket syntax for field extraction (e.g. xxx<20>) is not available in C++.<br>
| |
| 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++">
| |
| "f1^f2v1]f2v2]f2v3^f2"_var.f(2, 2); // "f2v2"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>extract</em>(fieldno, valueno = 0, subvalueno = 0)||Extract a specific field, value or subvalue from a dynamic array.<br>
| |
| The alias "f" is usually used instead
| |
| |-
| |
| |var=||str.<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.
| |
| |-
| |
| |var=||str.<em>pickreplace</em>(fieldno, valueno, replacement)||Ditto for a specific multivalue
| |
| |-
| |
| |var=||str.<em>pickreplace</em>(fieldno, replacement)||Ditto for a specific field
| |
| |-
| |
| |var=||str.<em>insert</em>(fieldno, valueno, subvalueno, insertion)||Same as var.inserter() function but returns a new string instead of updating a variable in place.
| |
| |-
| |
| |var=||str.<em>insert</em>(fieldno, valueno, insertion)||Ditto for a specific multivalue
| |
| |-
| |
| |var=||str.<em>insert</em>(fieldno, insertion)||Ditto for a specific field
| |
| |-
| |
| |var=||str.<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.<br>
| |
| "remove" was called "delete" in Pick OS.
| |
| |}
| |
| | |
| | |
| ===== Dynamic Array Filters =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||str.<em>sum</em>()||Sum up multiple values into one higher level
| |
| <syntaxhighlight lang="c++">
| |
| "1]2]3^4]5]6"_var.sum(); // "6^15"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>sumall</em>()||Sum up all levels into a single figure
| |
| <syntaxhighlight lang="c++">
| |
| "1]2]3^4]5]6"_var.sumall(); // "21"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>sum</em>(sepchar)||Ditto allowing commas etc.
| |
| <syntaxhighlight lang="c++">
| |
| "10,20,33"_var.sum(","); // "60"</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>mv</em>(opcode, var2)||Binary ops (+, -, *, /) in parallel on multiple values
| |
| <syntaxhighlight lang="c++">
| |
| "10]20]30"_var.mv("+","2]3]4"); // "12]23]34"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== Dynamic Array Mutators (Standalone And Cannot Be Chained) =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |cmd||str.<em>r</em>(fieldno, replacement)||Replaces a specific field in a dynamic array
| |
| <syntaxhighlight lang="c++">
| |
| var v1 = "f1^v1]v2}s2}s3^f3"_var;
| |
| v1.r(2, 2, "X"); // v1 -> "f1^X^f3"</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<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"); // v1 -> "f1^v1]X^f3"</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<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"); // v1 -> "f1^v1]v2}X}s3^f3"</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<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"); // v1 -> "f1^X^v1]v2}s2}s3^f3"</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<em>inserter</em>(fieldno, valueno, insertion)||Ditto for a specific value in a specific field, moving all other fields up.
| |
| <syntaxhighlight lang="c++">
| |
| var v1 = "f1^v1]v2}s2}s3^f3"_var;
| |
| v1.inserter(2, 2, "X"); // v1 -> "f1^v1]X]v2}s2}s3^f3"</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<em>inserter</em>(fieldno, valueno, subvalueno, insertion)||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;
| |
| v1.inserter(2, 2, 2, "X"); // v1 -> "f1^v1]v2}X}s2}s3^f3"</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<em>remover</em>(fieldno, valueno = 0, subvalueno = 0)||Remove a specific field (or value, or subvalue) from a dynamic array, moving all other fields (or values, or subvalues) down.
| |
| <syntaxhighlight lang="c++">
| |
| var v1 = "f1^v1]v2}s2}s3^f3"_var;
| |
| v1.remover(2, 2); // v1 -> "f1^v1^f3"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== Dynamic Array Search =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||str.<em>locate</em>(target)||locate() with only the target substr argument provided searches unordered values separated by VM chars.<br>
| |
| Returns true if found and false if not.
| |
| <syntaxhighlight lang="c++">
| |
| if ("UK]US]UA"_var.locate("US")) ... // true</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>locate</em>(target, out valueno)||locate() with only the target substr and valueno arguments provided searches unordered values separated by VM chars.<br>
| |
| Returns true if found and with the value number in valueno.<br>
| |
| Returns false if not found and with the max value number + 1 in setting. Suitable for additiom of new values
| |
| <syntaxhighlight lang="c++">
| |
| var valueno; if ("UK]US]UA"_var.locate("US", valueno)) ... // returns true and valueno = 2</syntaxhighlight>
| |
| |-
| |
| |if||str.<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.<br>
| |
| Returns true if found and with the field, value or subvalue number in setting.<br>
| |
| 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.
| |
| <syntaxhighlight lang="c++">
| |
| var setting; if ("f1^f2v1]f2v2]s1}s2}s3}s4^f3^f4"_var.locate("s4", setting, 2, 3)) ... // returns true and setting = 4</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>locateby</em>(ordercode, target, out valueno)||locateby() without fieldno or valueno arguments searches ordered values separated by VM chars.<br>
| |
| The order code can be AL, DL, AR, DR meaning Ascending Left, Descending Right, Ascending Right, Ascending Left.<br>
| |
| Left is used to indicate alphabetic order where 10 < 2.<br>
| |
| Right is used to indicate numeric order where 10 > 2.<br>
| |
| Data must be in the correct order for searching to work properly.<br>
| |
| Returns true if found.<br>
| |
| 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)) ... // returns false and valueno = 2 where it could be correctly inserted.</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>locateby</em>(ordercode, target, out setting, fieldno, valueno = 0)||locateby() ordered as above but in fields if fieldno is 0, or values in a specific fieldno, or subvalues in a specific valueno.
| |
| <syntaxhighlight lang="c++">
| |
| var setting; if ("f1^f2^aaa]bbb]ccc^f4"_var.locateby("AL", "bb", setting, 3)) ... // returns false and setting = 2 where it could be correctly inserted.</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>locateusing</em>(usingchar, target)||locate() a target substr in the whole unordered string using a given delimiter char returning true if found.<br>
| |
| if (<syntaxhighlight lang="c++">
| |
| "AB,EF,CD"_var.locateusing(",", "EF")) ... // true</syntaxhighlight>
| |
| |-
| |
| |if||str.<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<br>
| |
| Returns true If found and returns in setting the number of the delimited field found.<br>
| |
| Returns false if not found and returns in setting the maximum number of delimited fields + 1 if not found.<br>
| |
| 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)) ... // returns true and setting = 2</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>locatebyusing</em>(ordercode, usingchar, target, out setting, fieldno = 0, valueno = 0, subvalueno = 0)||locatebyusing() supports all the above features in a single function.<br>
| |
| Returns true if found.
| |
| |}
| |
| | |
| | |
| ===== Database Access =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||conn.<em>connect</em>(conninfo = "")||For all db operations, var() can be db connection created with dbconnect() or any var will perform a default connection.<br>
| |
| The db connection string (conninfo) parameters are merged from the following places in descending priority.<br>
| |
| 1. Provided in connect()'s conninfo argument. See 4. for the complete list of parameters.<br>
| |
| 2. Any environment variables EXO_HOST EXO_PORT EXO_USER EXO_DATA EXO_PASS EXO_TIME<br>
| |
| 3. Any parameters found in a configuration file at ~/.config/exodus/exodus.cfg<br>
| |
| 4. The defaults "host=127.0.0.1 port=5432 dbname=exodus user=exodus password=somesillysecret connect_timeout=10"
| |
| <syntaxhighlight lang="c++">
| |
| var db="mydb";
| |
| if (not db.connect()) abort(db.lasterror());
| |
| db.version().outputl();
| |
| db.disconnect();</syntaxhighlight>
| |
| |-
| |
| |cmd||conn.<em>disconnect</em>()||Removes a db connection and frees resources.
| |
| |-
| |
| |cmd||conn.<em>disconnectall</em>()||Removes all db connection and frees resources.
| |
| |-
| |
| |if||conn.<em>attach</em>(filenames)||Attach (connect) specific files by name to specific connections.<br>
| |
| For the remainder of the session, opening the file by name will automatically use the specified connection.
| |
| |-
| |
| |cmd||conn.<em>detach</em>(filenames)||Detach (disconnect) files that have been attached using attach().
| |
| |-
| |
| |if||conn.<em>begintrans</em>()||Begin a db transaction.
| |
| |-
| |
| |if||conn.<em>rollbacktrans</em>()||Rollback a db transaction.
| |
| |-
| |
| |if||conn.<em>committrans</em>()||Commit a db transaction.
| |
| |-
| |
| |if||conn.<em>statustrans</em>()||Check if a db transaction is in progress.
| |
| |-
| |
| |if||conn.<em>sqlexec</em>(sqlcmd)||Execute an sql command.
| |
| |-
| |
| |if||conn.<em>sqlexec</em>(sqlcmd, io response)||Execute an SQL command and capture the response.
| |
| |-
| |
| |var=||conn.<em>lasterror</em>()||Get the last os or db error message.
| |
| |-
| |
| |var=||conn.<em>loglasterror</em>(source = "")||Log the last os or db error message.
| |
| |}
| |
| | |
| | |
| ===== Database Management =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||conn.<em>dbcreate</em>(dbname)||Create a named database on a particular connection.
| |
| |-
| |
| |var=||conn.<em>dblist</em>()||Return a list of available databases on a particular connection.
| |
| |-
| |
| |if||conn.<em>dbcopy</em>(from_dbname, to_dbname)||Create a named database from an existing database.
| |
| |-
| |
| |if||conn.<em>dbdelete</em>(dbname)||Delete (drop) a named database.
| |
| |-
| |
| |if||conn.<em>createfile</em>(filename)||Create a named db file.
| |
| |-
| |
| |if||conn.<em>renamefile</em>(filename, newfilename)||Rename a db file.
| |
| |-
| |
| |if||conn.<em>deletefile</em>(filename)||Delete (drop) a db file
| |
| |-
| |
| |if||conn.<em>clearfile</em>(filename)||Delete all records in a db file
| |
| |-
| |
| |var=||conn.<em>listfiles</em>()||Return a list of all files in a database
| |
| |-
| |
| |var=||conn.<em>reccount</em>(filename = "")||Returns the approx. number of records in a file
| |
| |-
| |
| |if||conn.<em>flushindex</em>(filename = "")||Calls db maintenance function (vacuum)<br>
| |
| This doesnt flush any indexes any longer but does make sure that reccount() function is reasonably accurate.
| |
| |}
| |
| | |
| | |
| ===== Database File I/O =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||file.<em>open</em>(dbfilename, connection = "")||
| |
| |-
| |
| |cmd||file.<em>close</em>()||
| |
| |-
| |
| |if||file.<em>createindex</em>(fieldname, dictfile = "")||
| |
| |-
| |
| |if||file.<em>deleteindex</em>(fieldname)||
| |
| |-
| |
| |var=||file.<em>listindex</em>(filename = "", fieldname = "")||
| |
| |-
| |
| |var=||file.<em>lock</em>(key)||Returns 1=ok, 0=failed, ""=already locked
| |
| |-
| |
| |if||file.<em>unlock</em>(key)||
| |
| |-
| |
| |if||file.<em>unlockall</em>()||
| |
| |-
| |
| |if||rec.<em>read</em>(file, key)||Reads a record from a file given its unique primary key.<br>
| |
| Returns false if the key doesnt exist
| |
| <syntaxhighlight lang="c++">
| |
| var rec; if (not rec.read(file, key)) ...</syntaxhighlight>
| |
| |-
| |
| |cmd||rec.<em>write</em>(file, key)||Writes a record to a file.<br>
| |
| It updates an existing record if the key already exists or inserts a new record.<br>
| |
| It always succeeds so no result code is returned.<br>
| |
| Any memory cached record is deleted.
| |
| <syntaxhighlight lang="c++">
| |
| rec.write(file, key);</syntaxhighlight>
| |
| |-
| |
| |if||rec.<em>updaterecord</em>(file, key)||Updates an existing record in a file.<br>
| |
| Returns false if the key doesnt already exist<br>
| |
| Any memory cached record is deleted.
| |
| <syntaxhighlight lang="c++">
| |
| if (not rec.updaterecord(file, key)) ...</syntaxhighlight>
| |
| |-
| |
| |if||rec.<em>insertrecord</em>(file, key)||Inserts a new record in a file.<br>
| |
| Returns false if the key already exists<br>
| |
| Any memory cached record is deleted.
| |
| <syntaxhighlight lang="c++">
| |
| if (not rec.insertrecord(file, key)) ...</syntaxhighlight>
| |
| |-
| |
| |if||file.<em>deleterecord</em>(key)||Deletes a record from a file given its key.<br>
| |
| Returns false if the key doesnt exist<br>
| |
| Any memory cached record is deleted.<br>
| |
| <syntaxhighlight lang="c++">
| |
| if (not file.deleterecord(key)) ...</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>readf</em>(file, key, fieldno)||Same as read() but only returns a specific field no from the record
| |
| <syntaxhighlight lang="c++">
| |
| var field; if (not field.readf(file, key, fieldno)) ...</syntaxhighlight>
| |
| |-
| |
| |cmd||str.<em>writef</em>(file, key, fieldno)||Same as write() but only writes a specific field no to the record
| |
| <syntaxhighlight lang="c++">
| |
| field.writef(file, key, fieldno);</syntaxhighlight>
| |
| |-
| |
| |if||rec.<em>readc</em>(file, key)||Cache read a record from a memory cache "file" given its key.<br>
| |
| 1. Tries to read from a memory cache and returns true if successful.<br>
| |
| 2. Reads to read from the actual file and returns false if unsuccessful.<br>
| |
| 3. Writes the record and key to the memory cache and returns true.<br>
| |
| Cached db file data lives in exodus process memory not the database.
| |
| <syntaxhighlight lang="c++">
| |
| var rec; if (not rec.readc(file, key)) ...</syntaxhighlight>
| |
| |-
| |
| |cmd||rec.<em>writec</em>(file, key)||Cache write a record and key into a memory cached "file".<br>
| |
| The actual file is NOT updated.<br>
| |
| It either updates an existing record if the key already exists or otherwise inserts a new record.<br>
| |
| It always succeeds so no result code is returned.
| |
| <syntaxhighlight lang="c++">
| |
| rec.writec(file, key);</syntaxhighlight>
| |
| |-
| |
| |if||dbfile.<em>deletec</em>(key)||Deletes a record and key from a memory cached "file".<br>
| |
| The actual file is NOT updated.<br>
| |
| Returns false if the key doesnt exist
| |
| <syntaxhighlight lang="c++">
| |
| if (not file.deletec(key)) ...</syntaxhighlight>
| |
| |-
| |
| |cmd||conn.<em>cleardbcache</em>()||Clears the memory cache of all records for the given connection<br>
| |
| 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();</syntaxhighlight>
| |
| |-
| |
| |var=||str.<em>xlate</em>(filename, fieldno, mode)||
| |
| |}
| |
| | |
| | |
| ===== Database Sort/Select =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||file.<em>select</em>(sortselectclause = "")||
| |
| |-
| |
| |cmd||file.<em>clearselect</em>()||
| |
| |-
| |
| |if||file.<em>hasnext</em>()||
| |
| |-
| |
| |if||file.<em>readnext</em>(out key)||
| |
| |-
| |
| |if||file.<em>readnext</em>(out key, out valueno)||
| |
| |-
| |
| |if||file.<em>readnext</em>(out record, out key, out valueno)||
| |
| |-
| |
| |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 =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||var.<em>date</em>()||Number of whole days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.
| |
| <syntaxhighlight lang="c++">
| |
| var today1 = var().date(); // e.g. was 20821 from 2025-01-01 00:00:00 UTC
| |
| // or just
| |
| var today2 = date();</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>time</em>()||Number of whole seconds since last 00:00:00 (UTC).
| |
| <syntaxhighlight lang="c++">
| |
| var now1 = var().time(); // range 0 - 86399 since there are 24*60*60 (86400) seconds in a day.
| |
| // or just
| |
| var now2 = time();</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>ostime</em>()||Number of fractional seconds since last 00:00:00 (UTC).<br>
| |
| A floating point with approx. nanosecond resolution depending on hardware.
| |
| <syntaxhighlight lang="c++">
| |
| var now1 = var().ostime(); // e.g. 23343.704387955 approx. 06:29:03 UTC
| |
| // or just
| |
| var now2 = ostime();</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>timestamp</em>()||Number of fractional days since pick epoch 1967-12-31 00:00:00 UTC. Negative for dates before.<br>
| |
| A floating point with approx. nanosecond resolution depending on hardware.
| |
| <syntaxhighlight lang="c++">
| |
| var now1 = var().timestamp(); // was 20821.99998842593 around 2025-01-01 23:59:59 UTC
| |
| // or just
| |
| var now2 = ostimestamp();</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>timestamp</em>(ostime)||Construct a timestamp from a date and time
| |
| <syntaxhighlight lang="c++">
| |
| var ts1 = var().timestamp(iconv("2025-01-01", "D"), iconv("23:59:59", "MT")); // 20821.99998842593
| |
| // or just
| |
| var ts2 = timestamp(somedate, sometime);</syntaxhighlight>
| |
| |-
| |
| |cmd||var.<em>ossleep</em>(milliseconds)||Sleep/pause/wait for a number of milliseconds
| |
| <syntaxhighlight lang="c++">
| |
| var().ossleep(3000); // sleep for 3 seconds
| |
| // or just
| |
| ossleep(3000);</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>oswait</em>(milliseconds, directory)||Sleep/pause/wait for any activity in a file system directory for a number of milliseconds
| |
| <syntaxhighlight lang="c++">
| |
| var().oswait(3000, "."); // max 3 seconds
| |
| // or just
| |
| oswait(3000, ".");</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== OS File Io =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||osfilevar.<em>osopen</em>(osfilename, locale = "")||Given the name of an existing file name including path, initialises a var that can be used in random access osbread and osbwrite functions.<br>
| |
| Optionally allows specifying a locale/codepage to which and from which all writes and reads will be converted (?) from a assumed internal UTF8 encoding.<br>
| |
| File will be opened for writing if possible otherwise for reading.<br>
| |
| Returns true if successful or false if not possible for any reason.<br>
| |
| e.g. Target doesnt exist, permissions etc.
| |
| <syntaxhighlight lang="c++">
| |
| var hostsfile;
| |
| if (not hostsfile.osopen("/etc/hosts") ...
| |
| // or
| |
| if (not osopen("/etc/hosts" to hostsfile) ...</syntaxhighlight>
| |
| |-
| |
| |if||osfilevar.<em>osbread</em>(osfilevar, io offset, length)||Reads length bytes from an existing os file starting at a given byte offset (0 based).<br>
| |
| The osfilevar file handle may either be initialised by osopen (optionally with a locale/codepage) or be just a normal string variable holding the path and name of the os file.<br>
| |
| After reading, the offset is updated to point to the correct offset for a subsequent sequential read.<br>
| |
| If reading utf8 data 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++">
| |
| var text, hostsfile = "/etc/hosts", offset = 0;
| |
| if (not text.osbread(hostsfile, offset, 1024) ...
| |
| // or
| |
| if (not osbread(text from hostsfile, offset, 1024) ...</syntaxhighlight>
| |
| |-
| |
| |if||osfilevar.<em>osbwrite</em>(osfilevar, io offset)||Writes data to an existing os file starting at a given byte offset (0 based).<br>
| |
| See osbread for more info.
| |
| <syntaxhighlight lang="c++">
| |
| let text = "\n#comment", xyzfile = "../xyz.conf";
| |
| var offset = osfile(xyzfile).f(1); // size of file -> append
| |
| if (not text.osbwrite(xyzfile, offset)) abort(lasterror());
| |
| // or
| |
| if (not osbwrite(text on xyzfile, offset) ...</syntaxhighlight>
| |
| |-
| |
| |cmd||osfilevar.<em>osclose</em>()||Removes an osfilevar handle from the internal memory cache of os file handles freeing up both exodus process memory and operating system resources.<br>
| |
| 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();
| |
| // or
| |
| osclose(osfilevar);</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>osread</em>(osfilename, codepage = "")||Read a complete os file into a var<br>
| |
| Returns true if successful or false if not possible for any reason.<br>
| |
| e.g. File doesnt exist, permissions etc.
| |
| <syntaxhighlight lang="c++">
| |
| var text;
| |
| if (not text.osread("/etc/hosts")) ...
| |
| // or
| |
| if (not osread(text from "/etc/hosts")) ...</syntaxhighlight>
| |
| |-
| |
| |if||str.<em>oswrite</em>(osfilename, codepage = "")||Create a complete os file from a var.<br>
| |
| Any existing file is removed first.<br>
| |
| Returns true if successful or false if not possible for any reason.<br>
| |
| e.g. Path is not writeable, permissions etc.
| |
| <syntaxhighlight lang="c++">
| |
| let text = "xyz = 123\n", osfilename="../xyz.conf";
| |
| if (not text.oswrite(osfilename)) abort(lasterror());
| |
| // or
| |
| if (not oswrite(text on osfilename)) ...</syntaxhighlight>
| |
| |-
| |
| |if||osfilename.<em>osremove</em>()||Removes/deletes an os file from the OS file system given path and name.<br>
| |
| Will not remove directories. Use osrmdir() to remove directories<br>
| |
| Returns true if successful or false if not possible for any reason.<br>
| |
| e.g. Target doesnt exist, path is not writeable, permissions etc.
| |
| <syntaxhighlight lang="c++">
| |
| if (not "../xyz.conf"_var.osfilevar.osremove()) abort(lasterror());
| |
| // or
| |
| if (not osremove("../xyz.conf") ...</syntaxhighlight>
| |
| |-
| |
| |if||osfileordirname.<em>osrename</em>(new_dirpath_or_filepath)||Renames an os file or dir in the OS file system.<br>
| |
| Will not overwrite an existing file or dir.<br>
| |
| Source and target must exist in the same storage device.<br>
| |
| Returns true if successful or false if not possible for any reason.<br>
| |
| e.g. Target already exists, path is not writeable, permissions etc.<br>
| |
| Uses std::filesystem::rename internally.
| |
| <syntaxhighlight lang="c++">
| |
| if (not "../xyz.conf"_var.osfilevar.osrename("../abc.conf")) abort(lasterror());
| |
| // or
| |
| if (not osrename("../xyz.conf", "../abc.conf") ...</syntaxhighlight>
| |
| |-
| |
| |if||osfileordirname.<em>oscopy</em>(to_osfilename)||Copies a file or directory recursively within the file system.<br>
| |
| Uses std::filesystem::copy internally with recursive and overwrite options
| |
| <syntaxhighlight lang="c++">
| |
| if (not "../xyz.conf"_var.osfilevar.oscopy("../abc.conf")) abort(lasterror());
| |
| // or
| |
| if (not oscopy("../xyz.conf", "../abc.conf") ...</syntaxhighlight>
| |
| |-
| |
| |if||osfileordirname.<em>osmove</em>(to_osfilename)||"Moves" a file or dir within the os file system.<br>
| |
| Will not overwrite an existing file or dir.<br>
| |
| Returns true if successful or false if not possible for any reason.<br>
| |
| e.g. Source doesnt exist or cannot be accessed, target already exists, source or target is not writeable, permissions etc.<br>
| |
| Attempts osrename first then oscopy followed by osremove original.
| |
| <syntaxhighlight lang="c++">
| |
| if (not "../xyz.conf"_var.osfilevar.osmove("../abc.conf")) abort(lasterror());
| |
| // or
| |
| if (not osmove("../xyz.conf", "../abc.conf") ...</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== OS Directories =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |var=||dirpath.<em>oslist</em>(globpattern = "", mode = 0)||Returns a FM delimited string containing all matching dir entries given a dir path<br>
| |
| 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"); // "adduser.conf^ca-certificates.conf^ ..."
| |
| // or just
| |
| var entries2 = oslist("/etc/" "*.conf";</syntaxhighlight>
| |
| |-
| |
| |var=||dirpath.<em>oslistf</em>(globpattern = "")||Same as oslist for files only
| |
| |-
| |
| |var=||dirpath.<em>oslistd</em>(globpattern = "")||Same as oslist for files only
| |
| |-
| |
| |var=||osfileordirpath.<em>osinfo</em>(mode = 0)||Return dir info for any dir entry or "" if it doesnt exist<br>
| |
| A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time<br>
| |
| mode 0 default<br>
| |
| mode 1 returns "" if not a file<br>
| |
| mode 2 returns "" if not a dir<br>
| |
| See also osfile() and osdir()
| |
| <syntaxhighlight lang="c++">
| |
| var info1 = "/etc/hosts"_var.osinfo(); // "221^20597^78309"
| |
| // or just
| |
| var info2 = osinfo("/etc/hosts");</syntaxhighlight>
| |
| |-
| |
| |var=||osfilename.<em>osfile</em>()||Return dir info for a file<br>
| |
| A short string containing size ^ FM ^ modified_time ^ FM ^ modified_time<br>
| |
| Alias for osinfo(1)
| |
| <syntaxhighlight lang="c++">
| |
| var fileinfo1 = "/etc/hosts"_var.osfile(); // "221^20597^78309"
| |
| // or just
| |
| var fileinfo2 = osfile("/etc/hosts");</syntaxhighlight>
| |
| |-
| |
| |var=||dirpath.<em>osdir</em>()||Return dir info for a dir.<br>
| |
| A short string containing FM ^ modified_time ^ FM ^ modified_time<br>
| |
| Alias for osinfo(2)
| |
| <syntaxhighlight lang="c++">
| |
| var dirinfo1 = "/etc/"_var.osdir(); // "^20848^44464"
| |
| // or just
| |
| var dirinfo2 = osfile("/etc/");</syntaxhighlight>
| |
| |-
| |
| |if||dirpath.<em>osmkdir</em>()||Makes a new directory and returns true if successful.<br>
| |
| Including parent dirs if necessary.
| |
| <syntaxhighlight lang="c++">
| |
| if (not "abc/def"_var.osmkdir()) ...
| |
| // or just
| |
| if (not osmkdir("abc/def")) ...</syntaxhighlight>
| |
| |-
| |
| |if||dirpath.<em>osrmdir</em>(evenifnotempty = false)||Removes a os dir and returns true if successful.<br>
| |
| Optionally even if not empty. Including subdirs.
| |
| <syntaxhighlight lang="c++">
| |
| if (not "abc/def"_var.osrmdir()) ...
| |
| // or just
| |
| if (not osrmdir("abc/def")) ...</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>oscwd</em>()||Returns the current working directory
| |
| <syntaxhighlight lang="c++">
| |
| var cwd1 = var().oscwd(); // "/home/exodus"
| |
| // or just
| |
| var cwd2 = oscwd();</syntaxhighlight>
| |
| |-
| |
| |if||var.<em>oscwd</em>(newpath)||Changes the current working dir and returns true if successful.
| |
| <syntaxhighlight lang="c++">
| |
| if (not "abc/def"_var.oscwd()) ...
| |
| // or just
| |
| if (not oscwd("abc/def")) ...</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== OS Shell/Environment =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |if||command.<em>osshell</em>()||Execute a shell command<br>
| |
| Returns true if the process terminates with error status 0 and false otherwise.
| |
| <syntaxhighlight lang="c++">
| |
| let cmd = "ls -l xyz";
| |
| if (not cmd.osshell()) ...
| |
| // or
| |
| if (not osshell(cmd)) ...</syntaxhighlight>
| |
| |-
| |
| |if||instr.<em>osshellread</em>(oscmd)||Same as osshell but captures stdout
| |
| <syntaxhighlight lang="c++">
| |
| var intext;
| |
| if (not intext.osshellread("ls -l xyz")) ...
| |
| | |
| // or just capturing stdout but ignoring exit status
| |
| intext = osshellread("ls -l xyz");</syntaxhighlight>
| |
| |-
| |
| |if||outstr.<em>osshellwrite</em>(oscmd)||Same as osshell but provides stdin to the process
| |
| <syntaxhighlight lang="c++">
| |
| var outtext = ...
| |
| if (not outtext.osshellwrite("grep xyz")) ...
| |
| // or
| |
| if (not osshellwrite(outtext, "grep xyz")) ...</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>ostempdirpath</em>()||Get the path of the tmp dir
| |
| <syntaxhighlight lang="c++">
| |
| var v1 = var().ostempdirpath(); // "/tmp/"
| |
| // or just
| |
| var v1 = ostempdirpath();</syntaxhighlight>()
| |
| |-
| |
| |var=||var.<em>ostempfilename</em>()||Create and get a temporary file
| |
| <syntaxhighlight lang="c++">
| |
| var tempfilename1 = var().ostempfilename(); // "/tmp/~exoEcLj3C"
| |
| // or just
| |
| var tempfilename2 = ostempfilename();</syntaxhighlight>()
| |
| |-
| |
| |if||envvalue.<em>osgetenv</em>(envcode)||Get the value of an environment variable
| |
| <syntaxhighlight lang="c++">
| |
| var envvalue1;
| |
| if (not envvalue1.osgetenv("HOME")) ... // "/home/exodus"
| |
| // or just
| |
| var envvalue2 = osgetenv("HOME");</syntaxhighlight>
| |
| |-
| |
| |cmd||envvalue.<em>ossetenv</em>(envcode)||Set the value of an environment variable code
| |
| <syntaxhighlight lang="c++">
| |
| envvalue.ossetenv(envcode);
| |
| // or just
| |
| ossetenv(envcode, envvalue);</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>ospid</em>()||Get the os process id
| |
| <syntaxhighlight lang="c++">
| |
| let pid = var().ospid(); // 663237
| |
| // or just
| |
| let pid = ospid();</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>ostid</em>()||Get the os thread process id
| |
| <syntaxhighlight lang="c++">
| |
| let tid = var().ostid(); // 663237
| |
| // or just
| |
| let tid = ostid();</syntaxhighlight>
| |
| |-
| |
| |var=||var.<em>version</em>()||Get the libexodus build date and time
| |
| <syntaxhighlight lang="c++">
| |
| var().version(); // "29 JAN 2025 14:56:52"</syntaxhighlight>
| |
| |}
| |
| | |
| | |
| ===== Output =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |expr||var.<em>output</em>()||stdout no new line, buffered
| |
| |-
| |
| |expr||var.<em>outputl</em>()||stdout starts a new line, flushed
| |
| |-
| |
| |expr||var.<em>outputt</em>()||stdout adds a tab, buffered
| |
| |-
| |
| |expr||var.<em>logput</em>()||stdlog no new line, buffered
| |
| |-
| |
| |expr||var.<em>logputl</em>()||stdlog starts a new line, flushed
| |
| |-
| |
| |expr||var.<em>errput</em>()||stderr no new line, flushed
| |
| |-
| |
| |expr||var.<em>errputl</em>()||stderr starts a new line, flushed
| |
| |-
| |
| |expr||var.<em>output</em>(prefix)||stdout with a prefix, no new line, buffered
| |
| |-
| |
| |expr||var.<em>outputl</em>(prefix)||stdout with a prefix, starts a new line, flushed
| |
| |-
| |
| |expr||var.<em>outputt</em>(prefix)||stdout with a prefix, adds a tab, buffered
| |
| |-
| |
| |expr||var.<em>logput</em>(prefix)||stdlog with a prefix, no new line, buffered
| |
| |-
| |
| |expr||var.<em>logputl</em>(prefix)||stdlog with a prefix, starts a new line, flushed
| |
| |-
| |
| |expr||var.<em>errput</em>(prefix)||stderr with a prefix, no new line, flushed
| |
| |-
| |
| |expr||var.<em>errputl</em>(prefix)||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 just
| |
| osflush();</syntaxhighlight>()
| |
| |}
| |
| | |
| | |
| ===== Standard Input =====
| |
| | |
| {|border="1" cellpadding="10" cellspacing="0"
| |
| !Usage!!Function!!Comment
| |
| |-
| |
| |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
| |
| |}
| |