Qore Util Module Reference 2.0.1
Loading...
Searching...
No Matches
Util.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Util.qm Copyright 2014 - 2024 Qore Technologies, s.r.o.
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// minimum Qore version
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
35
36
191namespace Init {
192 init();
193
194};
195
197namespace Util {
199public hashdecl UiMessageInfo {
201 string title;
202
204 string intent;
205
207 string content;
208};
209
211public hashdecl AllowedValueInfo {
214
216 *string short_desc;
217
219 auto value;
220
222 string desc;
223
225 *string intent;
226
228 *bool disabled;
229
231 *hash<auto> metadata;
232
234 *list<hash<UiMessageInfo>> messages;
235
237 *string icon;
238
240 *string image;
241};
242
244
246public hashdecl UriQueryInfo {
248
251 string method;
252
254
262 *hash<auto> params;
263
265
267 *hash<auto> path_params;
268};
269
271
279 string get_bit_string(int i, *int min_bits);
280
281
283
300 int parse_memory_size(string str, *bool use_binary);
301
302
304
317 int compare_version(string lv, string rv);
318
319
321
339 string normalize_dir(string path, string cwd = getcwd());
340
341
343
358 string normalize_dir_unix(string path, string cwd = getcwd());
359
360
362
377 string normalize_dir_windows(string path, string cwd = getcwd());
378
379
381
394 string get_relative_path(string basedir, string path, string cwd = getcwd());
395
396
398
411 bool absolute_path(string path);
412
413
415
428 bool absolute_path_unix(string path);
429
430
432
445 bool absolute_path_windows(string path);
446
447
448// private, non-exported helper function for parse_memory_size()
449int _get_size(string num, number mult);
450
451
452// private, non-exported constant hashes for scan_exp() below
453const ParenMap = ...;
454
455const FwdParenMap = map {$1.value: $1.key}, ParenMap.pairIterator();
456
457// private, non-exported constants for parsing
458const ET_RawString = 0;
459const ET_QuotedString = 1;
460const ET_BracketString = 2;
461const ET_CurlyBracketString = 3;
462const ET_Eq = 4;
463const ET_Comma = 5;
464const ET_FileRef = 6;
465const EtMap = ...;
466
467const Suffixes = ("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th");
468
469// private scanner for parse_to_qore_value()
470list<hash> scan_exp(string arg);
471
472
473// private, non-exported function: tries to evaluate the argument as a Qore expression/value
474hash<auto> eval_text(string arg, bool err = False);
475
476
477// private, non-exported function: tries to evaluate the argument as a Qore expression/value
478/* returns the value parsed
479*/
480auto parse_to_basic_value(*string arg);
481
482
483string get_string_file_data(string loc);
484
485
486binary get_binary_file_data(string loc);
487
488
489auto get_file_ref(string type, string path);
490
491
493
600 auto parse_to_qore_value(string arg);
601
602
604
622 string serialize_to_string(auto val);
623
624
626
634 hash<UriQueryInfo> parse_uri_query(string path);
635
636
638
643 string make_uri_query(hash<UriQueryInfo> h, string arg_separator = ';');
644
645
647
663 string get_random_string(softint len = 15, int level = 3);
664
665
667
671 string get_exception_string(hash<auto> ex);
672
673
675const StorageNames = ("Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Zetta", "Yotta", "Bronto");
676
678const StorageAbbr = map {$1[0].lwr(): $#}, StorageNames;
679
681
689 string get_byte_size(softnumber n, int decimals = 2);
690
691
693
701 string get_marketing_byte_size(softnumber n, int decimals = 2);
702
703
705
716 bool same(list<auto> l);
717
718
720
730 list<auto> slice(list<auto> l, softlist<auto> indices);
731
732
734
753 string tmp_location();
754
755
757
774 bool is_int(string text, bool pure = False);
775
776
777const RE_FLOAT = ...;
778
779
781
798 bool is_float(string text, bool pure = False);
799
800
801const RE_NUMBER = ...;
802
803
805
823 bool is_number(string text, bool pure = False);
824
825
827
842 string lpad(softstring text, int length, string padding = ' ');
843
844
846
861 string rpad(softstring text, int length, string padding = ' ');
862
863
865
876 string ordinal(int i);
877
878
880
899 string plural(int count, string base, string singular = '', string plural = 's');
900
901
903
915 string regex_escape(string text);
916
917
919
931 string glob_to_regex(string pat);
932
933
935
946 list<auto> flatten(softlist<auto> arg);
947
948
950
961 list<int> parse_ranges(string text);
962
963
965
982 list<auto> uniq(softlist<auto> arg);
983
984
986
997 list<auto> zip();
998
999
1001
1015 bool check_ip_address(string ip, bool exception = False);
1016
1017
1019
1024 bool string_starts_with(string str, string substr);
1025
1026
1028
1033 bool string_ends_with(string str, string substr);
1034
1035
1037public hashdecl UrlRetrievalOptions {
1039 bool as_binary = False;
1040
1043
1045 *hash<auto> http_headers;
1046
1049
1052};
1053
1055
1063 data get_file_from_sftp(string url, string path, *hash<UrlRetrievalOptions> options);
1064
1065
1067
1075 data get_file_from_ftp(string url, string path, *hash<UrlRetrievalOptions> options);
1076
1077
1079
1085 data get_file_from_http(string url, *string path, *hash<UrlRetrievalOptions> options);
1086
1087
1089
1094 data get_local_file(string path, *hash<UrlRetrievalOptions> options);
1095
1096
1098
1105 data get_file_from_url(string url, *hash<UrlRetrievalOptions> options);
1106
1107
1109
1115 string substitute_env_vars(string str);
1116
1117
1119
1125 hash<ExceptionInfo> check_exception_serializable(hash<ExceptionInfo> ex);
1126
1127};
the Util namespace contains all the objects in the Util module
Definition Util.qm.dox.h:197
string normalize_dir_windows(string path, string cwd=getcwd())
returns a normalized Windows path name (eliminates ".", "..", and "//")
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,...
data get_file_from_http(string url, *string path, *hash< UrlRetrievalOptions > options)
Retrieves file data from an HTTP URL.
hash< ExceptionInfo > check_exception_serializable(hash< ExceptionInfo > ex)
Recursively ensure that exception arguments are serializable.
list< auto > zip()
Returns a list of lists, where the i-th list contains the i-th element from each of the argument list...
data get_file_from_ftp(string url, string path, *hash< UrlRetrievalOptions > options)
Retrieves file data from an FTP URL and a path.
string tmp_location()
Returns a path for temporary files.
list< auto > slice(list< auto > l, softlist< auto > indices)
list slice implementation
string make_uri_query(hash< UriQueryInfo > h, string arg_separator=';')
returns a serialized string for a UriQueryInfo hash
string serialize_to_string(auto val)
Serializes the given value to a string that can be deserialized with parse_to_qore_value()
bool same(list< auto > l)
checks whether given list has only unique elements
data get_local_file(string path, *hash< UrlRetrievalOptions > options)
Retrieves file data from a local file path.
string get_random_string(softint len=15, int level=3)
function that returns a random string
string ordinal(int i)
Returns string with partially textual representation of ordinal integer value.
string normalize_dir_unix(string path, string cwd=getcwd())
returns a normalized UNIX path name (starting from /, eliminates ".", "..", and "//")
string normalize_dir(string path, string cwd=getcwd())
returns a platform-specific normalized path name (starting from /, eliminates ".",...
bool is_number(string text, bool pure=False)
Checks whether string represents a (true) number value.
data get_file_from_sftp(string url, string path, *hash< UrlRetrievalOptions > options)
Retrieves file data from an SFTP URL and a path.
string lpad(softstring text, int length, string padding=' ')
Returns a string left-padded to a specified length with the specified characters.
list< auto > flatten(softlist< auto > arg)
Flattens a nested list (the nesting can be to any depth).
bool is_float(string text, bool pure=False)
Checks whether string represents a (true) float 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
bool absolute_path_windows(string path)
returns True if the argument is a Windows absolute path, False if not
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...
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...
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.
data get_file_from_url(string url, *hash< UrlRetrievalOptions > options)
Retrieves file data from the given URL.
string get_exception_string(hash< auto > ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
string substitute_env_vars(string str)
Substitutes environment variables in a string and returns the string.
bool string_starts_with(string str, string substr)
Verifies whether a string begins with specific substring.
const StorageNames
storage names (Geop, which would normally follow Bronto, is excluded as the abbreviation would be GB/...
Definition Util.qm.dox.h:675
string get_bit_string(int i, *int min_bits)
Returns a string of the bits set in an integer.
string regex_escape(string text)
Escapes (backslashes) all non-alphanumeric characters in a string.
list< int > parse_ranges(string text)
Parses a string and returns a list of integers.
int compare_version(string lv, string rv)
compares complex versions by breaking down strings into component parts
string plural(int count, string base, string singular='', string plural='s')
Returns string with number and proper singular/plural form of noun.
bool string_ends_with(string str, string substr)
Verifies whether a string ends with specific substring.
bool absolute_path_unix(string path)
returns True if the argument is a UNIX absolute path, False if not
bool check_ip_address(string ip, bool exception=False)
verifies if a string is an IPv4 or IPv6 address
bool is_int(string text, bool pure=False)
Checks whether string represents a (true) integer value.
int parse_memory_size(string str, *bool use_binary)
Returns a size in bytes from a string where "1M" = 1048576 and so forth.
list< auto > uniq(softlist< auto > arg)
Returns a duplicate-free version of the list.
string get_relative_path(string basedir, string path, string cwd=getcwd())
returns a path as a relative path from another directory
const StorageAbbr
hash of single-letter storage name abbreviations
Definition Util.qm.dox.h:678
bool absolute_path(string path)
returns True if the argument is an absolute path, False if not
Allowed value hash.
Definition Util.qm.dox.h:211
*string short_desc
A short description in plain text for the value.
Definition Util.qm.dox.h:216
auto value
The value itself.
Definition Util.qm.dox.h:219
*bool disabled
If the value is disabled.
Definition Util.qm.dox.h:228
string desc
Description for the value.
Definition Util.qm.dox.h:222
*list< hash< UiMessageInfo > > messages
Messages related to the value.
Definition Util.qm.dox.h:234
*string icon
Any icon info for the allowed value.
Definition Util.qm.dox.h:237
*string display_name
A display name for the allowed value.
Definition Util.qm.dox.h:213
*hash< auto > metadata
Any additional data about the value.
Definition Util.qm.dox.h:231
*string intent
Any UI intent associated with the value.
Definition Util.qm.dox.h:225
*string image
Any image info for the allowed value.
Definition Util.qm.dox.h:240
Message information for display to the user.
Definition Util.qm.dox.h:199
string intent
The intent of the message.
Definition Util.qm.dox.h:204
string content
The message content itself.
Definition Util.qm.dox.h:207
string title
The title of the message.
Definition Util.qm.dox.h:201
the return value of the parse_uri_query() function
Definition Util.qm.dox.h:246
*hash< auto > params
Query parameters.
Definition Util.qm.dox.h:262
string method
The URI method.
Definition Util.qm.dox.h:251
*hash< auto > path_params
Path params; only when matching a request with a REST schema.
Definition Util.qm.dox.h:267
URL retrieval options for get_file_from_url()
Definition Util.qm.dox.h:1037
*string ssh2_private_key
SSH2 private key path.
Definition Util.qm.dox.h:1048
bool as_binary
Return the file data as binary data; if False (the default), a string will be returned.
Definition Util.qm.dox.h:1039
*hash< auto > http_headers
HTTP headers to add to any HTTP GET request.
Definition Util.qm.dox.h:1045
*string default_path
The default path for files with relative paths.
Definition Util.qm.dox.h:1042
*string ssh2_public_key
SSH2 public key path.
Definition Util.qm.dox.h:1051