Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
CSS

A growing implementation of CSS-related utilities. More...

Functions

SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_hex_color (const std::string_view value) noexcept -> bool
SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_color_keyword (const std::string_view value) noexcept -> bool
SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_rgb_function (const std::string_view value) noexcept -> bool
SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_color (const std::string_view value) noexcept -> bool

Detailed Description

A growing implementation of CSS-related utilities.

This functionality is included as follows:

#include <sourcemeta/core/css.h>

Function Documentation

◆ is_css2_color()

SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_color ( const std::string_view value) -> bool
noexcept

Check whether the given string is a valid CSS 2.1 <color> value per §4.3.6. The accept set is the union of:

For example:

#include <sourcemeta/core/css.h>
#include <cassert>
assert(sourcemeta::core::is_css2_color("rgb(255, 0, 0)"));
assert(!sourcemeta::core::is_css2_color("#00332520"));
SOURCEMETA_CORE_CSS_EXPORT auto is_css2_color(const std::string_view value) noexcept -> bool

◆ is_css2_color_keyword()

SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_color_keyword ( const std::string_view value) -> bool
noexcept

Check whether the given string is one of the 17 CSS 2.1 color keywords defined in §4.3.6:

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy,
olive, orange, purple, red, silver, teal, white, yellow

Matching is case-insensitive. The transparent keyword and the deprecated system colors (ButtonFace, ActiveBorder, etc.) are out of scope, as are the extended X11 names introduced by CSS Color Module Level 3. For example:

#include <sourcemeta/core/css.h>
#include <cassert>
SOURCEMETA_CORE_CSS_EXPORT auto is_css2_color_keyword(const std::string_view value) noexcept -> bool

◆ is_css2_hex_color()

SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_hex_color ( const std::string_view value) -> bool
noexcept

Check whether the given string is a valid CSS 2.1 hex color per §4.3.6. Accepts only the two hex notations defined by CSS 2.1:

"#" 3HEXDIG ; e.g. "#C89"
"#" 6HEXDIG ; e.g. "#CC8899"

Hex digits are case-insensitive. The 4-digit and 8-digit alpha forms from CSS Color Module Level 4 are not accepted. For example:

#include <sourcemeta/core/css.h>
#include <cassert>
SOURCEMETA_CORE_CSS_EXPORT auto is_css2_hex_color(const std::string_view value) noexcept -> bool

◆ is_css2_rgb_function()

SOURCEMETA_CORE_CSS_EXPORT auto sourcemeta::core::is_css2_rgb_function ( const std::string_view value) -> bool
noexcept

Check whether the given string is a valid CSS 2.1 functional RGB color per §4.3.6. Accepts both the integer and percentage forms:

rgb( <integer> , <integer> , <integer> )
rgb( <percentage> , <percentage> , <percentage> )

All three values must be the same type. The function name rgb is case-insensitive, and CSS whitespace (space, tab, CR, LF, FF) is permitted between tokens. Out-of-range values are accepted (CSS 2.1 clamps at use time). The 4-argument rgba(...) form from CSS Color Module Level 3 is not accepted. For example:

#include <sourcemeta/core/css.h>
#include <cassert>
assert(sourcemeta::core::is_css2_rgb_function("rgb(255, 0, 128)"));
assert(sourcemeta::core::is_css2_rgb_function("rgb(100%, 0%, 50%)"));
assert(sourcemeta::core::is_css2_rgb_function("rgb(300, -5, 128)"));
assert(!sourcemeta::core::is_css2_rgb_function("rgb(100%, 0, 50%)"));
assert(!sourcemeta::core::is_css2_rgb_function("rgba(0, 0, 0, 1)"));
SOURCEMETA_CORE_CSS_EXPORT auto is_css2_rgb_function(const std::string_view value) noexcept -> bool