mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
expr: Use StringView literals more (instead of raw C strings)
This commit is contained in:
parent
c5c0c7c620
commit
a32cbf1df3
1 changed files with 20 additions and 20 deletions
|
@ -208,15 +208,15 @@ public:
|
||||||
|
|
||||||
static ComparisonOperation op_from(StringView sv)
|
static ComparisonOperation op_from(StringView sv)
|
||||||
{
|
{
|
||||||
if (sv == "<")
|
if (sv == "<"sv)
|
||||||
return ComparisonOperation::Less;
|
return ComparisonOperation::Less;
|
||||||
if (sv == "<=")
|
if (sv == "<="sv)
|
||||||
return ComparisonOperation::LessEq;
|
return ComparisonOperation::LessEq;
|
||||||
if (sv == "=")
|
if (sv == "="sv)
|
||||||
return ComparisonOperation::Eq;
|
return ComparisonOperation::Eq;
|
||||||
if (sv == "!=")
|
if (sv == "!="sv)
|
||||||
return ComparisonOperation::Neq;
|
return ComparisonOperation::Neq;
|
||||||
if (sv == ">=")
|
if (sv == ">="sv)
|
||||||
return ComparisonOperation::GreaterEq;
|
return ComparisonOperation::GreaterEq;
|
||||||
return ComparisonOperation::Greater;
|
return ComparisonOperation::Greater;
|
||||||
}
|
}
|
||||||
|
@ -278,13 +278,13 @@ public:
|
||||||
};
|
};
|
||||||
static ArithmeticOperation op_from(StringView sv)
|
static ArithmeticOperation op_from(StringView sv)
|
||||||
{
|
{
|
||||||
if (sv == "+")
|
if (sv == "+"sv)
|
||||||
return ArithmeticOperation::Sum;
|
return ArithmeticOperation::Sum;
|
||||||
if (sv == "-")
|
if (sv == "-"sv)
|
||||||
return ArithmeticOperation::Difference;
|
return ArithmeticOperation::Difference;
|
||||||
if (sv == "*")
|
if (sv == "*"sv)
|
||||||
return ArithmeticOperation::Product;
|
return ArithmeticOperation::Product;
|
||||||
if (sv == "/")
|
if (sv == "/"sv)
|
||||||
return ArithmeticOperation::Quotient;
|
return ArithmeticOperation::Quotient;
|
||||||
return ArithmeticOperation::Remainder;
|
return ArithmeticOperation::Remainder;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
}
|
}
|
||||||
case And: {
|
case And: {
|
||||||
auto left = parse(args, Comp);
|
auto left = parse(args, Comp);
|
||||||
while (!args.is_empty() && args.head() == "&") {
|
while (!args.is_empty() && args.head() == "&"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto right = parse(args, Comp);
|
auto right = parse(args, Comp);
|
||||||
left = make<BooleanExpression>(BooleanExpression::BooleanOperator::And, move(left), move(right));
|
left = make<BooleanExpression>(BooleanExpression::BooleanOperator::And, move(left), move(right));
|
||||||
|
@ -482,7 +482,7 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
}
|
}
|
||||||
case Comp: {
|
case Comp: {
|
||||||
auto left = parse(args, ArithS);
|
auto left = parse(args, ArithS);
|
||||||
while (!args.is_empty() && args.head().is_one_of("<", "<=", "=", "!=", "=>", ">")) {
|
while (!args.is_empty() && args.head().is_one_of("<"sv, "<="sv, "="sv, "!="sv, "=>"sv, ">"sv)) {
|
||||||
auto op = args.dequeue();
|
auto op = args.dequeue();
|
||||||
auto right = parse(args, ArithM);
|
auto right = parse(args, ArithM);
|
||||||
left = make<ComparisonExpression>(ComparisonExpression::op_from(op), move(left), move(right));
|
left = make<ComparisonExpression>(ComparisonExpression::op_from(op), move(left), move(right));
|
||||||
|
@ -491,7 +491,7 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
}
|
}
|
||||||
case ArithS: {
|
case ArithS: {
|
||||||
auto left = parse(args, ArithM);
|
auto left = parse(args, ArithM);
|
||||||
while (!args.is_empty() && args.head().is_one_of("+", "-")) {
|
while (!args.is_empty() && args.head().is_one_of("+"sv, "-"sv)) {
|
||||||
auto op = args.dequeue();
|
auto op = args.dequeue();
|
||||||
auto right = parse(args, ArithM);
|
auto right = parse(args, ArithM);
|
||||||
left = make<ArithmeticExpression>(ArithmeticExpression::op_from(op), move(left), move(right));
|
left = make<ArithmeticExpression>(ArithmeticExpression::op_from(op), move(left), move(right));
|
||||||
|
@ -500,7 +500,7 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
}
|
}
|
||||||
case ArithM: {
|
case ArithM: {
|
||||||
auto left = parse(args, StringO);
|
auto left = parse(args, StringO);
|
||||||
while (!args.is_empty() && args.head().is_one_of("*", "/", "%")) {
|
while (!args.is_empty() && args.head().is_one_of("*"sv, "/"sv, "%"sv)) {
|
||||||
auto op = args.dequeue();
|
auto op = args.dequeue();
|
||||||
auto right = parse(args, StringO);
|
auto right = parse(args, StringO);
|
||||||
left = make<ArithmeticExpression>(ArithmeticExpression::op_from(op), move(left), move(right));
|
left = make<ArithmeticExpression>(ArithmeticExpression::op_from(op), move(left), move(right));
|
||||||
|
@ -515,26 +515,26 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
|
|
||||||
while (!args.is_empty()) {
|
while (!args.is_empty()) {
|
||||||
auto& op = args.head();
|
auto& op = args.head();
|
||||||
if (op == "+") {
|
if (op == "+"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
left = make<ValueExpression>(args.dequeue());
|
left = make<ValueExpression>(args.dequeue());
|
||||||
} else if (op == "substr") {
|
} else if (op == "substr"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto str = parse(args, Paren);
|
auto str = parse(args, Paren);
|
||||||
auto pos = parse(args, Paren);
|
auto pos = parse(args, Paren);
|
||||||
auto len = parse(args, Paren);
|
auto len = parse(args, Paren);
|
||||||
left = make<StringExpression>(StringExpression::StringOperation::Substring, move(str), move(pos), move(len));
|
left = make<StringExpression>(StringExpression::StringOperation::Substring, move(str), move(pos), move(len));
|
||||||
} else if (op == "index") {
|
} else if (op == "index"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto str = parse(args, Paren);
|
auto str = parse(args, Paren);
|
||||||
auto chars = parse(args, Paren);
|
auto chars = parse(args, Paren);
|
||||||
left = make<StringExpression>(StringExpression::StringOperation::Index, move(str), move(chars));
|
left = make<StringExpression>(StringExpression::StringOperation::Index, move(str), move(chars));
|
||||||
} else if (op == "match") {
|
} else if (op == "match"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto str = parse(args, Paren);
|
auto str = parse(args, Paren);
|
||||||
auto pattern = parse(args, Paren);
|
auto pattern = parse(args, Paren);
|
||||||
left = make<StringExpression>(StringExpression::StringOperation::Match, move(str), move(pattern));
|
left = make<StringExpression>(StringExpression::StringOperation::Match, move(str), move(pattern));
|
||||||
} else if (op == "length") {
|
} else if (op == "length"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto str = parse(args, Paren);
|
auto str = parse(args, Paren);
|
||||||
left = make<StringExpression>(StringExpression::StringOperation::Length, move(str));
|
left = make<StringExpression>(StringExpression::StringOperation::Length, move(str));
|
||||||
|
@ -542,7 +542,7 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
left = parse(args, Paren);
|
left = parse(args, Paren);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args.is_empty() && args.head() == ":") {
|
if (!args.is_empty() && args.head() == ":"sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto right = parse(args, Paren);
|
auto right = parse(args, Paren);
|
||||||
left = make<StringExpression>(StringExpression::StringOperation::Match, left.release_nonnull(), move(right));
|
left = make<StringExpression>(StringExpression::StringOperation::Match, left.release_nonnull(), move(right));
|
||||||
|
@ -557,7 +557,7 @@ NonnullOwnPtr<Expression> Expression::parse(Queue<StringView>& args, Precedence
|
||||||
if (args.is_empty())
|
if (args.is_empty())
|
||||||
fail("Expected a term");
|
fail("Expected a term");
|
||||||
|
|
||||||
if (args.head() == "(") {
|
if (args.head() == "("sv) {
|
||||||
args.dequeue();
|
args.dequeue();
|
||||||
auto expr = parse(args);
|
auto expr = parse(args);
|
||||||
if (args.head() != ")")
|
if (args.head() != ")")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue