Skip to content

Commit f64ba62

Browse files
committed
feat: Add Tier 1-2 ZRTL plugins (string, json, regex, process)
New plugins: - zrtl_string: String manipulation (45+ functions) - Basic: length, concat, repeat, join - Case: to_upper, to_lower, capitalize, to_title - Trim: trim, trim_start, trim_end - Search: contains, starts_with, ends_with, index_of, count - Replace: replace, replace_all, remove - Extract: substring, char_at, split, lines - Padding: pad_start, pad_end - Conversion: parse_int, parse_float, from_int, from_float - Comparison: compare, equals (case-sensitive and insensitive) - zrtl_json: JSON parsing and manipulation - Handle-based API for JSON values - Parse/stringify with pretty-print option - Type checking (null, bool, number, string, array, object) - Object access: get, set, has, keys, remove - Array access: length, get, set, push, pop - Constructors: null, bool, int, float, string, array, object - JSONPath-like access via dot-notation paths - zrtl_regex: Regular expression matching - Pattern compilation with case-insensitive option - Matching: is_match, find, find_all, count - Replacement: replace_first, replace_all - Capture groups: capture, captures - Splitting: split, splitn - Quick functions for one-off operations - Escape utility for literal strings - zrtl_process: Subprocess execution - Quick execution: run, run_capture, shell, shell_capture - Process management: spawn, wait, kill, is_running, id - I/O: read_stdout, read_stderr, write_stdin, close_stdin - Utility: current_pid, command_exists Updated book chapter 14 with documentation for all new plugins. Total plugins: 11 (IO, FS, Time, Thread, Net, Env, Math, String, JSON, Regex, Process)
1 parent 5a1ba37 commit f64ba62

10 files changed

Lines changed: 2566 additions & 0 deletions

File tree

book/14-runtime-plugins.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,91 @@ Mathematical functions for numerical computation.
206206
| `$Math$to_radians` | `(f64) -> f64` | Degrees to radians |
207207
| `$Math$to_degrees` | `(f64) -> f64` | Radians to degrees |
208208

