chromium/third_party/blink/renderer/core/css/parser/css_parser_fast_paths.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/core/css/parser/css_parser_fast_paths.h"

#ifdef __SSE2__
#include <immintrin.h>
#elif defined(__ARM_NEON__)
#include <arm_neon.h>
#endif

#include "build/build_config.h"
#include "third_party/blink/public/public_buildflags.h"
#include "third_party/blink/renderer/core/css/css_color.h"
#include "third_party/blink/renderer/core/css/css_function_value.h"
#include "third_party/blink/renderer/core/css/css_identifier_value.h"
#include "third_party/blink/renderer/core/css/css_inherited_value.h"
#include "third_party/blink/renderer/core/css/css_initial_value.h"
#include "third_party/blink/renderer/core/css/css_numeric_literal_value.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/css_revert_layer_value.h"
#include "third_party/blink/renderer/core/css/css_revert_value.h"
#include "third_party/blink/renderer/core/css/css_unset_value.h"
#include "third_party/blink/renderer/core/css/css_value.h"
#include "third_party/blink/renderer/core/css/css_value_clamping_utils.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_idioms.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser.h"
#include "third_party/blink/renderer/core/css/properties/css_bitset.h"
#include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
#include "third_party/blink/renderer/core/css/style_color.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/style_property_shorthand.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/character_visitor.h"
#include "third_party/blink/renderer/platform/wtf/text/string_to_number.h"

