feat(stdlib): Mid M1 regex and encoding libraries
Add lib/re and lib/encoding (EN/ZH) backed by host_re_* and host_encoding_*, with golds, public demos, and design docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1a5ee57a6f
commit
838a2b425a
26 files changed
+702
-13
No files matched your search
@@ -1066,6 +1066,35 @@ fn lib_fs_read() {
|
||||
assert_out("tests/lib/fs-read.mq.md", "exists\nhello-lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_re_smoke() {
|
||||
assert_out(
|
||||
"tests/lib/re-smoke.mq.md",
|
||||
"True\n12\n1,22,333\naXbXc3\na|b|c",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_re_smoke_zh() {
|
||||
assert_out("tests/lib/正则-烟测.mq.md", "True\n12\n1,22,333");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_encoding_smoke() {
|
||||
assert_out(
|
||||
"tests/lib/encoding-smoke.mq.md",
|
||||
"aGVsbG8=\nhello\n6869\nhi",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_encoding_smoke_zh() {
|
||||
assert_out(
|
||||
"tests/lib/编码-烟测.mq.md",
|
||||
"aGVsbG8=\nhello\n6869\nhi",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_fs_read_zh() {
|
||||
assert_out("tests/lib/文件-读.mq.md", "存在\nhello-lib");
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: lib/encoding smoke
|
||||
import enc:lib/encoding.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*b = > enc.base64_encode text="hello"*
|
||||
> print text=`b`
|
||||
|
||||
*back = > enc.base64_decode text=`b`*
|
||||
> print text=`back`
|
||||
|
||||
*h = > enc.hex_encode text="hi"*
|
||||
> print text=`h`
|
||||
|
||||
*hb = > enc.hex_decode text=`h`*
|
||||
> print text=`hb`
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
title: lib/re smoke
|
||||
import re:lib/re.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*ok = > re.is_match text="abc123" pattern="\\d+"*
|
||||
> print text=`ok`
|
||||
|
||||
*m = > re.find text="ab12cd34" pattern="\\d+"*
|
||||
> print text=`m`
|
||||
|
||||
*all = > re.find_all text="a1b22c333" pattern="\\d+"*
|
||||
*joined = > join value=`all` sep=","*
|
||||
> print text=`joined`
|
||||
|
||||
*rep = > re.replace text="a1b2c3" pattern="\\d+" with="X" count=2*
|
||||
> print text=`rep`
|
||||
|
||||
*parts = > re.split text="a-b-c" pattern="-"*
|
||||
*pj = > join value=`parts` sep="|"*
|
||||
> print text=`pj`
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
title: lib/正则 烟测
|
||||
导入 正则:lib/正则.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*ok = > 正则.匹配 内容="abc123" 模式="\\d+"*
|
||||
> 打印 内容=`ok`
|
||||
|
||||
*m = > 正则.查找 内容="ab12cd34" 模式="\\d+"*
|
||||
> 打印 内容=`m`
|
||||
|
||||
*all = > 正则.查找全部 内容="a1b22c333" 模式="\\d+"*
|
||||
*joined = > join value=`all` sep=","*
|
||||
> 打印 内容=`joined`
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: lib/编码 烟测
|
||||
导入 编码:lib/编码.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*b = > 编码.基64编码 内容="hello"*
|
||||
> 打印 内容=`b`
|
||||
|
||||
*back = > 编码.基64解码 内容=`b`*
|
||||
> 打印 内容=`back`
|
||||
|
||||
*h = > 编码.十六进制编码 内容="hi"*
|
||||
> 打印 内容=`h`
|
||||
|
||||
*hb = > 编码.十六进制解码 内容=`h`*
|
||||
> 打印 内容=`hb`
|
||||
Reference in new issue
Block a user