Skip to content

Commit

Permalink
improve source
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed May 28, 2021
1 parent 13db9f4 commit fc14692
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
12 changes: 3 additions & 9 deletions include/jsoncons/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,6 @@ namespace jsoncons {

// string_source

template <class CharT, class T, class Enable=void>
struct is_string_sourceable : std::false_type {};

template <class CharT, class T>
struct is_string_sourceable<CharT,T,typename std::enable_if<std::is_same<typename T::value_type, CharT>::value>::type> : std::true_type {};

template <class CharT>
class string_source
{
Expand All @@ -258,13 +252,13 @@ namespace jsoncons {

template <class Source>
string_source(const Source& s,
typename std::enable_if<is_string_sourceable<value_type,typename std::decay<Source>::type>::value>::type* = 0)
typename std::enable_if<type_traits::is_string_or_string_view<Source>::value && std::is_same<value_type,typename Source::value_type>::value>::type* = 0)
: data_(s.data()), current_(s.data()), end_(s.data()+s.size())
{
}

string_source(const value_type* data, std::size_t size)
: data_(data), current_(data), end_(data+size)
string_source(const value_type* data)
: data_(data), current_(data), end_(data+std::char_traits<value_type>::length(data))
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/jsonpath/src/jsonpath_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void jsonpath_tests(const std::string& fpath)
{
flags |= jsonpath::result_options::sort;
}
auto expression = jsoncons::jsonpath::make_expression<json>(jsoncons::string_view(expr));
auto expression = jsoncons::jsonpath::make_expression<json>(expr);
if (test_case.contains("result"))
{
jsonpath::result_options rflags = flags | jsonpath::result_options::value;
Expand Down
20 changes: 10 additions & 10 deletions tests/src/json_in_place_update_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -76,7 +76,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -90,7 +90,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -105,7 +105,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -119,7 +119,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -133,7 +133,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -147,7 +147,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -161,7 +161,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -175,7 +175,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand All @@ -189,7 +189,7 @@ TEST_CASE("json in-place update tests")
snprintf(expected, 500, format.c_str(), "ab");

my_in_place_updater updater(input, (size_t)length, "id", "ab");
jsoncons::json_string_reader reader(jsoncons::string_view(input), updater);
jsoncons::json_string_reader reader(input, updater);
reader.read();
CHECK(std::string(input) == std::string(expected));
}
Expand Down

0 comments on commit fc14692

Please sign in to comment.