libcss
Loading...
Searching...
No Matches
Macros | Functions
utils.c File Reference
#include <assert.h>
#include <string.h>
#include <strings.h>
#include "stylesheet.h"
#include "bytecode/bytecode.h"
#include "bytecode/opcodes.h"
#include "parse/properties/properties.h"
#include "parse/properties/utils.h"
#include "utils/parserutilserror.h"

Macros

#define MAP_ENTRIES   52
 
#define ORGB(R, G, B)
 

Functions

css_error css__parse_list_style_type_value (css_language *c, const css_token *ident, uint16_t *value)
 
css_error css__parse_border_side (css_language *c, const parserutils_vector *vector, int32_t *ctx, css_style *result, enum border_side_e side)
 
css_error css__parse_colour_specifier (css_language *c, const parserutils_vector *vector, int32_t *ctx, uint16_t *value, uint32_t *result)
 
css_error css__parse_named_colour (css_language *c, lwc_string *data, uint32_t *result)
 
css_error css__parse_hash_colour (lwc_string *data, uint32_t *result)
 
css_error css__parse_unit_specifier (css_language *c, const parserutils_vector *vector, int32_t *ctx, uint32_t default_unit, css_fixed *length, uint32_t *unit)
 
css_error css__parse_unit_keyword (const char *ptr, size_t len, uint32_t *unit)
 
css_error css__ident_list_or_string_to_string (css_language *c, const parserutils_vector *vector, int32_t *ctx, bool(*reserved)(css_language *c, const css_token *ident), lwc_string **result)
 
css_error css__ident_list_to_string (css_language *c, const parserutils_vector *vector, int32_t *ctx, bool(*reserved)(css_language *c, const css_token *ident), lwc_string **result)
 
css_error css__comma_list_to_style (css_language *c, const parserutils_vector *vector, int32_t *ctx, bool(*reserved)(css_language *c, const css_token *ident), css_code_t(*get_value)(css_language *c, const css_token *token, bool first), css_style *result)
 
css_error css__parse_calc (css_language *c, const parserutils_vector *vector, int *ctx, css_style *result, css_code_t OPV, uint32_t unit)
 

Macro Definition Documentation

◆ MAP_ENTRIES

#define MAP_ENTRIES   52

◆ ORGB

#define ORGB (   R,
  G,
 
)
Value:
*r = FMUL((R), F_255); \
*g = FMUL((G), F_255); \
*b = FMUL((B), F_255)
#define FMUL(a, b)
Definition fpmath.h:117
#define F_255
Definition fpmath.h:154

Function Documentation

◆ css__comma_list_to_style()

css_error css__comma_list_to_style ( css_language c,
const parserutils_vector *  vector,
int32_t *  ctx,
bool(*)(css_language *c, const css_token *ident)  reserved,
css_code_t(*)(css_language *c, const css_token *token, bool first)  get_value,
css_style result 
)

Parse a comma separated list, converting to bytecode

Parameters
cParsing context
vectorVector of tokens to process
ctxPointer to vector iteration context
reservedCallback to determine if an identifier is reserved
get_valueCallback to retrieve bytecode value for a token
stylePointer to output style
Returns
CSS_OK on success, CSS_INVALID if the input is invalid

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.

◆ css__ident_list_or_string_to_string()

css_error css__ident_list_or_string_to_string ( css_language c,
const parserutils_vector *  vector,
int32_t *  ctx,
bool(*)(css_language *c, const css_token *ident)  reserved,
lwc_string **  result 
)

Create a string from a list of IDENT/S tokens if the next token is IDENT or references the next token's string if it is a STRING

Parameters
cParsing context
vectorVector containing tokens
ctxVector iteration context
reservedCallback to determine if an identifier is reserved
resultPointer to location to receive resulting string
Returns
CSS_OK on success, appropriate error otherwise.

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.

The resulting string's reference is passed to the caller

◆ css__ident_list_to_string()

css_error css__ident_list_to_string ( css_language c,
const parserutils_vector *  vector,
int32_t *  ctx,
bool(*)(css_language *c, const css_token *ident)  reserved,
lwc_string **  result 
)

