Skip to content

Commit

Permalink
Make uri(string) ctor explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 5, 2024
1 parent 151c917 commit 09f9fec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
11 changes: 7 additions & 4 deletions doc/ref/corelib/uri.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The class `uri` represents a Uniform Resource Identifier (URI) reference.

uri();

uri(const std::string& s);
Constructs a URI by parsing the given string.
explicit uri(const std::string& str);
Constructs a `uri` by parsing the given string.

uri(const std::string& uri);
Constructs a URI by parsing the given string.
Constructs a `uri` by parsing the given string.

uri(jsoncons::string_view scheme,
jsoncons::string_view userinfo,
Expand All @@ -23,7 +23,7 @@ Constructs a URI by parsing the given string.
jsoncons::string_view path,
jsoncons::string_view query,
jsoncons::string_view fragment)
Constructs a URI from the given non-encoded parts.
Constructs a `uri` from the given non-encoded parts.

uri(const uri& other);

Expand Down Expand Up @@ -90,6 +90,9 @@ scheme-specific part does not begin with a slash character ('/'), e.g. 'mailto:j

const std::string& string() const;

static uri parse(const std::string& str, std::error_code& ec);
Creates a `uri` by parsing the given string.

### Examples


42 changes: 21 additions & 21 deletions include/jsoncons/utility/uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ namespace jsoncons {
}
}

/*explicit*/ uri(const std::string& uri)
explicit uri(const std::string& str)
{
std::error_code ec;
*this = parse(uri, ec);
*this = parse(str, ec);
if (ec)
{
JSONCONS_THROW(std::system_error(ec));
Expand Down Expand Up @@ -531,7 +531,7 @@ namespace jsoncons {
}
return decoded;
}
static uri parse(const std::string& s, std::error_code& ec)
static uri parse(const std::string& str, std::error_code& ec)
{
part_type scheme;
part_type userinfo;
Expand All @@ -544,9 +544,9 @@ namespace jsoncons {
std::size_t start = 0;

parse_state state = parse_state::expect_scheme;
for (std::size_t i = 0; i < s.size(); ++i)
for (std::size_t i = 0; i < str.size(); ++i)
{
char c = s[i];
char c = str[i];
switch (state)
{
case parse_state::expect_scheme:
Expand Down Expand Up @@ -690,7 +690,7 @@ namespace jsoncons {
start = i+1;
break;
default:
if (!(is_pchar(c,s.data()+i, s.size() - i) || c == '/'))
if (!(is_pchar(c,str.data()+i, str.size() - i) || c == '/'))
{
ec = uri_errc::invalid_characters_in_path;
return uri{};
Expand Down Expand Up @@ -720,36 +720,36 @@ namespace jsoncons {
userinfo = std::make_pair(start,start);
host = std::make_pair(start,start);
port = std::make_pair(start,start);
path = std::make_pair(start,s.size());
query = std::make_pair(s.size(), s.size());
fragment = std::make_pair(s.size(), s.size());
path = std::make_pair(start,str.size());
query = std::make_pair(str.size(), str.size());
fragment = std::make_pair(str.size(), str.size());
break;
case parse_state::expect_userinfo:
userinfo = std::make_pair(start,start);
host = std::make_pair(start,s.size());
port = std::make_pair(s.size(), s.size());
path = std::make_pair(s.size(), s.size());
query = std::make_pair(s.size(), s.size());
fragment = std::make_pair(s.size(), s.size());
host = std::make_pair(start,str.size());
port = std::make_pair(str.size(), str.size());
path = std::make_pair(str.size(), str.size());
query = std::make_pair(str.size(), str.size());
fragment = std::make_pair(str.size(), str.size());
break;
case parse_state::expect_path:
path = std::make_pair(start,s.size());
query = std::make_pair(s.size(), s.size());
fragment = std::make_pair(s.size(), s.size());
path = std::make_pair(start,str.size());
query = std::make_pair(str.size(), str.size());
fragment = std::make_pair(str.size(), str.size());
break;
case parse_state::expect_query:
query = std::make_pair(start,s.size());
fragment = std::make_pair(s.size(), s.size());
query = std::make_pair(start,str.size());
fragment = std::make_pair(str.size(), str.size());
break;
case parse_state::expect_fragment:
fragment = std::make_pair(start,s.size());
fragment = std::make_pair(start,str.size());
break;
default:
ec = uri_errc::invalid_uri;
break;
}

return uri(s, scheme, userinfo, host, port, path, query, fragment);
return uri(str, scheme, userinfo, host, port, path, query, fragment);
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,7 @@ namespace jsonschema {
{
result = reporter.error(validation_message(this->keyword_name(),
this_context.eval_path(),
additional_properties_->schema_location().string(),
additional_properties_->schema_location(),
instance_location,
"Additional property '" + prop.key() + "' found but was invalid."));
if (result == walk_result::abort)
Expand Down
14 changes: 7 additions & 7 deletions include/jsoncons_ext/jsonschema/json_schema_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,23 @@ namespace jsonschema {
template <typename Json>
Json meta_resolver(const jsoncons::uri& uri)
{
if (uri.base() == schema_version::draft202012())
if (uri.base() == jsoncons::uri{schema_version::draft202012()})
{
return jsoncons::jsonschema::draft202012::schema_draft202012<Json>::get_schema();
}
else if (uri.base() == schema_version::draft201909())
else if (uri.base() == jsoncons::uri{schema_version::draft201909()})
{
return jsoncons::jsonschema::draft201909::schema_draft201909<Json>::get_schema();
}
else if (uri.base() == schema_version::draft7())
else if (uri.base() == jsoncons::uri{schema_version::draft7()})
{
return jsoncons::jsonschema::draft7::schema_draft7<Json>::get_schema();
}
else if (uri.base() == schema_version::draft6())
else if (uri.base() == jsoncons::uri{schema_version::draft6()})
{
return jsoncons::jsonschema::draft6::schema_draft6<Json>::get_schema();
}
else if (uri.base() == schema_version::draft4())
else if (uri.base() == jsoncons::uri{schema_version::draft4()})
{
return jsoncons::jsonschema::draft4::schema_draft4<Json>::get_schema();
}
Expand All @@ -209,7 +209,7 @@ namespace jsonschema {
#if !defined(JSONCONS_NO_DEPRECATED)
template <typename Json,typename ResolveURI>
JSONCONS_DEPRECATED_MSG("Instead, set `default_base_uri` in options")
typename std::enable_if<extension_traits::is_unary_function_object_exact<ResolveURI,Json,std::string>::value,json_schema<Json>>::type
typename std::enable_if<extension_traits::is_unary_function_object_exact<ResolveURI,Json,jsoncons::uri>::value,json_schema<Json>>::type
make_json_schema(Json sch, const std::string& retrieval_uri, const ResolveURI& resolve,
evaluation_options options = evaluation_options{})
{
Expand Down Expand Up @@ -244,7 +244,7 @@ namespace jsonschema {
#endif

template <typename Json,typename ResolveURI>
typename std::enable_if<extension_traits::is_unary_function_object_exact<ResolveURI,Json,std::string>::value,json_schema<Json>>::type
typename std::enable_if<extension_traits::is_unary_function_object_exact<ResolveURI,Json,jsoncons::uri>::value,json_schema<Json>>::type
make_json_schema(Json sch, const ResolveURI& resolve,
evaluation_options options = evaluation_options{})
{
Expand Down

0 comments on commit 09f9fec

Please sign in to comment.