MCPcopy Create free account
hub / github.com/NativeScript/android / add_part

Method add_part

test-app/runtime/src/main/cpp/ada/ada.h:9972–10085  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9970
9971template <url_pattern_encoding_callback F>
9972std::optional<errors> url_pattern_parser<F>::add_part(
9973 std::string_view prefix, token* name_token, token* regexp_or_wildcard_token,
9974 std::string_view suffix, token* modifier_token) {
9975 // Let modifier be "none".
9976 auto modifier = url_pattern_part_modifier::none;
9977 // If modifier token is not null:
9978 if (modifier_token) {
9979 // If modifier token's value is "?" then set modifier to "optional".
9980 if (modifier_token->value == "?") {
9981 modifier = url_pattern_part_modifier::optional;
9982 } else if (modifier_token->value == "*") {
9983 // Otherwise if modifier token's value is "*" then set modifier to
9984 // "zero-or-more".
9985 modifier = url_pattern_part_modifier::zero_or_more;
9986 } else if (modifier_token->value == "+") {
9987 // Otherwise if modifier token's value is "+" then set modifier to
9988 // "one-or-more".
9989 modifier = url_pattern_part_modifier::one_or_more;
9990 }
9991 }
9992 // If name token is null and regexp or wildcard token is null and modifier
9993 // is "none":
9994 if (!name_token && !regexp_or_wildcard_token &&
9995 modifier == url_pattern_part_modifier::none) {
9996 // Append prefix to the end of parser's pending fixed value.
9997 pending_fixed_value.append(prefix);
9998 return std::nullopt;
9999 }
10000 // Run maybe add a part from the pending fixed value given parser.
10001 if (auto error = maybe_add_part_from_the_pending_fixed_value()) {
10002 return *error;
10003 }
10004 // If name token is null and regexp or wildcard token is null:
10005 if (!name_token && !regexp_or_wildcard_token) {
10006 // Assert: suffix is the empty string.
10007 ADA_ASSERT_TRUE(suffix.empty());
10008 // If prefix is the empty string, then return.
10009 if (prefix.empty()) return std::nullopt;
10010 // Let encoded value be the result of running parser's encoding callback
10011 // given prefix.
10012 auto encoded_value = encoding_callback(prefix);
10013 if (!encoded_value) {
10014 return encoded_value.error();
10015 }
10016 // Let part be a new part whose type is "fixed-text", value is encoded
10017 // value, and modifier is modifier.
10018 // Append part to parser's part list.
10019 parts.emplace_back(url_pattern_part_type::FIXED_TEXT,
10020 std::move(*encoded_value), modifier);
10021 return std::nullopt;
10022 }
10023 // Let regexp value be the empty string.
10024 std::string regexp_value{};
10025 // If regexp or wildcard token is null, then set regexp value to parser's
10026 // segment wildcard regexp.
10027 if (!regexp_or_wildcard_token) {
10028 regexp_value = segment_wildcard_regexp;
10029 } else if (regexp_or_wildcard_token->type == token_type::ASTERISK) {

Callers 1

parse_pattern_stringFunction · 0.80

Calls 5

to_stringFunction · 0.85
emplace_backMethod · 0.80
appendMethod · 0.65
clearMethod · 0.65
emptyMethod · 0.45

Tested by

no test coverage detected