← back to roto on ba3a.dev

SafeName

object SafeName

The rule for every name that ends up in a file name — project ids, profile ids, facings, actions: it starts with a letter or digit and holds only letters, digits, _ and -. Such a name is safe as, or inside, a path segment on every desktop file system.

Functions

Link copied to clipboard
fun isValid(name: String): Boolean

Whether name follows the rule.

Link copied to clipboard
fun validate(name: String, what: String)

Throws unless name follows the rule; what names it in the message.

Link copied to clipboard
fun validateList(names: List<String>, what: String)

Throws unless names is non-empty, each follows the rule, and no two differ only in case. Templates may lower- or upper-case a name, and Windows and macOS file systems ignore case, so names differing only in case would collide on disk.