data.paramsparser #
Params
import freeflowuniverse.crystallib.data.paramsparser
mut p:=paramsparser.new('
id:a1 name6:aaaaa
name:'need to do something 1'
)!
assert "a1"==p.get_default("id","")!
'
example text to parse
id:a1 name6:aaaaa
name:'need to do something 1'
description:
#
description can be multiline
lets see what happens
- a
- something else
#
name2: test
name3: hi name10:'this is with space' name11:aaa11
#
name4: 'aaa'
//somecomment
name5: 'aab'
results in
Params{
params: [Param{
key: 'id'
value: 'a1'
}, Param{
key: 'name6'
value: 'aaaaa'
}, Param{
key: 'name'
value: 'need to do something 1'
}, Param{
key: 'description'
value: '## markdown works in it
description can be multiline
lets see what happens
- a
- something else
### subtitle
'
}, Param{
key: 'name2'
value: 'test'
}, Param{
key: 'name3'
value: 'hi'
}, Param{
key: 'name10'
value: 'this is with space'
}, Param{
key: 'name11'
value: 'aaa11'
}, Param{
key: 'name4'
value: 'aaa'
}, Param{
key: 'name5'
value: 'aab'
}]
}
fn encode #
fn encode[T](t T, args EncodeArgs) !Params
fn from_resp #
fn from_resp(data []u8) !Params
fn importparams #
fn importparams(txt string) !Params
fn json_import #
fn json_import(data string) !Params
fn new #
fn new(txt string) !Params
get params from txt, same as parse()
fn new_from_dict #
fn new_from_dict(kwargs map[string]string) !Params
fn new_params #
fn new_params() Params
fn parse #
fn parse(text string) !Params
convert text with e.g. color:red or color:'red' to arguments multiline is supported result is params object which allows you to query the info you need params is following:
struct Params { params []Param args []Arg } struct Arg { value string } struct Param { key string value string } it has nice methods to query the params
struct EncodeArgs #
struct EncodeArgs {
pub:
recursive bool = true
}
struct ExportArgs #
struct ExportArgs {
pub mut:
presort []string
postsort []string
sortdefault bool = true // if set will do the default sorting
args_allowed bool = true
args_remove bool
comments_remove bool
maxcolsize int = 120
oneline bool // if set then will put all on oneline
multiline bool = true // if we will put the multiline strings as multiline in output
indent string
pre string // e.g. can be used to insert action e.g. !!remark.define (pre=prefix on the first line)
skip_empty bool
}
struct Param #
struct Param {
pub mut:
key string
value string
comment string
}
struct Params #
struct Params {
pub mut:
params []Param
args []string
comments []string
}
fn (Params) add #
fn (mut params Params) add(txt string) !
parse new txt as params and merge into params
fn (Params) check_arg_len #
fn (params &Params) check_arg_len(checknrargs int) !
fn (Params) decode #
fn (params Params) decode[T]() !T
fn (Params) decode_struct #
fn (params Params) decode_struct[T](_ T) !T
fn (Params) decode_value #
fn (params Params) decode_value[T](_ T, key string) !T
fn (Params) delete #
fn (mut params Params) delete(key string)
fn (Params) delete_arg #
fn (mut params Params) delete_arg(key string)
fn (Params) empty #
fn (p Params) empty() bool
fn (Params) equal #
fn (p Params) equal(p2 Params) bool
fn (Params) exists #
fn (params &Params) exists(key_ string) bool
check if kwarg exist line: arg1 arg2 color:red priority:'incredible' description:'with spaces, lets see if ok arg1 is an arg description is a kwarg
fn (Params) exists_arg #
fn (params &Params) exists_arg(key_ string) bool
check if arg exist (arg is just a value in the string e.g. red, not value:something) line: arg1 arg2 color:red priority:'incredible' description:'with spaces, lets see if ok arg1 is an arg description is a kwarg
fn (Params) export #
fn (p Params) export(args ExportArgs) string
standardised export format . . it outputs a default way sorted and readable .
presort []string
postsort []string
sortdefault bool = true //if set will do the default sorting
args_allowed bool = true
args_remove bool
comments_remove bool
maxcolsize int = 120
oneline bool // if set then will put all on oneline
multiline bool = true // if we will put the multiline strings as multiline in output
indent string
pre string // e.g. can be used to insert action e.g. !!remark.define (pre=prefix on the first line)
fn (Params) export_json #
fn (mut params Params) export_json() string
pub struct ParamPub { pub: key string value string }
fn (Params) filter_match #
fn (params Params) filter_match(myfilter ParamsFilter) !bool
will return true if the params object match the filter (include and excludes) will first do the include filter then exclude, which means if matched and exclude is then matched won't count uses the filter_item function for each include or excluse (see further)
fn (Params) filter_match_item #
fn (params Params) filter_match_item(myfilter string) !bool
match params for 1 string based match can be e.g.- hr+development, means look for argument hr or development
- devel*, look for an argument which starts with devel (see match_glob)
- color:red, look for a value with key color, which has 'red' string insidematch_glob matches the string, with a Unix shell-style wildcard pattern The special characters used in shell-style wildcards are:* - matches everything? - matches any single character [seq] - matches any of the characters in the sequence [^seq] - matches any character that is NOT in the sequence Any other character in pattern, is matched 1:1 to the corresponding character in name, including / and . You can wrap the meta-characters in brackets too, i.e. [?] matches ? in the string, and [*] matches * in the string.
fn (Params) get #
fn (params &Params) get(key_ string) !string
see if the kwarg with the key exists if yes return as string trimmed
fn (Params) get_arg #
fn (params &Params) get_arg(nr int) !string
return the arg with nr, 0 is the first
fn (Params) get_arg_check #
fn (params &Params) get_arg_check(nr int, checknrargs int) !string
return the arg with nr, 0 is the first check the length of the args
fn (Params) get_arg_default #
fn (params &Params) get_arg_default(nr int, defval string) !string
return arg, if the nr is larger than amount of args, will return the defval
fn (Params) get_arg_int #
fn (params &Params) get_arg_int(nr int) !int
get arg return as int, if checknrargs is not 0, it will make sure the nr of args corresponds
fn (Params) get_arg_int_default #
fn (params &Params) get_arg_int_default(nr int, defval int) !int
get arg return as int. defval is the default value specified
fn (Params) get_currencyamount #
fn (params &Params) get_currencyamount(key string) !currency.Amount
Todo: fix if necessarysee currency object, gets it from params
fn (Params) get_currencyamount_default #
fn (params &Params) get_currencyamount_default(key string, defval string) !currency.Amount
fn (Params) get_currencyfloat #
fn (params &Params) get_currencyfloat(key string) !f64
get currency expressed in float in line to currency passed
fn (Params) get_currencyfloat_default #
fn (params &Params) get_currencyfloat_default(key string, defval f64) !f64
fn (Params) get_default #
fn (params &Params) get_default(key string, defval string) !string
get kwarg return as string, ifn't exist return the defval line: arg1 arg2 color:red priority:'incredible' description:'with spaces, lets see if ok arg1 is an arg description is a kwarg
fn (Params) get_default_false #
fn (params &Params) get_default_false(key string) bool
fn (Params) get_default_true #
fn (params &Params) get_default_true(key string) bool
fn (Params) get_email #
fn (params &Params) get_email(key string) !string
fn (Params) get_emails #
fn (params &Params) get_emails(key string) ![]string
fn (Params) get_emails_default #
fn (params &Params) get_emails_default(key string, default []string) ![]string
fn (Params) get_float #
fn (params &Params) get_float(key string) !f64
fn (Params) get_float_default #
fn (params &Params) get_float_default(key string, defval f64) !f64
fn (Params) get_from_hashmap #
fn (params &Params) get_from_hashmap(key_ string, defval string, hashmap map[string]string) !string
fn (Params) get_int #
fn (params &Params) get_int(key string) !int
get kwarg return as int line: arg1 arg2 color:red priority:'incredible' description:'with spaces, lets see if ok arg1 is an arg description is a kwarg
fn (Params) get_int_default #
fn (params &Params) get_int_default(key string, defval int) !int
get kwarg return as int, if it doesnt' exist return a default line: arg1 arg2 color:red priority:'incredible' description:'with spaces, lets see if ok arg1 is an arg description is a kwarg
fn (Params) get_list #
fn (params &Params) get_list(key string) ![]string
Looks for a list of strings in the parameters. If it doesn't exist this function will return an error. Furthermore an error will be returned if the list is not properly formatted Examples of valid lists: ["example", "another_example", "yes"] ['example', 'another_example'] ['example "yes yes"', "another_example", "yes"] Invalid examples: [example, example, example] ['example, example, example]
fn (Params) get_list_default #
fn (params &Params) get_list_default(key string, def []string) ![]string
Looks for a list of strings in the parameters. If it doesn't exist this function the provided default value. Furthermore an error will be returned if the parameter exists and it's not a valid list. Please look at get_list for examples of valid and invalid lists
fn (Params) get_list_f32 #
fn (params &Params) get_list_f32(key string) ![]f32
Looks for a list of f32 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_f32_default #
fn (params &Params) get_list_f32_default(key string, def []f32) []f32
Looks for a list of f32 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_f64 #
fn (params &Params) get_list_f64(key string) ![]f64
Looks for a list of f64 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_f64_default #
fn (params &Params) get_list_f64_default(key string, def []f64) []f64
Looks for a list of f64 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_i16 #
fn (params &Params) get_list_i16(key string) ![]i16
Looks for a list of i16 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_i16_default #
fn (params &Params) get_list_i16_default(key string, def []i16) []i16
Looks for a list of i16 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_i64 #
fn (params &Params) get_list_i64(key string) ![]i64
Looks for a list of i64 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_i64_default #
fn (params &Params) get_list_i64_default(key string, def []i64) []i64
Looks for a list of i64 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_i8 #
fn (params &Params) get_list_i8(key string) ![]i8
Looks for a list of i8 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_i8_default #
fn (params &Params) get_list_i8_default(key string, def []i8) []i8
Looks for a list of i8 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_int #
fn (params &Params) get_list_int(key string) ![]int
Looks for a list of int with the provided key. If it does not exist an error is returned.
fn (Params) get_list_int_default #
fn (params &Params) get_list_int_default(key string, def []int) []int
Looks for a list of int with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_namefix #
fn (params &Params) get_list_namefix(key string) ![]string
Looks for a list of strings in the parameters. If it doesn't exist this function returns an error. Furthermore an error will be returned if the parameter exists and it's not a valid list. The items in the list will be namefixed
fn (Params) get_list_namefix_default #
fn (params &Params) get_list_namefix_default(key string, def []string) ![]string
Looks for a list of strings in the parameters. If it doesn't exist this function returns the provided default value. Furthermore an error will be returned if the parameter exists and it's not a valid list. The items in the list will be namefixed
fn (Params) get_list_u16 #
fn (params &Params) get_list_u16(key string) ![]u16
Looks for a list of u16 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_u16_default #
fn (params &Params) get_list_u16_default(key string, def []u16) []u16
Looks for a list of u16 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_u32 #
fn (params &Params) get_list_u32(key string) ![]u32
Looks for a list of u32 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_u32_default #
fn (params &Params) get_list_u32_default(key string, def []u32) []u32
Looks for a list of u32 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_u64 #
fn (params &Params) get_list_u64(key string) ![]u64
Looks for a list of u64 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_u64_default #
fn (params &Params) get_list_u64_default(key string, def []u64) []u64
Looks for a list of u64 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_list_u8 #
fn (params &Params) get_list_u8(key string) ![]u8
Looks for a list of u8 with the provided key. If it does not exist an error is returned.
fn (Params) get_list_u8_default #
fn (params &Params) get_list_u8_default(key string, def []u8) []u8
Looks for a list of u8 with the provided key. If it does not exist the provided default value is returned.
fn (Params) get_map #
fn (params &Params) get_map() map[string]string
fn (Params) get_params #
fn (params &Params) get_params(key string) !Params
Looks for a string of params in the parameters. If it doesn't exist this function will return an error. Furthermore an error will be returned if the params is not properly formatted
fn (Params) get_path #
fn (params &Params) get_path(key string) !string
fn (Params) get_path_create #
fn (params &Params) get_path_create(key string) !string
create the path if it doesn't exist
fn (Params) get_percentage #
fn (params &Params) get_percentage(key string) !f64
fn (Params) get_percentage_default #
fn (params &Params) get_percentage_default(key string, defval string) !f64
fn (Params) get_storagecapacity_in_bytes #
fn (params &Params) get_storagecapacity_in_bytes(key string) !u64
convert GB, MB, KB to bytes e.g. 10 GB becomes bytes in u64
fn (Params) get_storagecapacity_in_bytes_default #
fn (params &Params) get_storagecapacity_in_bytes_default(key string, defval u64) !u64
fn (Params) get_storagecapacity_in_gigabytes #
fn (params &Params) get_storagecapacity_in_gigabytes(key string) !u64
Parses the provided value to gigabytes, the value is rounded up while doing so.
fn (Params) get_telnr #
fn (params &Params) get_telnr(key string) !string
fn (Params) get_telnrs #
fn (params &Params) get_telnrs(key string) ![]string
fn (Params) get_telnrs_default #
fn (params &Params) get_telnrs_default(key string, default []string) ![]string
fn (Params) get_time #
fn (params &Params) get_time(key string) !ourtime.OurTime
Get Expiration object from time string input input can be either relative or absolute## Relative time
time periods:
- s -> second
- h -> hour
- d -> day
- w -> week
- M -> month
- Q -> quarter
- Y -> year0 means right now input string example: "+1w +2d -4h"## Absolute timeinputs must be of the form: "YYYY-MM-DD HH:mm:ss" or "YYYY-MM-DD" input string examples: '2022-12-5 20:14:35' '2022-12-5' - sets hours, mins, seconds to 00
fn (Params) get_time_default #
fn (params &Params) get_time_default(key string, defval ourtime.OurTime) !ourtime.OurTime
fn (Params) get_time_interval #
fn (params &Params) get_time_interval(key string) !Duration
calculate difference in time, returled as u64 (is Duration type) format e.g. QUESTION: splitting by - doesn't work? Alternative?
fn (Params) get_timestamp #
fn (params &Params) get_timestamp(key string) !Duration
Parses a timestamp. Can be 12h or 24h format
fn (Params) get_timestamp_default #
fn (params &Params) get_timestamp_default(key string, defval Duration) !Duration
fn (Params) get_u32 #
fn (params &Params) get_u32(key string) !u32
fn (Params) get_u32_default #
fn (params &Params) get_u32_default(key string, defval u32) !u32
fn (Params) get_u64 #
fn (params &Params) get_u64(key string) !u64
fn (Params) get_u64_default #
fn (params &Params) get_u64_default(key string, defval u64) !u64
fn (Params) get_u8 #
fn (params &Params) get_u8(key string) !u8
fn (Params) get_u8_default #
fn (params &Params) get_u8_default(key string, defval u8) !u8
fn (Params) heroscript #
fn (p Params) heroscript() string
fn (Params) hexhash #
fn (p Params) hexhash() string
returns a unique sha256 in hex, will allways return the same independent of order of params
fn (Params) len_arg #
fn (params &Params) len_arg() int
fn (Params) merge #
fn (mut params Params) merge(params_to_merge Params) !
fn (Params) replace #
fn (mut params Params) replace(args map[string]string)
find parts of text in PARAM values which are of form {NAME}, and replace those . . will walk over all elements of the params, and then replace all the values . . NAME is as follows: . Uppercase letters: A-Z . Lowercase letters: a-z . Digits: 0-9 . Underscore: _ . . the NAME is key of the map, the val of the map is what we replace with
fn (Params) replace_from_params #
fn (mut params Params) replace_from_params(params_ Params)
fn (Params) set #
fn (mut params Params) set(key string, value string)
fn (Params) set_arg #
fn (mut params Params) set_arg(value string)
fn (Params) set_arg_with_comment #
fn (mut params Params) set_arg_with_comment(value string, comment string)
fn (Params) set_with_comment #
fn (mut params Params) set_with_comment(key string, value string, comment string)
fn (Params) to_resp #
fn (mut p Params) to_resp() ![]u8
encode using resp (redis procotol)
struct ParamsFilter #
struct ParamsFilter {
pub mut:
include []string
exclude []string
}
- README
- fn encode
- fn from_resp
- fn importparams
- fn json_import
- fn new
- fn new_from_dict
- fn new_params
- fn parse
- struct EncodeArgs
- struct ExportArgs
- struct Param
- struct Params
- fn add
- fn check_arg_len
- fn decode
- fn decode_struct
- fn decode_value
- fn delete
- fn delete_arg
- fn empty
- fn equal
- fn exists
- fn exists_arg
- fn export
- fn export_json
- fn filter_match
- fn filter_match_item
- fn get
- fn get_arg
- fn get_arg_check
- fn get_arg_default
- fn get_arg_int
- fn get_arg_int_default
- fn get_currencyamount
- fn get_currencyamount_default
- fn get_currencyfloat
- fn get_currencyfloat_default
- fn get_default
- fn get_default_false
- fn get_default_true
- fn get_email
- fn get_emails
- fn get_emails_default
- fn get_float
- fn get_float_default
- fn get_from_hashmap
- fn get_int
- fn get_int_default
- fn get_list
- fn get_list_default
- fn get_list_f32
- fn get_list_f32_default
- fn get_list_f64
- fn get_list_f64_default
- fn get_list_i16
- fn get_list_i16_default
- fn get_list_i64
- fn get_list_i64_default
- fn get_list_i8
- fn get_list_i8_default
- fn get_list_int
- fn get_list_int_default
- fn get_list_namefix
- fn get_list_namefix_default
- fn get_list_u16
- fn get_list_u16_default
- fn get_list_u32
- fn get_list_u32_default
- fn get_list_u64
- fn get_list_u64_default
- fn get_list_u8
- fn get_list_u8_default
- fn get_map
- fn get_params
- fn get_path
- fn get_path_create
- fn get_percentage
- fn get_percentage_default
- fn get_storagecapacity_in_bytes
- fn get_storagecapacity_in_bytes_default
- fn get_storagecapacity_in_gigabytes
- fn get_telnr
- fn get_telnrs
- fn get_telnrs_default
- fn get_time
- fn get_time_default
- fn get_time_interval
- fn get_timestamp
- fn get_timestamp_default
- fn get_u32
- fn get_u32_default
- fn get_u64
- fn get_u64_default
- fn get_u8
- fn get_u8_default
- fn heroscript
- fn hexhash
- fn len_arg
- fn merge
- fn replace
- fn replace_from_params
- fn set
- fn set_arg
- fn set_arg_with_comment
- fn set_with_comment
- fn to_resp
- struct ParamsFilter