|
Qore Util Module Reference
1.2
|
the Util namespace contains all the objects in the Util module More...
Functions | |
| bool | absolute_path (string path) |
| returns True if the argument is an absolute path, False if not More... | |
| bool | absolute_path_unix (string path) |
| returns True if the argument is a UNIX absolute path, False if not More... | |
| bool | absolute_path_windows (string path) |
| returns True if the argument is a Windows absolute path, False if not More... | |
| int | compare_version (string lv, string rv) |
| compares complex versions by breaking down strings into component parts More... | |
| string | get_byte_size (softnumber n, int decimals=2) |
| returns a string giving a user-friendly real storage size (ie based on 1KiB = 1024 bytes) in KiB, MiB, GiB, TiB, etc for the given byte size More... | |
| string | get_exception_string (hash ex) |
| returns a multi-line string from the exception hash argument suitable for logging or output on the console More... | |
| string | get_marketing_byte_size (softnumber n, int decimals=2) |
| returns a string giving a user-friendly "marketing storage" size (ie based on 1KB = 1000 bytes) in KB, MB, GB, TB, etc for the given byte size More... | |
| string | get_random_string (softint len=15, int level=3) |
| function that returns a random string More... | |
| string | glob_to_regex (string pat) |
| Translates a shell pattern to a regular expression. More... | |
| string | lpad (softstring text, int length, string padding= ' ') |
| Returns a string left-padded to a specified length with the specified characters. More... | |
| string | normalize_dir (string dir, string cwd=getcwd()) |
returns a platform-specific normalized path name (starting from /, eliminates ".", "..", and "//") More... | |
| string | normalize_dir_unix (string dir, string cwd=getcwd()) |
returns a normalized UNIX path name (starting from /, eliminates ".", "..", and "//") More... | |
| string | normalize_dir_windows (string dir, string cwd=getcwd()) |
returns a normalized Windows path name (eliminates ".", "..", and "//") More... | |
| string | ordinal (int i) |
| Returns string with partially textual representation of ordinal integer value. More... | |
| any | parse_to_qore_value (string arg) |
| tries to convert a string (such as an argument given from the command-line) to a Qore value More... | |
| string | plural (int count, string base, string singular="", string plural="s") |
| Returns string with number and proper singular/plural form of noun. More... | |
| string | regex_escape (string text) |
| Escapes (backslashes) all non-alphanumeric characters in a string. More... | |
| string | rpad (softstring text, int length, string padding= ' ') |
| Returns a string right-padded to a specified length with the specified characters. More... | |
| bool | same (list l) |
| checks whether given list has only uniq element More... | |
| list | slice (list l, softlist indices) |
| list slice implementation More... | |
| string | tmp_location () |
| Returns a path for temporary files. More... | |
| list | zip () |
| Returns a list of lists, where the i-th list contains the i-th element from each of the argument lists. More... | |
Variables | |
| const | StorageNames = ("Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Zetta", "Yotta", "Bronto") |
| storage names (Geop, which would normally follow Bronto, is excluded as the abbreviation would be GB/GiB) | |
compares complex versions by breaking down strings into component parts
Each element is compared separately, so that compare_version("2.11.1", "2.2") returns 1 (a regular string comparison would give the opposite result)
| lv | left-hand version |
| rv | right-hand version |
returns a multi-line string from the exception hash argument suitable for logging or output on the console
| ex | the exception hash to process |
function that returns a random string
| len | the length fo the string returned |
| level | a value from 1 - 4 inclusive giving the range of printable ASCII characters included in the output (values out of the range result in the nearest value in the range being used):
|
Translates a shell pattern to a regular expression.
Returns the shell-style pattern converted to a regular expression.
| pat | the pattern to convert |
Returns a string left-padded to a specified length with the specified characters.
Returns a string, left-padded to a specified length with the specified characters; or, when the string to be padded is longer than the length specified after padding, only that portion of the string that fits into the specified length.
| text | input string that you want to pad |
| length | total length of output string (in characters) |
| padding | padding character(s); default value is a single blank |
returns a platform-specific normalized path name (starting from /, eliminates ".", "..", and "//")
Currently only Windows and UNIX-style directories are supported; this function calls either:
| dir | the directory name to normalize |
| cwd | the current working directory for normalizing relative paths |
returns a normalized UNIX path name (starting from /, eliminates ".", "..", and "//")
For example, calling:
from current directory "/opt/qorus/sub/dir" returns:
| dir | the directory name to normalize |
| cwd | the current working directory |
".", "..", and "//") returns a normalized Windows path name (eliminates ".", "..", and "//")
For example, calling:
from current directory "c:\\lang\\qore\\prog1" returns:
| dir | the directory name to normalize |
| cwd | the current working directory |
".", "..", and "\\" (except at the beginning of a UNC path) Returns string with partially textual representation of ordinal integer value.
| i | integer value to convert to textual representation |
| any Util::parse_to_qore_value | ( | string | arg | ) |
tries to convert a string (such as an argument given from the command-line) to a Qore value
This function recognizes two special prefixes in the string:
STR= this prefix indicates that the rest of the string should be passed literally and not parsedEVAL= this prefix indicates that the rest of the string should be taken as a Qore expression and executed and the value returnedStrings are interpreted as in the following table.
String Parsing
| Format | Description |
key_string = value[, ...] | a hash |
value, [...] | a list |
integers | an integer |
floats | a float |
arbitrary-numeric value | a number |
| a bool |
| a date |
a Qore expression | the value evaluated |
a quoted string | a string |
prompt% qore -l ./Util.qm -X 'parse_to_qore_value("(a=(b=(c=x, 2, 3)))")'
hash: (1 member)
a : hash: (1 member)
b : list: (3 elements)
[0]=hash: (1 member)
c : "x"
[1]=2
[2]=3| arg | a string to convert to a Qore value according to the rules documented above |
| PARSE-ERROR | cannot parse the string given |
Returns string with number and proper singular/plural form of noun.
| count | integer value to convert |
| base | base word or possibly nothing |
| singular | singular form suffix or whole word |
| plural | plural form suffix or whole word |
Escapes (backslashes) all non-alphanumeric characters in a string.
Returns string with all non-alphanumerics backslashed; this is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it.
| text | string to escape / backslash |
Returns a string right-padded to a specified length with the specified characters.
Returns a string, right-padded to a specified length with the specified characters; or, when the string to be padded is longer than the length specified after padding, only that portion of the string that fits into the specified length.
| text | input string that you want to pad |
| length | total length of output string (in characters) |
| padding | padding character(s); default value is a single blank |
| bool Util::same | ( | list | l | ) |
list slice implementation
| l | some list |
| indices | indices that should be sliced from the original list |
| string Util::tmp_location | ( | ) |
Returns a path for temporary files.
Environment variables are searched in the following order (the first with a value is used):
TMPDIR TMP TEMP TEMPDIR If none of these are present, then "/tmp" (UNIX) or "c:\temp" (Windows) is checked.
| TMP-ERROR | unable to find the location of the temporary directory; temporary directory is not writable |