namespace blink {

static unsigned ParsePositiveDouble(const LChar* string,
                                    const LChar* end,
                                    double& value);

static bool ParseDoubleWithPrefix(const LChar* string,
                                  const LChar* end,
                                  double& value);

static inline bool IsSimpleLengthPropertyID(CSSPropertyID property_id,
                                            bool& accepts_negative_numbers) {}

ALWAYS_INLINE static bool ParseSimpleLength(const LChar* characters,
                                            unsigned length,
                                            CSSPrimitiveValue::UnitType& unit,
                                            double& number) {}

static CSSValue* ParseSimpleLengthValue(CSSPropertyID property_id,
                                        StringView string,
                                        CSSParserMode css_parser_mode) {}

// Returns the length of the angle, or 0 if the parse failed.
ALWAYS_INLINE static unsigned ParseSimpleAngle(
    const LChar* characters,
    unsigned length,
    CSSPrimitiveValue::UnitType& unit,
    double& number) {}

static inline bool IsColorPropertyID(CSSPropertyID property_id) {}

// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk
static inline bool ColorPropertyAllowsQuirkyColor(CSSPropertyID property_id) {}

// Returns the number of initial characters which form a valid double.
static unsigned FindLengthOfValidDouble(const LChar* string, const LChar* end) {}

// If also_accept_whitespace is true: Checks whether string[pos] is the given
// character, _or_ an HTML space.
// Otherwise: Checks whether string[pos] is the given character.
// Returns false if pos is past the end of the string.
static bool ContainsCharAtPos(const LChar* string,
                              const LChar* end,
                              int pos,
                              char ch,
                              bool also_accept_whitespace) {}

// Like ParsePositiveDouble(), but also accepts initial whitespace and negative
// values. This is similar to CharactersToDouble(), but does not support
// trailing periods (e.g. “100.”), cf.
//
//   https://drafts.csswg.org/css-syntax/#consume-number
//   https://drafts.csswg.org/css-syntax/#number-token-diagram
//
// It also does not support exponential notation (e.g. “100e3”), which means
// that such cases go through the slow path.
static bool ParseDoubleWithPrefix(const LChar* string,
                                  const LChar* end,
                                  double& value) {}

// Returns the number of characters consumed for parsing a valid double,
// or 0 if the string did not start with a valid double.
//
// NOTE: Digits after the seventh decimal are ignored, potentially leading
// to accuracy issues. (All digits _before_ the decimal points are used.)
ALWAYS_INLINE static unsigned ParsePositiveDouble(const LChar* string,
                                                  const LChar* end,
                                                  double& value) {}

// Parse a float and clamp it upwards to max_value. Optimized for having
// no decimal part. Returns true if the parse was successful (though it
// may not consume the entire string; you'll need to check string != end
// yourself if that is the intention).
ALWAYS_INLINE static bool ParseFloatWithMaxValue(const LChar*& string,
                                                 const LChar* end,
                                                 int max_value,
                                                 double& value,
                                                 bool& negative) {}

namespace {

enum TerminatorStatus {};

}  // namespace

static bool SkipToTerminator(const LChar*& string,
                             const LChar* end,
                             const char terminator,
                             TerminatorStatus& terminator_status) {}

static bool ParseColorNumberOrPercentage(const LChar*& string,
                                         const LChar* end,
                                         const char terminator,
                                         TerminatorStatus& terminator_status,
                                         CSSPrimitiveValue::UnitType& expect,
                                         int& value) {}

// Parses a percentage (including the % sign), clamps it and converts it to
// 0.0..1.0.
ALWAYS_INLINE static bool ParsePercentage(const LChar*& string,
                                          const LChar* end,
                                          const char terminator,
                                          TerminatorStatus& terminator_status,
                                          double& value) {}

static inline bool IsTenthAlpha(const LChar* string, const wtf_size_t length) {}

ALWAYS_INLINE static bool ParseAlphaValue(const LChar*& string,
                                          const LChar* end,
                                          const char terminator,
                                          int& value) {}

// Fast for LChar, reasonable for UChar.
template <int N>
static inline bool MatchesLiteral(const LChar* a, const char (&b)[N]) {}

template <int N>
static inline bool MatchesLiteral(const UChar* a, const char (&b)[N]) {}

// Right-hand side must already be lowercase.
static inline bool MatchesCaseInsensitiveLiteral4(const LChar* a,
                                                  const char (&b)[5]) {}

static inline bool MatchesCaseInsensitiveLiteral2(const LChar* a,
                                                  const char (&b)[3]) {}

static inline bool MightBeRGBOrRGBA(const LChar* characters, unsigned length) {}

static inline bool MightBeHSLOrHSLA(const LChar* characters, unsigned length) {}

static bool FastParseColorInternal(Color& color,
                                   const LChar* characters,
                                   unsigned length,
                                   bool quirks_mode) {}

// If the string identifies a color keyword, `out_color_keyword` is set and
// `kKeyword` is returned. If the string identifies a color, then `out_color`
// is set and `kColor` is returned.
static ParseColorResult ParseColor(CSSPropertyID property_id,
                                   StringView string,
                                   CSSParserMode parser_mode,
                                   Color& out_color,
                                   CSSValueID& out_color_keyword) {}

ParseColorResult CSSParserFastPaths::ParseColor(const String& string,
                                                CSSParserMode parser_mode,
                                                Color& color) {}

bool CSSParserFastPaths::IsValidKeywordPropertyAndValue(
    CSSPropertyID property_id,
    CSSValueID value_id,
    CSSParserMode parser_mode) {}

// NOTE: This list must match exactly those properties handled by
// IsValidKeywordPropertyAndValue().
CSSBitset CSSParserFastPaths::handled_by_keyword_fast_paths_properties_{};

bool CSSParserFastPaths::IsValidSystemFont(CSSValueID value_id) {}

static inline CSSValue* ParseCSSWideKeywordValue(const LChar* ptr,
                                                 unsigned length) {}

static CSSValue* ParseKeywordValue(CSSPropertyID property_id,
                                   StringView string,
                                   const CSSParserContext* context) {}

static bool ParseTransformTranslateArguments(
    const LChar*& pos,
    const LChar* end,
    unsigned expected_count,
    CSSFunctionValue* transform_value) {}

static bool ParseTransformRotateArgument(const LChar*& pos,
                                         const LChar* end,
                                         CSSFunctionValue* transform_value) {}

static bool ParseTransformNumberArguments(const LChar*& pos,
                                          const LChar* end,
                                          unsigned expected_count,
                                          CSSFunctionValue* transform_value) {}

static const int kShortestValidTransformStringLength =;

static CSSFunctionValue* ParseSimpleTransformValue(const LChar*& pos,
                                                   const LChar* end) {}

static bool TransformCanLikelyUseFastPath(const LChar* chars, unsigned length) {}

static CSSValue* ParseSimpleTransform(CSSPropertyID property_id,
                                      StringView string) {}

CSSValue* CSSParserFastPaths::MaybeParseValue(CSSPropertyID property_id,
                                              StringView string,
                                              const CSSParserContext* context) {}

}  // namespace blink