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
50
51
52
53
54
55
use ColorConversionError;
/// Validates whether a given string is a valid 3- or 6-digit hexadecimal color.
///
/// Accepts strings with or without a leading `#`, and checks that the remaining
/// characters are valid ASCII hexadecimal digits (`0-9`, `a-f`, `A-F`), with a length of
/// exactly 3 or 6.
///
/// # Arguments
///
/// * `input` - A string slice that may represent a hex color value (e.g. `"#FFA07A"` or `"0F0"`).
///
/// # Returns
///
/// * `Ok(())` if the input is a valid 3- or 6-digit hex string.
/// * `Err(ColorConversionError::InvalidHex)` if the input is invalid.
///
/// # Examples
///
/// ```
/// assert!(terminal_style::color::validate_hex("#ffcc00").is_ok());
/// assert!(terminal_style::color::validate_hex("abc").is_ok());
/// assert!(terminal_style::color::validate_hex("xyz").is_err());
/// ```
/// Validates that an ANSI color value is within the 0–255 range.
///
/// # Arguments
///
/// * `value` - An integer value to validate.
///
/// # Returns
///
/// * `Ok(())` if the value is between 0 and 255 inclusive.
/// * `Err(ColorConversionError::InvalidAnsiValue)` if the value is out of range.