This repository was archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer_algorithms.hpp
More file actions
79 lines (62 loc) · 2.55 KB
/
Copy pathtokenizer_algorithms.hpp
File metadata and controls
79 lines (62 loc) · 2.55 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
/**
* Copyright (C) 2020 Tristan. All Rights Reserved.
* This file is licensed under the BSD 2-Clause license.
* See the COPYING file for licensing information.
*/
#include "data/text/unicode.hpp"
#include "parser/css/tokenizer_stream.hpp"
namespace CSS {
[[nodiscard]] inline constexpr bool
IsWhitespace(Unicode::CodePoint character) noexcept {
return character == Unicode::LINE_FEED || character == Unicode::CHARACTER_TABULATION || character == Unicode::SPACE;
}
[[nodiscard]] inline constexpr bool
IsHexCharacter(Unicode::CodePoint character) noexcept {
return (character >= Unicode::LATIN_CAPITAL_LETTER_A && character <= Unicode::LATIN_CAPITAL_LETTER_F)
|| (character >= Unicode::LATIN_SMALL_LETTER_A && character <= Unicode::LATIN_SMALL_LETTER_F)
|| (character >= Unicode::DIGIT_ZERO && character <= Unicode::DIGIT_NINE);
}
[[nodiscard]] inline constexpr bool
IsNonASCIICodePoint(Unicode::CodePoint codePoint) noexcept {
return codePoint >= Unicode::PADDING_CHARACTER;
}
[[nodiscard]] inline constexpr bool
IsNameStartCodePoint(Unicode::CodePoint codePoint) noexcept {
return Unicode::IsASCIIAlpha(codePoint) || IsNonASCIICodePoint(codePoint) || codePoint == Unicode::LOW_LINE;
}
[[nodiscard]] inline constexpr bool
IsNameCodePoint(Unicode::CodePoint codePoint) noexcept {
return IsNameStartCodePoint(codePoint) || Unicode::IsDigit(codePoint) || codePoint == Unicode::HYPHEN_MINUS;
}
[[nodiscard]] inline constexpr bool
IsNonPrintableCodePoint(Unicode::CodePoint character) noexcept {
return character <= Unicode::BACKSPACE || character == Unicode::LINE_TABULATION || (character >= Unicode::SHIFT_OUT && character <= Unicode::INFORMATION_SEPARATOR_ONE) || character == Unicode::DELETE;
}
[[nodiscard]] inline bool
IsValidEscape(const CSS::TokenizerStream &stream, std::size_t offset = 0) noexcept {
Unicode::CodePoint next, next2;
return stream.Peek(&next, offset) && stream.Peek(&next2, offset + 1) && next == Unicode::REVERSE_SOLIDUS
&& next2 != Unicode::LINE_FEED;
}
[[nodiscard]] inline bool
WillStartIdentifier(const CSS::TokenizerStream &stream) noexcept {
Unicode::CodePoint first, second;
if (!stream.Peek(&first)) {
return false;
}
if (IsNameStartCodePoint(first)) {
return true;
}
if (!stream.Peek(&second, 1)) {
return false;
}
if (first == Unicode::REVERSE_SOLIDUS && second != Unicode::LINE_FEED) {
return true;
}
if (first == Unicode::HYPHEN_MINUS && (second == Unicode::HYPHEN_MINUS || IsValidEscape(stream, 1))) {
return true;
}
return false;
}
} // namespace CSS