Qore Util Module Reference  1.2
Util.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file Util.qm Qore user module for generally useful routines
3 
4 /* Util.qm Copyright 2014 - 2016 Qore Technologies, sro
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // this module requires Qore 0.8.12 or better
26 
27 // do not use $ for vars, assume local var scope
28 
29 // require type definitions everywhere
30 
31 // enable all warnings
32 
33 }
34 
98 namespace Init {
99  init();
100 
101 };
102 
104 namespace Util {
106 
119  int compare_version(string lv, string rv);
120 
121 
123 
141  string normalize_dir(string dir, string cwd = getcwd());
142 
143 
145 
160  string normalize_dir_unix(string dir, string cwd = getcwd());
161 
162 
164 
179  string normalize_dir_windows(string dir, string cwd = getcwd());
180 
181 
183 
196  bool absolute_path(string path);
197 
198 
200 
213  bool absolute_path_unix(string path);
214 
215 
217 
230  bool absolute_path_windows(string path);
231 
232 
233  // private, non-exported constant hashes for scan_exp() below
234  const ParenMap = (")": "(", "}": "{", "]": "[",);
235  const FwdParenMap = map {$1.value: $1.key}, ParenMap.pairIterator();
236 
237  // private, non-exported constants for parsing
238  const ET_RawString = 0;
239  const ET_QuotedString = 1;
240  const ET_BracketString = 2;
241  const ET_Eq = 3;
242  const ET_Comma = 4;
243  const EtMap = (
244  ET_RawString: "raw string",
245  ET_QuotedString: "quoted string",
246  ET_BracketString: "bracket expression",
247  ET_Eq: "=",
248  ET_Comma: ",",
249  );
250 
251  // private scanner for parse_to_qore_value()
252  list scan_exp(string arg);
253 
254 
255  // private, non-exported function: tries to evaluate the argument as a Qore expression/value
256  hash eval_text(string arg, bool err = False);
257 
258 
259  // private, non-exported function: tries to evaluate the argument as a Qore expression/value
260  /* returns the value parsed
261  */
262  any parse_to_basic_value(*string arg);
263 
264 
266 
335  any parse_to_qore_value(string arg);
336 
337 
339 
353  string get_random_string(softint len = 15, int level = 3);
354 
355 
357 
361  string get_exception_string(hash ex);
362 
363 
365  const StorageNames = ("Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Zetta", "Yotta", "Bronto");
366 
368 
376  string get_byte_size(softnumber n, int decimals = 2);
377 
378 
380 
388  string get_marketing_byte_size(softnumber n, int decimals = 2);
389 
390 
392 
403  bool same(list l);
404 
405 
407 
417  list slice(list l, softlist indices);
418 
419 
421 
440  string tmp_location();
441 
442 
444 
459  string lpad(softstring text, int length, string padding = ' ');
460 
461 
463 
478  string rpad(softstring text, int length, string padding = ' ');
479 
480 
482 
493  string ordinal(int i);
494 
495 
497 
516  string plural(int count, string base, string singular = "", string plural = "s");
517 
518 
520 
532  string regex_escape(string text);
533 
534 
536 
548  string glob_to_regex(string pat);
549 
550 
552 
563  list zip();
564 
565 };
string get_exception_string(hash ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
string normalize_dir_windows(string dir, string cwd=getcwd())
returns a normalized Windows path name (eliminates ".", "..", and "//")
string normalize_dir(string dir, string cwd=getcwd())
returns a platform-specific normalized path name (starting from /, eliminates ".", "..", and "//")
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 ...
string plural(int count, string base, string singular="", string plural="s")
Returns string with number and proper singular/plural form of noun.
string glob_to_regex(string pat)
Translates a shell pattern to a regular expression.
string rpad(softstring text, int length, string padding= ' ')
Returns a string right-padded to a specified length with the specified characters.
*string getcwd()
list zip()
Returns a list of lists, where the i-th list contains the i-th element from each of the argument list...
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...
string normalize_dir_unix(string dir, string cwd=getcwd())
returns a normalized UNIX path name (starting from /, eliminates ".", "..", and "//") ...
string tmp_location()
Returns a path for temporary files.
const False
list list(...)
const StorageNames
storage names (Geop, which would normally follow Bronto, is excluded as the abbreviation would be GB/...
Definition: Util.qm.dox.h:365
string lpad(softstring text, int length, string padding= ' ')
Returns a string left-padded to a specified length with the specified characters. ...
the Util namespace contains all the objects in the Util module
Definition: Util.qm.dox.h:104
string regex_escape(string text)
Escapes (backslashes) all non-alphanumeric characters in a string.
bool same(list l)
checks whether given list has only uniq element
int compare_version(string lv, string rv)
compares complex versions by breaking down strings into component parts
string ordinal(int i)
Returns string with partially textual representation of ordinal integer value.
string get_random_string(softint len=15, int level=3)
function that returns a random string
Definition: Util.qm.dox.h:98
list slice(list l, softlist indices)
list slice implementation
int length(softstring str)
hash hash(object obj)
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...