xpile 0.1.615

Polyglot transpile workbench (Python/C/C++/Rust/Ruchy/Lean ↔ Rust/Ruchy/PTX/WGSL/SPIR-V) with provable contracts at every layer.
1
2
3
4
5
6
7
8
9
10
11
12
# PMAT-674: `len(s.encode())` is the UTF-8 BYTE length of a str (NOT the
# code-point count `len(s)` gives) — equals Rust `String::len()`.
def byte_len(s: str) -> int:
    return len(s.encode())


def byte_len_utf8(s: str) -> int:
    return len(s.encode("utf-8"))


def char_len(s: str) -> int:
    return len(s)