docs: 改写字符串域注释并补正则工具文档

string/common.rs:文本通道节头改写为三载荷形态与两条匹配入口的范围单位约定,删依赖 crate 名与历史表述;to_value 文档由「物化/臂」改为「构造/变体」。
string/regex.rs:为 is_regexp_obj、builder_wrapper、make_match_done_result 补函数文档;string_raw 体内注释删除规范章节号,仅保留语义。
This commit is contained in:
2026-09-17 12:50:15 +00:00
parent aaad3786b7
commit 4b080b6f63
2 changed files with 13 additions and 6 deletions
+7 -5
View File
@@ -18,10 +18,12 @@ pub(crate) use try_string;
// ── 文本通道 ─────────────────────────────────────────────────────────────
//
// 字符串值的载荷分形态:Flat(良形 UTF-8)、FlatU16(单元载荷,可含孤立
// surrogate)、Cons(rope)。正则家族按文本通道分臂——Str 臂走良形文本
// (字节口径,与旧代码路径一致),Units 臂走单元序列(regress utf16 接口,
// 匹配范围即码元);其余方法统一按单元序列处理(规格口径)。
// 字符串值有三种载荷形态:Flat(良形 UTF-8 字节串)、FlatU16(UTF-16 单元
// 数组,可含孤立 surrogate)、Cons(分段拼接的 rope)。正则匹配按载荷形态
// 分两条入口:Str 入口以字节串调用匹配器,返回的匹配范围以字节为单位;
// Units 入口以单元数组调用匹配器,匹配范围以 UTF-16 码元为单位。两条入口
// 的范围单位不可互换,匹配片段端点必须换算到与所在入口相同的单位;
// 正则之外的 String 方法统一取单元序列处理。
/// 正则家族的匹配文本通道。
pub(crate) enum MatchText<'a> {
@@ -142,7 +144,7 @@ impl OwnedText {
}
}
/// 物化为字符串值(Str 臂文本 / Units 臂单元,载荷形态各自最小)。
/// 构造字符串值:Str 变体按字节串、Units 变体按单元数组,载荷形态各自最小。
pub(crate) fn to_value<H: VmHost>(&self, vm: &mut H) -> JsValue {
match self {
OwnedText::Str(s) => vm.new_string(s),
+6 -1
View File
@@ -238,6 +238,8 @@ fn string_replace_fn<H: VmHost>(
NativeResult::Ok(vm.new_string_units_owned(out))
}
/// 判断值是否为 RegExp 对象:非对象、空指针、原型非对象均返回 false,
/// 原型指针与 `%RegExpPrototype%` 恒等比较。
fn is_regexp_obj<H: VmHost>(val: JsValue, vm: &H) -> bool {
if !val.is_object() {
return false;
@@ -799,6 +801,8 @@ pub fn string_match_all<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
builder_wrapper(vm, input_val, re_obj)
}
/// 构造 matchAll 包装对象:原型挂 `%RegExpStringIteratorPrototype%`,
/// own 属性为 input/index(0)/re 三槽,next 由原型提供。
fn builder_wrapper<H: VmHost>(vm: &mut H, input_val: JsValue, re_obj: JsValue) -> NativeResult {
// matchAll 迭代器挂 %RegExpStringIteratorPrototype%(链到 %IteratorPrototype%),
// next 由原型提供(不挂实例 own)。
@@ -945,6 +949,7 @@ pub fn string_match_all_next<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult
make_match_done_result(vm, value)
}
/// 构造迭代器结果对象 `{value, done}`(done 仅在 value 为 undefined 时为 true)。
fn make_match_done_result<H: VmHost>(vm: &mut H, value: JsValue) -> NativeResult {
let done = value.is_undefined();
let object_proto = vm.session().builtin_world().object_proto.as_ptr() as *mut JsObject;
@@ -1061,7 +1066,7 @@ pub fn string_raw<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
result.extend(raw_units);
// 段间(i + 1 < length)才追加 substitutions[i];substitutions 缺失时
// 追加空串(spec 24.b.i),末段后不再追加任何内容。
// 追加空串,末段后不再追加任何内容。
if i + 1 < raw_len {
let sub_idx = i + 2;
if sub_idx < args.len() {