def is_name

ezx@1.11.0.0 · src/pub/plan.bend:45

import ezx@1.11.0.0/src/pub/plan.bend as Plan
import Base
import ezx@1.11.0.0/src/git/git.bend as G

45# whether a line is a `0x` package name and nothing else. Anchored at both
46# ends: the prefix, the exact length, and every character after the prefix one
47# a lowercase hex digest may hold. `git/git.bend` already walks a hex string
48# for `is_rev`, and its walk stops at the first character that is not hex.
49#
50# The lines bend prints around its answer fail this, and `pub/LAWS.bend` says
51# so for the two that hold the name, rather than leaving it to a reading of
52# bend's source: `publishing N files, ... as 0x... (mining its proof of work)`
53# and `import 0x.../entry.bend as Name` each start with something that is not
54# `0x`. The terms notice and the license line bend 2.0.27 prints first
55# (`Publishing to BendHub: ...`, `License: ...`) start with a word too.
56def is_name(+word: String) -> Bool:
57  Bool.and(String.starts_with(word, "0x"),
58    Bool.and(Nat.is_eq(String.length(word), name.length()),
59      G.hex.all(String.to_list(String.drop(word, 2n)))))

Uses (10)

Used by (2)