All Classes Namespaces Functions Variables Groups Pages
Util.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file Util.qm Qore user module for generally useful routines
/* Util.qm Copyright 2014 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// this module requires Qore 0.8.13 or better
// do not use $ for vars, assume local var scope
// require type definitions everywhere
// enable all warnings
}
namespace Init {
init();
};
namespace Util {
public struct UriQueryInfo {
string method;
*hash params;
};
int compare_version(string lv, string rv);
string normalize_dir(string dir, string cwd = getcwd());
string normalize_dir_unix(string dir, string cwd = getcwd());
string normalize_dir_windows(string dir, string cwd = getcwd());
bool absolute_path(string path);
bool absolute_path_unix(string path);
bool absolute_path_windows(string path);
// private, non-exported constant hashes for scan_exp() below
const ParenMap = (")": "(", "}": "{", "]": "[",);
const FwdParenMap = map {$1.value: $1.key}, ParenMap.pairIterator();
// private, non-exported constants for parsing
const ET_RawString = 0;
const ET_QuotedString = 1;
const ET_BracketString = 2;
const ET_Eq = 3;
const ET_Comma = 4;
const EtMap = (
ET_RawString: "raw string",
ET_QuotedString: "quoted string",
ET_BracketString: "bracket expression",
ET_Eq: "=",
ET_Comma: ",",
);
// private scanner for parse_to_qore_value()
list scan_exp(string arg);
// private, non-exported function: tries to evaluate the argument as a Qore expression/value
hash eval_text(string arg, bool err = False);
// private, non-exported function: tries to evaluate the argument as a Qore expression/value
/* returns the value parsed
*/
auto parse_to_basic_value(*string arg);
auto parse_to_qore_value(string arg);
hash<UriQueryInfo> parse_uri_query(string path);
string make_uri_query(hash<UriQueryInfo> h, string arg_separator = ";");
string get_random_string(softint len = 15, int level = 3);
string get_exception_string(hash ex);
const StorageNames = ("Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Zetta", "Yotta", "Bronto");
string get_byte_size(softnumber n, int decimals = 2);
string get_marketing_byte_size(softnumber n, int decimals = 2);
bool same(list l);
list slice(list l, softlist indices);
string tmp_location();
bool is_int(string text, bool pure = False);
const RE_FLOAT = '^\s*[-+]?('
'\d+\.\d*(e[-+]?\d+)?' // floating point number, with dot, optional exponent
'|\.\d+(e[-+]?\d+)?' // floating point number, starting with a dot, optional exponent
'|\d+e[-+]?\d+' // floating point number, without dot, with exponent
')\s*$'; //';
bool is_float(string text, bool pure = False);
const RE_NUMBER = '^\s*[-+]?('
'\d+\.\d*(e[-+]?\d+)?' // floating point number, with dot, optional exponent
'|\.\d+(e[-+]?\d+)?' // floating point number, starting with a dot, optional exponent
'|\d+e[-+]?\d+' // floating point number, without dot, with exponent
'|\d+)n\s*$'; //'; #integer
bool is_number(string text, bool pure = False);
string lpad(softstring text, int length, string padding = ' ');
string rpad(softstring text, int length, string padding = ' ');
string ordinal(int i);
string plural(int count, string base, string singular = "", string plural = "s");
string regex_escape(string text);
string glob_to_regex(string pat);
list flatten (softlist arg);
list uniq (softlist arg);
list zip();
};
Util::get_exception_string
string get_exception_string(hash ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
Util::normalize_dir_windows
string normalize_dir_windows(string dir, string cwd=getcwd())
returns a normalized Windows path name (eliminates &quot;.&quot;, &quot;..&quot;, and &quot;//&quot;)
Util::UriQueryInfo
the return value of the parse_uri_query() function
Definition: Util.qm.dox.h:126
Util::normalize_dir
string normalize_dir(string dir, string cwd=getcwd())
returns a platform-specific normalized path name (starting from /, eliminates &quot;.&quot;, &quot;..&quot;, and &quot;//&quot;)
Util::is_number
bool is_number(string text, bool pure=False)
Checks whether string represents a (true) number value.
Util::plural
string plural(int count, string base, string singular="", string plural="s")
Returns string with number and proper singular/plural form of noun.
Util::glob_to_regex
string glob_to_regex(string pat)
Translates a shell pattern to a regular expression.
Util::UriQueryInfo::method
string method
the part of the URI path before the first &quot;?&quot; character or the entire path if no &quot;?&quot; character is present in the path
Definition: Util.qm.dox.h:128
Util::rpad
string rpad(softstring text, int length, string padding= ' ')
Returns a string right-padded to a specified length with the specified characters.
getcwd
*string getcwd()
Util::zip
list zip()
Returns a list of lists, where the i-th list contains the i-th element from each of the argument list...
Util::get_byte_size
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...
Util::normalize_dir_unix
string normalize_dir_unix(string dir, string cwd=getcwd())
returns a normalized UNIX path name (starting from /, eliminates &quot;.&quot;, &quot;..&quot;, and &quot;//&quot;) ...
Util::tmp_location
string tmp_location()
Returns a path for temporary files.
False
const False
list
list list(...)
Util::StorageNames
const StorageNames
storage names (Geop, which would normally follow Bronto, is excluded as the abbreviation would be GB/...
Definition: Util.qm.dox.h:417
Util::lpad
string lpad(softstring text, int length, string padding= ' ')
Returns a string left-padded to a specified length with the specified characters. ...
Util::parse_uri_query
hash< UriQueryInfo > parse_uri_query(string path)
parses a URI path for a arguments and a method; where the method is the part of the path before the f...
Util::is_float
bool is_float(string text, bool pure=False)
Checks whether string represents a (true) float value.
Util::regex_escape
string regex_escape(string text)
Escapes (backslashes) all non-alphanumeric characters in a string.
Util::same
bool same(list l)
checks whether given list has only uniq element
Util::flatten
list flatten(softlist arg)
Flattens a nested list (the nesting can be to any depth).
Util::UriQueryInfo::params
*hash params
(only present if a &quot;?&quot; character is present in the input); the part of the path after the first &quot;...
Definition: Util.qm.dox.h:131
Util::compare_version
int compare_version(string lv, string rv)
compares complex versions by breaking down strings into component parts
Util::ordinal
string ordinal(int i)
Returns string with partially textual representation of ordinal integer value.
Util::get_random_string
string get_random_string(softint len=15, int level=3)
function that returns a random string
Util::uniq
list uniq(softlist arg)
Returns a duplicate-free version of the list.
Util::slice
list slice(list l, softlist indices)
list slice implementation
Util::parse_to_qore_value
auto parse_to_qore_value(string arg)
tries to convert a string (such as an argument given from the command-line) to a Qore value ...
length
int length(softstring str)
hash
hash hash(object obj)
Util::make_uri_query
string make_uri_query(hash< UriQueryInfo > h, string arg_separator=";")
returns a serialized string for a UriQueryInfo hash
Util::get_marketing_byte_size
string get_marketing_byte_size(softnumber n, int decimals=2)
returns a string giving a user-friendly &quot;marketing storage&quot; size (ie based on 1KB = 1000 bytes) in KB...
Util::is_int
bool is_int(string text, bool pure=False)
Checks whether string represents a (true) integer value.