Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 1 | OPTIONAL |
| 2 | SYNOPSIS |
| 3 | string process_string(string str) |
| 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 5 | DESCRIPTION |
| 6 | Searches string str for occurrences of a "value by function |
| 7 | call", which is an implicit function call surrounded by @@. See |
| 8 | "value_by_function_call" in the principles section. |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 10 | The value should contain a string like this: |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 11 | @@function[:filename][|arg|arg]@@ |
| 12 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 13 | <function> must return a string or else the string which should be |
| 14 | processed will be returned unchanged. |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 15 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 16 | process_string() does not recurse over returned |
| 17 | replacement values. If a function returns another function |
| 18 | description, that description will not be replaced. |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 19 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 20 | Both the filename and the args are optional. |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 21 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 22 | Consecutive function calls can be written adjacent: |
| 23 | |
| 24 | @@function1@@function2@@ |
| 25 | |
| 26 | EXAMPLES |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 27 | string foo(string str) { |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 28 | return "ab"+str+"ef"; |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 29 | } |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 30 | void func() { |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 31 | write(process_string("@@foo|cd@@")+"\n"); |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 34 | The function func() will print out the string "abcdef". |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 35 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 36 | BUGS |
| 37 | Using process_string() can lead to severe security problems. |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 38 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 39 | HISTORY |
| 40 | Because of the security problems, process_string() is an |
| 41 | optional efun since 3.2.1@34 |
| 42 | LDMud 3.3.160 removed the undocumented 'feature' that a function call |
| 43 | declaration could be terminated by a space. In turn this now allows |
| 44 | the use of arguments with spaces. |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 45 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 46 | SEE ALSO |
Zesstra | 9ef23d0 | 2020-09-03 19:48:47 +0200 | [diff] [blame] | 47 | notify_fail(E), closures(LPC), get_bb_uid(M) |