String, character vector, and regular expression operations. More...
#include <memory_resource>#include <string>#include <nk/value/value.hpp>#include <nk/value/span.hpp>Go to the source code of this file.
Functions | |
| Value | nk::builtin::num2str (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Formats numeric array into character vector (num2str(x)). | |
| Value | nk::builtin::num2str (const Value &x, int N, std::pmr::memory_resource *mr=nullptr) |
| Formats numeric array into character vector with specified precision digits (num2str(x, N)). | |
| Value | nk::builtin::num2str (const Value &x, const std::string &fmt, std::pmr::memory_resource *mr=nullptr) |
| Formats numeric array into character vector with format specification (num2str(x, fmt)). | |
| Value | nk::builtin::int2str (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Formats integer into character vector (int2str(x)). | |
| Value | nk::builtin::mat2str (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Formats matrix into MATLAB syntax string (mat2str(x)). | |
| Value | nk::builtin::mat2str (const Value &x, int precision, std::pmr::memory_resource *mr=nullptr) |
| Formats matrix into MATLAB syntax string with precision (mat2str(x, precision)). | |
| Value | nk::builtin::str2num (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Converts string representation to numeric matrix (str2num(s)). | |
| Value | nk::builtin::str2double (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Converts text to double precision numeric values (str2double(s)). | |
| Value | nk::builtin::char_array (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Converts input to character array (char(x)). | |
| Value | nk::builtin::toChar (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Alias for char_array conversion (char(x)). | |
| Value | nk::builtin::string_array (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Converts input to string array (string(x)). | |
| Value | nk::builtin::toString (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Alias for string_array conversion (string(x)). | |
| Value | nk::builtin::blanks (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates character vector of blank spaces (blanks(n)). | |
| Value | nk::builtin::newline (std::pmr::memory_resource *mr=nullptr) |
| Creates newline character string (newline). | |
| Value | nk::builtin::newlineFn (std::pmr::memory_resource *mr=nullptr) |
| Generates newline character as string Value. | |
| Value | nk::builtin::strcmp (const Value &s1, const Value &s2, std::pmr::memory_resource *mr=nullptr) |
| Compares strings for exact equality (case-sensitive) (strcmp(s1, s2)). | |
| Value | nk::builtin::strncmp (const Value &s1, const Value &s2, size_t n, std::pmr::memory_resource *mr=nullptr) |
| Compares first n characters of strings (case-sensitive) (strncmp(s1, s2, n)). | |
| Value | nk::builtin::strcmpi (const Value &s1, const Value &s2, std::pmr::memory_resource *mr=nullptr) |
| Compares strings for equality ignoring case (strcmpi(s1, s2)). | |
| Value | nk::builtin::strncmpi (const Value &s1, const Value &s2, size_t n, std::pmr::memory_resource *mr=nullptr) |
| Compares first n characters of strings ignoring case (strncmpi(s1, s2, n)). | |
| Value | nk::builtin::matches (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr) |
| Tests if strings match pattern (matches(str, pat)). | |
| Value | nk::builtin::upper (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Converts string to uppercase (upper(s)). | |
| Value | nk::builtin::lower (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Converts string to lowercase (lower(s)). | |
| Value | nk::builtin::strtrim (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Removes leading and trailing whitespace (strtrim(s)). | |
| Value | nk::builtin::deblank (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Removes trailing whitespace (deblank(s)). | |
| Value | nk::builtin::strip (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Strips leading and trailing whitespace from string array (strip(s)). | |
| Value | nk::builtin::strip (const Value &s, const Value &side, const Value &ch, std::pmr::memory_resource *mr=nullptr) |
| Strips specified characters from side of string array (strip(s, side, ch)). | |
| Value | nk::builtin::strcat (Span< const Value > args, std::pmr::memory_resource *mr=nullptr) |
| Concatenates strings horizontally (strcat(s1, s2, ...)). | |
| Value | nk::builtin::strjoin (const Value &c, const std::string &delim=" ", std::pmr::memory_resource *mr=nullptr) |
| Joins string array or cell array of strings with delimiter (strjoin(c, delim)). | |
| Value | nk::builtin::strjoin (const Value &arr, const Value &delim, std::pmr::memory_resource *mr=nullptr) |
| Joins string array with Value delimiter (strjoin(arr, delim)). | |
| Value | nk::builtin::join (const Value &arr, const Value &delim=Value::Empty, std::pmr::memory_resource *mr=nullptr) |
| Combines elements of string array into single string (join(arr, delim)). | |
| Value | nk::builtin::append (Span< const Value > parts, std::pmr::memory_resource *mr=nullptr) |
| Appends multiple strings element-wise (append(s1, s2, ...)). | |
| Value | nk::builtin::strsplit (const Value &s, const std::string &delim=" ", std::pmr::memory_resource *mr=nullptr) |
| Splits string by delimiter string (strsplit(s, delim)). | |
| Value | nk::builtin::strsplit (const Value &s, const Value &delim, std::pmr::memory_resource *mr=nullptr) |
| Splits string by Value delimiter (strsplit(s, delim)). | |
| Value | nk::builtin::strsplit (const Value &s, std::pmr::memory_resource *mr) |
| Splits string by whitespace (strsplit(s)). | |
| Value | nk::builtin::split (const Value &s, const Value &delim=Value::Empty, std::pmr::memory_resource *mr=nullptr) |
| Splits string array elements by delimiter (split(s, delim)). | |
| Value | nk::builtin::splitlines (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Splits string into separate lines (splitlines(s)). | |
| Value | nk::builtin::strfind (const Value &text, const Value &pattern, std::pmr::memory_resource *mr=nullptr) |
| Finds occurrences of substring within string (strfind(text, pattern)). | |
| Value | nk::builtin::strrep (const Value &orig, const Value &oldStr, const Value &newStr, std::pmr::memory_resource *mr=nullptr) |
| Replaces occurrences of substring within string (strrep(orig, old, new)). | |
| Value | nk::builtin::contains (const Value &str, const Value &pat, bool ignoreCase=false, std::pmr::memory_resource *mr=nullptr) |
| Checks if string contains pattern (contains(str, pat)). | |
| Value | nk::builtin::startsWith (const Value &str, const Value &pat, bool ignoreCase=false, std::pmr::memory_resource *mr=nullptr) |
| Checks if string starts with pattern (startsWith(str, pat)). | |
| Value | nk::builtin::endsWith (const Value &str, const Value &pat, bool ignoreCase=false, std::pmr::memory_resource *mr=nullptr) |
| Checks if string ends with pattern (endsWith(str, pat)). | |
| Value | nk::builtin::strlength (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Returns number of characters in each string element (strlength(s)). | |
| Value | nk::builtin::count (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr) |
| Counts occurrences of pattern in string (count(str, pat)). | |
| Value | nk::builtin::reverse (const Value &str, std::pmr::memory_resource *mr=nullptr) |
| Reverses characters in string (reverse(str)). | |
| Value | nk::builtin::erase (const Value &s, const Value &pat, std::pmr::memory_resource *mr=nullptr) |
| Erases occurrences of substring pattern from string (erase(s, pat)). | |
| Value | nk::builtin::replace (const Value &s, const Value &oldPat, const Value &newPat, std::pmr::memory_resource *mr=nullptr) |
| Replaces substring pattern with new pattern in string array (replace(s, oldPat, newPat)). | |
| Value | nk::builtin::replaceBetween (const Value &s, const Value &start, const Value &end, const Value &newText, std::pmr::memory_resource *mr=nullptr) |
| Replaces text between specified start and end boundaries (replaceBetween(s, start, end, newText)). | |
| Value | nk::builtin::extractAfter (const Value &s, const Value &p, std::pmr::memory_resource *mr=nullptr) |
| Extracts substrings after specified pattern or position (extractAfter(s, p)). | |
| Value | nk::builtin::extractBefore (const Value &s, const Value &p, std::pmr::memory_resource *mr=nullptr) |
| Extracts substrings before specified pattern or position (extractBefore(s, p)). | |
| Value | nk::builtin::extractBetween (const Value &s, const Value &start, const Value &end, std::pmr::memory_resource *mr=nullptr) |
| Extracts substrings between specified boundaries (extractBetween(s, start, end)). | |
| Value | nk::builtin::insertAfter (const Value &s, const Value &p, const Value &newText, std::pmr::memory_resource *mr=nullptr) |
| Inserts text after specified position or pattern (insertAfter(s, p, newText)). | |
| Value | nk::builtin::insertBefore (const Value &s, const Value &p, const Value &newText, std::pmr::memory_resource *mr=nullptr) |
| Inserts text before specified position or pattern (insertBefore(s, p, newText)). | |
| Value | nk::builtin::eraseBetween (const Value &s, const Value &start, const Value &end, std::pmr::memory_resource *mr=nullptr) |
| Erases text between specified boundaries (eraseBetween(s, start, end)). | |
| Value | nk::builtin::extract (const Value &s, const Value &pat, std::pmr::memory_resource *mr=nullptr) |
| Extracts substring matching pattern (extract(s, pat)). | |
| Value | nk::builtin::pad (const Value &s, size_t n, const Value &side=Value(), const Value &padChar=Value(), std::pmr::memory_resource *mr=nullptr) |
| Pads string to fixed length (pad(s, n, side, padChar)). | |
| Value | nk::builtin::strjust (const Value &M, const std::string &side="left", std::pmr::memory_resource *mr=nullptr) |
| Justifies character matrix (strjust(M, side)). | |
| Value | nk::builtin::isletter (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Tests if characters are letters (isletter(s)). | |
| Value | nk::builtin::isspace (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Tests if characters are whitespace (isspace(s)). | |
| Value | nk::builtin::isspaceFn (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Tests if characters are whitespace (internal helper returning Value). | |
| Value | nk::builtin::isstrprop (const Value &s, const std::string &category, std::pmr::memory_resource *mr=nullptr) |
| Tests if characters have specified string property (isstrprop(s, category)). | |
| Value | nk::builtin::isstrprop (const Value &s, const Value &category, std::pmr::memory_resource *mr=nullptr) |
| Tests if characters have specified string property via Value category (isstrprop(s, category)). | |
| Value | nk::builtin::isstringscalar (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Tests if input is a scalar string (isstringscalar(s)). | |
| Value | nk::builtin::validatestring (const Value &str, const Value &validStrings, std::pmr::memory_resource *mr=nullptr) |
| Validates text against list of valid strings (validatestring(str, validStrings)). | |
| Value | nk::builtin::convertCharsToStrings (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Converts character arrays in input to string arrays (convertCharsToStrings(x)). | |
| Value | nk::builtin::convertStringsToChars (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Converts string arrays in input to character vectors (convertStringsToChars(x)). | |
| Value | nk::builtin::convertContainedStringsToChars (const Value &v, std::pmr::memory_resource *mr=nullptr) |
| Recursively converts all contained strings in cells/structs to character vectors. | |
| Value | nk::builtin::stringsND (Span< const size_t > dims, std::pmr::memory_resource *mr=nullptr) |
| Constructs an N-dimensional array of empty strings. | |
| Value | nk::builtin::dec2bin (const Value &d, int minDigits=0, std::pmr::memory_resource *mr=nullptr) |
| Decimal to binary string (dec2bin(d, minDigits)). | |
| Value | nk::builtin::dec2hex (const Value &d, int minDigits=0, std::pmr::memory_resource *mr=nullptr) |
| Decimal to hexadecimal string (dec2hex(d, minDigits)). | |
| Value | nk::builtin::dec2base (const Value &d, int base, int minDigits=0, std::pmr::memory_resource *mr=nullptr) |
| Decimal to base-N string (dec2base(d, base, minDigits)). | |
| Value | nk::builtin::base2dec (const Value &s, int base, std::pmr::memory_resource *mr=nullptr) |
| Base-N string to decimal (base2dec(s, base)). | |
| Value | nk::builtin::bin2dec (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Binary string to decimal (bin2dec(s)). | |
| Value | nk::builtin::hex2dec (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Hexadecimal string to decimal (hex2dec(s)). | |
| Value | nk::builtin::hex2num (const Value &s, std::pmr::memory_resource *mr=nullptr) |
| Converts 16-character hexadecimal string to IEEE double-precision floating-point number (hex2num(s)). | |
| Value | nk::builtin::num2hex (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Converts double-precision floating-point number to 16-character hexadecimal string (num2hex(x)). | |
| Value | nk::builtin::rat (const Value &x, double tol=0.0, std::pmr::memory_resource *mr=nullptr) |
| Rational approximation as fraction / continued fraction (rat(x, tol)). | |
| Value | nk::builtin::rats (const Value &x, int len=13, std::pmr::memory_resource *mr=nullptr) |
| Formats numbers as rational string representations (rats(x, len)). | |
| std::pair< Value, Value > | nk::builtin::strtok (const Value &str, const std::string &delim=" \t\n\r", std::pmr::memory_resource *mr=nullptr) |
| Extracts first token from character vector up to delimiter ([token, rem] = strtok(str, delim)). | |
| Value | nk::builtin::regexp (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr) |
| Regular expression matching (regexp(str, pat)). | |
| Value | nk::builtin::regexpi (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr) |
| Case-insensitive regular expression matching (regexpi(str, pat)). | |
| Value | nk::builtin::regexpFind (const Value &s, const Value &pat, const std::string &option, bool ignoreCase, std::pmr::memory_resource *mr=nullptr) |
| Regular expression search helper. | |
| Value | nk::builtin::regexpFindOnce (const Value &s, const Value &pat, const std::string &option, bool ignoreCase, std::pmr::memory_resource *mr=nullptr) |
| Regular expression search once helper. | |
| Value | nk::builtin::regexprep (const Value &str, const Value &pat, const Value &rep, bool ignoreCase=false, bool once=false, std::pmr::memory_resource *mr=nullptr) |
| Regular expression replacement (regexprep(str, pat, rep, ignoreCase, once)). | |
| Value | nk::builtin::regexptranslate (const std::string &type, const std::string &str, std::pmr::memory_resource *mr=nullptr) |
| Translates wildcard strings to regular expressions (regexptranslate(type, str)). | |
| Value | nk::builtin::regexptranslate (const std::string &type, const Value &str, std::pmr::memory_resource *mr=nullptr) |
| Translates wildcard Value to regular expression (regexptranslate(type, str)). | |
| Value | nk::builtin::compose (const Value &fmt, const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Formats data into string array (compose(fmt, x)). | |
| std::string | nk::builtin::formatOnce (const std::string &fmt, Span< const Value > args, size_t argStart=0, bool literalWhenShort=false) |
| Formats single pass of format specification. | |
| std::string | nk::builtin::formatCyclic (const std::string &fmt, Span< const Value > args, size_t argStart=0, std::pmr::memory_resource *mr=nullptr) |
| Formats cyclic repetition of format specification across array elements. | |
| size_t | nk::builtin::countFormatSpecs (const std::string &fmt) |
| Counts number of conversion specifiers in format string. | |
| std::string | nk::builtin::dispFormat (const Value &a) |
| Formats Value for terminal display via disp. | |
String, character vector, and regular expression operations.
Provides a clean, engine-free C++ API for string comparisons, formatting, pattern searching, regex replacements, base conversions, and predicates.
Definition in file strfun.hpp.