Files
FFF_vtt_frozen/server/text.nim
T
SirStone 67762c1309 server: the property buckets, the registry and the status set (#22)
Migration step 6 ("token details") adds the three prop buckets to `entity`
and creates `entity_status`, the `(status, source)` set of 5.5. A token's
status rows are rewritten with its row, so a status change and the `token`
frame that reports it commit together.

server/props.nim owns the buckets, their caps (64 keys per bucket, a key of
1..64 code points, a value of at most 8 KB of serialized JSON) and the
property-schema registry: empty at start with a permissive fallback, because
DESIGN 8 says v1 never interprets props; a key the rules module registers is
enforced (kind and bucket). server/text.nim is the one copy of the 6.5 text
rule, shared by names and prop keys.

tokens.nim gains `props` and `statuses` on the record, the sorted-unique
entry helpers, `isLocked`, `parseRadius`/`parseStatusKind`/`parseStatusSource`,
the prop and status columns in insert/replace, and `loadStatuses` joined on
the scene. Every helper builds a fresh sequence: a copied record shares its
seq buffer, so an in-place edit would reach the authoritative list before
the transaction commits (4.2 step 6).
2026-11-15 11:02:23 +01:00

14 lines
687 B
Nim

## The one copy of the text rules of DESIGN 6.5: a stored text field is trimmed, 1..maxLen code
## points and free of control characters. Shared by the token/character names (tokens.nim) and the
## property keys (props.nim), so the two cannot drift apart.
import std/unicode
proc hasControlChar*(s: string): bool =
for r in s.runes:
if r.int < 0x20 or r.int == 0x7f: return true
proc validText*(s: string, maxLen: int): bool =
## Trimmed, 1..maxLen code points, no control characters. NFC normalisation and the per-player
## uniqueness rule arrived with the name machinery of slice 8 (#23).
s.len > 0 and s == s.strip and s.runeLen in 1 .. maxLen and not hasControlChar(s)