Commit 2d8091d5b5ae5c9458c07d6970459bde19813b27
1 parent
6f6c93dc
improve of replace web arg
Showing
1 changed file
with
52 additions
and
5 deletions
Show diff stats
web/CXM_web_arg_utils.anubis
| ... | ... | @@ -29,23 +29,70 @@ public define One |
| 29 | 29 | lwa <- [ w_arg . *lwa] |
| 30 | 30 | . |
| 31 | 31 | |
| 32 | +define List(Web_arg) | |
| 33 | + _remove_web_arg | |
| 34 | + ( | |
| 35 | + List(Web_arg) lwa, | |
| 36 | + String arg_name | |
| 37 | + )= | |
| 38 | + if lwa is | |
| 39 | + { | |
| 40 | + [] then [], | |
| 41 | + [h . t] then | |
| 42 | + if h is web_arg(name, _) then | |
| 43 | + if name = arg_name then | |
| 44 | + t | |
| 45 | + else | |
| 46 | + [h . _remove_web_arg(t, arg_name)] | |
| 47 | + else | |
| 48 | + [h . _remove_web_arg(t, arg_name)] | |
| 49 | + } | |
| 50 | +. | |
| 51 | + | |
| 32 | 52 | public define One |
| 33 | 53 | remove_web_arg |
| 34 | 54 | ( |
| 35 | 55 | Var(List(Web_arg)) lwa, |
| 36 | 56 | String arg_name |
| 37 | 57 | )= |
| 38 | - lwa <- map_select((Web_arg w_arg) |-> if w_arg is web_arg(name, value) then if name = arg_name then failure else success(w_arg) else success(w_arg), *lwa) | |
| 58 | + lwa <- _remove_web_arg(*lwa, arg_name) | |
| 59 | +. | |
| 60 | + | |
| 61 | +define List(Web_arg) | |
| 62 | + _replace_web_arg | |
| 63 | + ( | |
| 64 | + List(Web_arg) lwa, | |
| 65 | + String arg_name, | |
| 66 | + String value | |
| 67 | + )= | |
| 68 | + if lwa is | |
| 69 | + { | |
| 70 | + [] then /*println("arg_name "+arg_name+" not found, add it");*/[web_arg(arg_name, value)], | |
| 71 | + [h . t] then | |
| 72 | + if h is web_arg(name, _) then | |
| 73 | + if name = arg_name then | |
| 74 | + [web_arg(name, value) . t] | |
| 75 | + else | |
| 76 | + [h . _replace_web_arg(t, arg_name, value)] | |
| 77 | + else | |
| 78 | + [h . _replace_web_arg(t, arg_name, value)] | |
| 79 | + } | |
| 39 | 80 | . |
| 40 | 81 | |
| 41 | 82 | public define One |
| 83 | +/* replace the value of given web argument name in the list. Replace the value of the first found | |
| 84 | + * argument. | |
| 85 | + * If the web argument is not found, an entry is created for this WEB argument name with given | |
| 86 | + * value | |
| 87 | + */ | |
| 42 | 88 | replace_web_arg |
| 43 | 89 | ( |
| 44 | - Var(List(Web_arg)) lwa, | |
| 45 | - String arg_name, | |
| 46 | - String value | |
| 90 | + Var(List(Web_arg)) lwa, //current list of web argument | |
| 91 | + String arg_name, //web argument name to replace | |
| 92 | + String value //value to replace | |
| 47 | 93 | )= |
| 48 | - lwa <- map_select((Web_arg w_arg) |-> if w_arg is web_arg(name, value) then if name = arg_name then success(web_arg(name, value)) else success(w_arg) else success(w_arg), *lwa) | |
| 94 | + //println("replace web arg name "+arg_name+" value "+value); | |
| 95 | + lwa <- _replace_web_arg(*lwa, arg_name, value) | |
| 49 | 96 | . |
| 50 | 97 | |
| 51 | 98 | ... | ... |