Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding some optional logging of the parse results
  • Loading branch information
lemire committed Dec 26, 2024
commit 5ca32435a0adae8a0a3d6768b50302ff85ed077a
17 changes: 17 additions & 0 deletions include/ada/url_pattern-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ada/url_pattern.h"

#include <string_view>
#include <format>

namespace ada {

Expand All @@ -17,6 +18,12 @@ inline bool url_pattern_component::has_regexp_groups() const noexcept
return has_regexp_groups_;
}

inline std::string url_pattern_component::to_string() const {
return std::format(R"({{"pattern": "{}", "has_regexp_groups": {}}})", pattern,
has_regexp_groups_ ? "true" : "false" //,
);
}

inline std::string_view url_pattern_component::get_pattern() const noexcept
ada_lifetime_bound {
return pattern;
Expand Down Expand Up @@ -63,6 +70,16 @@ url_pattern_component::create_component_match_result(
return result;
}

inline std::string url_pattern::to_string() const {
return std::format(
R"({{"protocol_component": "{}", "username_component": {}, "password_component": {}, "hostname_component": {}, "port_component": {}, "pathname_component": {}, "search_component": {}, "hash_component": {}, "ignore_case": {}}})",
protocol_component.to_string(), username_component.to_string(),
password_component.to_string(), hostname_component.to_string(),
port_component.to_string(), pathname_component.to_string(),
search_component.to_string(), hash_component.to_string(),
ignore_case_ ? "true" : "false");
}

inline std::string_view url_pattern::get_protocol() const ada_lifetime_bound {
// Return this's associated URL pattern's protocol component's pattern string.
return protocol_component.get_pattern();
Expand Down
4 changes: 4 additions & 0 deletions include/ada/url_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class url_pattern_component {
ada_lifetime_bound ada_warn_unused;
bool has_regexp_groups() const noexcept ada_lifetime_bound ada_warn_unused;

std::string to_string() const;

private:
std::string pattern{};
std::regex_constants::syntax_option_type flags{};
Expand Down Expand Up @@ -295,6 +297,8 @@ class url_pattern {
// @see https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
bool has_regexp_groups() const ada_lifetime_bound;

std::string to_string() const;

private:
url_pattern_component protocol_component{};
url_pattern_component username_component{};
Expand Down
3 changes: 3 additions & 0 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <filesystem>
#include <iostream>

#include "ada/log.h"
#include "gtest/gtest.h"
#include "simdjson.h"

Expand Down Expand Up @@ -252,6 +253,8 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
<< main_object.raw_json().value() << std::endl;
}

ada_log("parse_result: ", parse_result->to_string());

ondemand::array exactly_empty_components;
if (!main_object["exactly_empty_components"].get_array().get(
exactly_empty_components)) {
Expand Down
Loading