Module colorizer.parser.rgba_hex
This module provides a parser for identifying and converting `#RRGGBBAA` hexadecimal color values to RGB hexadecimal format.
It is commonly used in Android apps for colors with an alpha (transparency) component. The function reads the color, applies the alpha to each RGB channel, and returns the resulting RGB hex string.
Functions
parser (line, i, opts) | Parses `#RRGGBBAA` hexadecimal colors and converts them to RGB hex format. |
Functions
- parser (line, i, opts)
-
Parses `#RRGGBBAA` hexadecimal colors and converts them to RGB hex format.
This function matches `#RRGGBBAA` format colors within a line, handling alpha transparency if specified.
It checks the length of the color string to match expected valid lengths (e.g., 4, 7, 9 characters).
Parameters:
- line string The line of text to parse for the hex color
- i number The starting index within the line where parsing should begin
- opts table Options containing: - `minlen` (number): Minimum length of the color string - `maxlen` (number): Maximum length of the color string - `valid_lengths` (table): Set of valid lengths (e.g., `{4, 7, 9}`)
Returns:
- number|nil The end index of the parsed hex color within the line, or `nil` if parsing failed
- string|nil The RGB hexadecimal color (e.g., "ff0000" for red), or `nil` if parsing failed