209+
### zrtl_string - String Manipulation
210+
211+
String manipulation and formatting functions.
212+
213+
| Symbol | Signature | Description |
214+
|--------|-----------|-------------|
215+
| `$String$length` | `(StringPtr) -> i64` | Get byte length |
216+
| `$String$char_count` | `(StringPtr) -> i64` | Get character count (Unicode) |
217+
| `$String$is_empty` | `(StringPtr) -> i32` | Check if empty |
218+
| `$String$concat` | `(StringPtr, StringPtr) -> StringPtr` | Concatenate strings |
219+
| `$String$repeat` | `(StringPtr, i64) -> StringPtr` | Repeat n times |
220+
| `$String$to_upper` | `(StringPtr) -> StringPtr` | Convert to uppercase |
221+
| `$String$to_lower` | `(StringPtr) -> StringPtr` | Convert to lowercase |
222+
| `$String$trim` | `(StringPtr) -> StringPtr` | Trim whitespace |
223+
| `$String$contains` | `(StringPtr, StringPtr) -> i32` | Check if contains |
224+
| `$String$starts_with` | `(StringPtr, StringPtr) -> i32` | Check prefix |
225+
| `$String$ends_with` | `(StringPtr, StringPtr) -> i32` | Check suffix |
226+
| `$String$index_of` | `(StringPtr, StringPtr) -> i64` | Find first index |
227+
| `$String$replace_all` | `(StringPtr, StringPtr, StringPtr) -> StringPtr` | Replace all |
228+
| `$String$substring` | `(StringPtr, i64, i64) -> StringPtr` | Extract substring |
229+
| `$String$split` | `(StringPtr, StringPtr) -> ArrayPtr` | Split by delimiter |
230+
| `$String$parse_int` | `(StringPtr) -> i64` | Parse as integer |
231+
| `$String$parse_float` | `(StringPtr) -> f64` | Parse as float |
232+
| `$String$from_int` | `(i64) -> StringPtr` | Integer to string |
233+
| `$String$from_float` | `(f64) -> StringPtr` | Float to string |
234+
235+
### zrtl_json - JSON Parsing
236+
237+
JSON parsing and manipulation using opaque handles.
238+
239+
| Symbol | Signature | Description |
240+
|--------|-----------|-------------|
241+
| `$Json$parse` | `(StringPtr) -> u64` | Parse JSON string |
242+
| `$Json$stringify` | `(u64) -> StringPtr` | Convert to JSON string |
243+
| `$Json$free` | `(u64) -> void` | Free JSON handle |
244+
| `$Json$get_type` | `(u64) -> i32` | Get type (0=null,1=bool,2=num,3=str,4=arr,5=obj) |
245+
| `$Json$get_bool` | `(u64) -> i32` | Get boolean value |
246+
| `$Json$get_int` | `(u64) -> i64` | Get integer value |
247+
| `$Json$get_float` | `(u64) -> f64` | Get float value |
248+
| `$Json$get_string` | `(u64) -> StringPtr` | Get string value |
249+
| `$Json$get` | `(u64, StringPtr) -> u64` | Get object property |
250+
| `$Json$set` | `(u64, StringPtr, u64) -> void` | Set object property |
251+
| `$Json$array_length` | `(u64) -> i64` | Get array length |
252+
| `$Json$array_get` | `(u64, i64) -> u64` | Get array element |
253+
| `$Json$object` | `() -> u64` | Create empty object |
254+
| `$Json$array` | `() -> u64` | Create empty array |
255+
| `$Json$path_get` | `(u64, StringPtr) -> u64` | Get by dot-path |
256+
257+
### zrtl_regex - Regular Expressions
258+
259+
Regex matching and replacement using compiled patterns.
260+
261+
| Symbol | Signature | Description |
262+
|--------|-----------|-------------|
263+
| `$Regex$compile` | `(StringPtr) -> u64` | Compile pattern |
264+
| `$Regex$free` | `(u64) -> void` | Free pattern handle |
265+
| `$Regex$matches` | `(u64, StringPtr) -> i32` | Check if matches |
266+
| `$Regex$find_match` | `(u64, StringPtr) -> StringPtr` | Find first match |
267+
| `$Regex$find_all` | `(u64, StringPtr) -> ArrayPtr` | Find all matches |
268+
| `$Regex$replace_first` | `(u64, StringPtr, StringPtr) -> StringPtr` | Replace first |
269+
| `$Regex$replace_all_compiled` | `(u64, StringPtr, StringPtr) -> StringPtr` | Replace all |
270+
| `$Regex$capture` | `(u64, StringPtr, i32) -> StringPtr` | Get capture group |
271+
| `$Regex$split` | `(u64, StringPtr) -> ArrayPtr` | Split by pattern |
272+
| `$Regex$is_match` | `(StringPtr, StringPtr) -> i32` | Quick match check |
273+
| `$Regex$replace_all` | `(StringPtr, StringPtr, StringPtr) -> StringPtr` | Quick replace |
274+
275+
### zrtl_process - Subprocess Execution
276+
277+
Process spawning and management.
278+
279+
| Symbol | Signature | Description |
280+
|--------|-----------|-------------|
281+
| `$Process$run` | `(StringPtr, ArrayPtr) -> i32` | Run command, return exit code |
282+
| `$Process$run_capture` | `(StringPtr, ArrayPtr) -> StringPtr` | Run and capture stdout |
283+
| `$Process$shell` | `(StringPtr) -> i32` | Run shell command |
284+
| `$Process$shell_capture` | `(StringPtr) -> StringPtr` | Shell with capture |
285+
| `$Process$spawn` | `(StringPtr, ArrayPtr) -> u64` | Spawn process |
286+
| `$Process$wait` | `(u64) -> i32` | Wait for completion |
287+
| `$Process$kill` | `(u64) -> i32` | Kill process |
288+
| `$Process$is_running` | `(u64) -> i32` | Check if running |
289+
| `$Process$read_stdout` | `(u64) -> StringPtr` | Read stdout |
290+
| `$Process$write_stdin` | `(u64, StringPtr) -> i32` | Write to stdin |
291+
| `$Process$current_pid` | `() -> u32` | Get current PID |
292+
| `$Process$command_exists` | `(StringPtr) -> i32` | Check if command exists |
293+
209294
## Building Plugins
210295

211296
### Dynamic Libraries (.zrtl)
@@ -225,6 +310,10 @@ zrtl_thread.zrtl
225310
zrtl_net.zrtl
226311
zrtl_env.zrtl
227312
zrtl_math.zrtl
313+
zrtl_string.zrtl
314+
zrtl_json.zrtl
315+
zrtl_regex.zrtl
316+
zrtl_process.zrtl
228317
plugins.json
229318
```
230319

plugins/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ members = [
88
"zrtl_time",
99
"zrtl_env",
1010
"zrtl_math",
11+
"zrtl_string",
12+
"zrtl_json",
13+
"zrtl_regex",
14+
"zrtl_process",
1115
]
1216

1317
[workspace.dependencies]

plugins/zrtl_json/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "zrtl_json"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "ZRTL JSON plugin - JSON parsing and serialization"
6+
license = "Apache-2.0"
7+
8+
[lib]
9+
crate-type = ["cdylib", "staticlib", "rlib"]
10+
11+
[dependencies]
12+
zrtl = { path = "../../sdk/zrtl" }
13+
serde_json = "1.0"

0 commit comments

Comments
 (0)