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
Prev Previous commit
Next Next commit
guarding
  • Loading branch information
Daniel Lemire committed Dec 26, 2024
commit 8477db3778fa44e751a479b2cd8bfb2377d99f54
7 changes: 7 additions & 0 deletions include/ada/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,11 @@ namespace ada {
#define ada_lifetime_bound
#endif

#ifdef __has_include
#if __has_include(<format>)
#include <format>
#define ADA_HAS_FORMAT 1
#endif
#endif

#endif // ADA_COMMON_DEFS_H
9 changes: 8 additions & 1 deletion include/ada/url_pattern-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ada/url_pattern.h"

#include <string_view>
#include <format>

namespace ada {

Expand All @@ -19,9 +18,13 @@ inline bool url_pattern_component::has_regexp_groups() const noexcept
}

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

inline std::string_view url_pattern_component::get_pattern() const noexcept
Expand Down Expand Up @@ -71,13 +74,17 @@ url_pattern_component::create_component_match_result(
}

inline std::string url_pattern::to_string() const {
#ifdef ADA_HAS_FORMAT
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");
#else
return "";
#endif
}

inline std::string_view url_pattern::get_protocol() const ada_lifetime_bound {
Expand Down
4 changes: 2 additions & 2 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
FAIL() << "Test should have succeeded but failed" << std::endl
<< main_object.raw_json().value() << std::endl;
}

#ifdef ADA_HAS_FORMAT
ada_log("parse_result: ", parse_result->to_string());

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