Create a string from a list of IDENT/S tokens

Parameters
cParsing context
vectorVector containing tokens
ctxVector iteration context
reservedCallback to determine if an identifier is reserved
resultPointer to location to receive resulting string
Returns
CSS_OK on success, appropriate error otherwise.

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.

The resulting string's reference is passed to the caller

◆ css__parse_border_side()

css_error css__parse_border_side ( css_language c,
const parserutils_vector *  vector,
int32_t *  ctx,
css_style result,
enum border_side_e  side 
)

Parse border-{top,right,bottom,left} shorthand

Parameters
cParsing context
vectorVector of tokens to process
ctxPointer to vector iteration context
sideThe side we're parsing for
resultPointer to location to receive resulting style
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion, CSS_INVALID if the input is not valid

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.

◆ css__parse_calc()

css_error css__parse_calc ( css_language c,
const parserutils_vector *  vector,
int *  ctx,
css_style result,
css_code_t  OPV,
uint32_t  unit 
)

Parse a CSS calc() invocation

Calc can generate a number of kinds of units, so we have to tell the parser the kind of unit we're aiming for (e.g. UNIT_PX, UNIT_ANGLE, etc.)

Parameters
[in]cParsing context
[in]vectorVector of tokens to process
[in]ctxPointer to vector iteration context
[in]resultPointer to location to receive resulting style
[in]OPVThe CSS property we are calculating for
[in]unitThe kind of unit which we want to come out of this calc()
Returns
CSS_OK on success, CSS_NOMEM on memory exhaustion, CSS_INVALID if the input is not valid

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.

◆ css__parse_colour_specifier()

css_error css__parse_colour_specifier ( css_language c,
const parserutils_vector *  vector,
int32_t *  ctx,
uint16_t *  value,
uint32_t *  result 
)

Parse a colour specifier

Parameters
cParsing context
vectorVector of tokens to process
ctxPointer to vector iteration context
valuePointer to location to receive value
resultPointer to location to receive result (AARRGGBB)
Returns
CSS_OK on success, CSS_INVALID if the input is invalid

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.

◆ css__parse_hash_colour()

css_error css__parse_hash_colour ( lwc_string *  data,
uint32_t *  result 
)

Parse a hash colour (#rgb, #rgba, #rrggbb or #rrggbbaa)

Parameters
dataPointer to colour string
resultPointer to location to receive result (AARRGGBB)
Returns
CSS_OK on success, CSS_INVALID if the input is invalid

◆ css__parse_list_style_type_value()

css_error css__parse_list_style_type_value ( css_language c,
const css_token ident,
uint16_t *  value 
)

Parse list-style-type value

Parameters
cParsing context
identIdentifier to consider
valuePointer to location to receive value
Returns
CSS_OK on success, CSS_INVALID if the input is not valid

◆ css__parse_named_colour()

css_error css__parse_named_colour ( css_language c,
lwc_string *  data,
uint32_t *  result 
)

Parse a named colour

Parameters
cParsing context
dataColour name string
resultPointer to location to receive result
Returns
CSS_OK on success, CSS_INVALID if the colour name is unknown

Legacy system colour mapping

◆ css__parse_unit_keyword()

css_error css__parse_unit_keyword ( const char *  ptr,
size_t  len,
uint32_t *  unit 
)

Parse a unit keyword

Parameters
ptrPointer to keyword string
lenLength, in bytes, of string
unitPointer to location to receive computed unit
Returns
CSS_OK on success, CSS_INVALID on encountering an unknown keyword

◆ css__parse_unit_specifier()

css_error css__parse_unit_specifier ( css_language c,
const parserutils_vector *  vector,
int32_t *  ctx,
uint32_t  default_unit,
css_fixed length,
uint32_t *  unit 
)

Parse a unit specifier

Parameters
cParsing context
vectorVector of tokens to process
ctxPointer to current vector iteration context
default_unitThe default unit to use if none specified
lengthPointer to location to receive length
unitPointer to location to receive unit
Returns
CSS_OK on success, CSS_INVALID if the tokens do not form a valid unit

Post condition: *ctx is updated with the next token to process If the input is invalid, then *ctx remains unchanged.