def is_safe.plain

yaml-for-bend@0.1.1.0 · emit.bend:115

import yaml-for-bend@0.1.1.0/emit.bend as Emit
import Base
import yaml-for-bend@0.1.1.0/core.bend as C

115# Whether +s+ reads back as itself when written plain: it isn't empty, has
116# no blank at either end, starts with no indicator, holds no ": ", " #" or
117# character that needs escaping, and the Core schema reads it as a string.
118def is_safe.plain(+s: String) -> Bool:
119  Bool.and(Bool.and(Bool.not(String.is_empty(s)), all.plain(s)),
120    Bool.and(Bool.and(Bool.not(is_in(first.char(s), " -?:,[]{}#&*!|>'\"%@`")), Bool.not(Char.is_eq(last.char(s), ' '))),
121      Bool.and(Bool.and(Bool.not(String.contains(s, ": ")), Bool.not(String.contains(s, " #"))),
122        Bool.and(Bool.not(String.ends_with(s, ":")), is_str(C.plain(s))))))

Uses (15)

Used by (1)