Files
marqdo-cli/stdlib/text.mq.md
T
cflmy 1377af1601 feat(stdlib): ship a verified bundled stdlib with std: imports
- Move the Compat-A print prototype into stdlib/ as the official offline
  bundle with stdlib.json (version 0.1.0 + sha256 content digest).
- Add std:<relative> import resolution in the loader with bundle path
  confinement, extension inference and fail-closed digest verification.
- Record the verified version/digest/instance_id in Analysis v2
  project.stdlib; stdlib modules get a std:name@version#digest instance id.
- Add CLI tests: std:io execution, digest-tamper rejection, missing manifest,
  Analysis identity, no foreign/plugin calls, and frozen binary hash equality.
- Update ADR-0028, specs, status, changelog and evidence.

Gate: fmt, clippy -D warnings, 415 tests passed.
2026-11-20 21:43:14 +08:00

1.1 KiB

utf8编码

(文本, 内存, 基址)

把 Unicode 标量序列按 UTF-8 写入 Memory,返回字节长度。

点 = text.codepoints(文本)

下标 = 0

偏移 = 0

  • 下标 < 长度(点)

    码点 = 点[下标]

    1. 码点 < 128

      内存[基址 + 偏移] = 码点

      偏移 = 偏移 + 1

    2. 码点 < 2048

      内存[基址 + 偏移] = 192 + 码点 // 64

      内存[基址 + 偏移 + 1] = 128 + 码点 % 64

      偏移 = 偏移 + 2

    3. 码点 < 65536

      内存[基址 + 偏移] = 224 + 码点 // 4096

      内存[基址 + 偏移 + 1] = 128 + 码点 // 64 % 64

      内存[基址 + 偏移 + 2] = 128 + 码点 % 64

      偏移 = 偏移 + 3

    4. true

      内存[基址 + 偏移] = 240 + 码点 // 262144

      内存[基址 + 偏移 + 1] = 128 + 码点 // 4096 % 64

      内存[基址 + 偏移 + 2] = 128 + 码点 // 64 % 64

      内存[基址 + 偏移 + 3] = 128 + 码点 % 64

      偏移 = 偏移 + 4

    下标 = 下标 + 1

偏移