1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This file is part of helpers4.
// Copyright (C) 2025 baxyz
// SPDX-License-Identifier: LGPL-3.0-or-later
/// Checks whether `s` has the shape of an ASCII URL slug: non-empty, made only of lowercase
/// ASCII letters, digits and hyphens, with no leading, trailing or doubled hyphen.
///
/// This is ASCII-only by design, even though [`slugify`](crate::string::slugify) keeps Unicode
/// letters (`slugify("café")` is `"café"`, which `is_slug` rejects): a slug meant to go
/// unescaped in a URL path is conventionally ASCII. For ASCII input, `is_slug(&slugify(s))` is
/// `true` whenever `slugify(s)` is not empty.
///
/// # Arguments
///
/// - `s` - The text to check.
///
/// # Returns
///
/// `true` when `s` already has the shape of a slug.
///
/// # Examples
///
/// ```
/// use helpers4::validate::is_slug;
///
/// assert!(is_slug("hello-world"));
/// assert!(is_slug("v2"));
/// assert!(!is_slug("Hello-World"));
/// assert!(!is_slug("-leading"));
/// assert!(!is_slug("double--hyphen"));
/// assert!(!is_slug(""));
/// ```