Skip to content

Conversation

@sdkrystian
Copy link
Member

This implements the new boost::json::string interface, along with checked replacement and insertion. replace and insert for InputIterator still need to be implemented as checked.

@sdkrystian sdkrystian force-pushed the new-string-interface branch from a6960de to 55c1c5c Compare February 8, 2020 22:48
@codecov
Copy link

codecov bot commented Feb 8, 2020

Codecov Report

Merging #37 into develop will decrease coverage by 0.87%.
The diff coverage is 71.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop     #37      +/-   ##
==========================================
- Coverage    99.08%   98.2%   -0.88%     
==========================================
  Files           57      57              
  Lines         4823    4856      +33     
==========================================
- Hits          4779    4769      -10     
- Misses          44      87      +43
Impacted Files Coverage Δ
include/boost/json/detail/string_impl.hpp 100% <ø> (ø) ⬆️
include/boost/json/impl/string.ipp 100% <100%> (ø) ⬆️
include/boost/json/string.hpp 100% <100%> (ø) ⬆️
include/boost/json/impl/string.hpp 100% <100%> (ø) ⬆️
include/boost/json/detail/impl/string_impl.ipp 77.83% <65.21%> (-20.11%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5aae31d...7552858. Read the comment docs.

@sdkrystian sdkrystian force-pushed the new-string-interface branch 2 times, most recently from e930cb2 to 6e9a145 Compare February 8, 2020 23:29
@sdkrystian sdkrystian force-pushed the new-string-interface branch from 6e9a145 to 834b1e2 Compare February 8, 2020 23:41

#include <boost/json/error.hpp>
#include <boost/json/detail/string_impl.hpp>
#include <boost/json/detail/impl/string_impl.hpp>
Copy link
Member

@vinniefalco vinniefalco Feb 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should be including this here, it should be included in <boost/json/detail/string_impl.hpp>. These directives:
https://github.com/sdkrystian/json/blob/834b1e29f463fc391652eb22ffbaacf13540ea74/include/boost/json/detail/string_impl.hpp#L292

Should read:

#include <boost/json/detail/impl/string_impl.hpp>
#ifdef BOOST_JSON_HEADER_ONLY
#include <boost/json/detail/impl/string_impl.ipp>
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed; ptr_in_range was turned into an inline non-template function and moved into detail/string_impl.hpp

}

// KRYSTIAN TODO: this can be done without copies when
// reallocation is not needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the comment to explain that we should use a separate algorithm if iterator category is Forward or better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

iter_cat<InputIt>{});
cleanup c{tmp, dsp};
traits_type::copy(
impl_.replace_unchecked(first - begin(), last - first, tmp.size(), sp_),
Copy link
Member

@vinniefalco vinniefalco Feb 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long line.. out of balance with the other lines and blocks the chi. consider:

traits_type::copy(
     impl_.replace_unchecked(
         first - begin(),
         last - first,
         tmp.size(),
         sp_),
     tmp.data(),
     tmp.size());
return *this;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to multiple lines.

BOOST_TEST(s == std::string(
t.v1).insert(1, t.s2, 1, 3));
});
//// insert(size_type, string const&, size_type, size_type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a comment explaining why this is disabled, put your name in caps // SDK or something like that so the reader knows it is editorial.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

test/string.cpp Outdated
{
std::string s1(t.v2.data(), t.v2.size());
string s2(t.v2, sp);
BOOST_TEST(s2.replace(s2.begin(), s2.begin() + 1, t.v2.substr(0)) == s1.replace(0, 1, t.v2.data(), t.v2.size()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard to read

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted:

BOOST_TEST(
    s2.replace(
        s2.begin(),
        s2.begin() + 1,
        t.v2.substr(0)) ==
    s1.replace(
        0, 1,
        t.v2.data(),
        t.v2.size()));

Now that I can read it... we are using the iterator overload of json::string but the index overload of std::string? Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted in new commit.

Now that I can read it... we are using the iterator overload of json::string but the index overload of std::string? Why?

They perform the same operation, it was just easier to copy the index based tests.

@vinniefalco
Copy link
Member

Looks great, minor style nits, but the tests need some work.

@vinniefalco
Copy link
Member

@sdkrystian sdkrystian force-pushed the new-string-interface branch 2 times, most recently from 0c8384a to 6027ce3 Compare February 9, 2020 00:28
@sdkrystian sdkrystian force-pushed the new-string-interface branch from 42b0f37 to 7552858 Compare February 9, 2020 00:41
@vinniefalco vinniefalco merged commit 7552858 into boostorg:develop Feb 11, 2020
@sdkrystian sdkrystian mentioned this pull request Feb 14, 2020
@sdkrystian sdkrystian deleted the new-string-interface branch June 8, 2020 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants