-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update codebase from boost::string_view into std::string_view #4509
Changes from 25 commits
ba1da15
3850093
1141e0f
c966149
efaf7ae
92fda38
8c17a5c
eada2c3
4967121
6dbfd7f
e4015fd
be6e9be
9d9f40e
0c39f13
8da02e5
a433207
2cf0eb8
85e001d
88412ea
b780312
999d9c2
cee5ff8
ac77412
cfa960f
5313b13
204f9f4
d851b16
49968bf
a20907f
d3d309a
fcf1375
3cda316
ba99ab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
#include <boost/beast/core/string.hpp> | ||
#include <functional> | ||
#include <string> | ||
|
||
namespace Json { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,12 @@ | |
#include <ripple/app/ledger/LedgerMaster.h> | ||
#include <ripple/app/main/Application.h> | ||
#include <ripple/basics/base64.h> | ||
#include <ripple/basics/safe_cast.h> | ||
#include <ripple/beast/core/LexicalCast.h> | ||
#include <ripple/beast/rfc2616.h> | ||
#include <ripple/overlay/impl/Handshake.h> | ||
#include <ripple/protocol/digest.h> | ||
|
||
#include <boost/regex.hpp> | ||
|
||
#include <algorithm> | ||
#include <chrono> | ||
|
||
// VFALCO Shouldn't we have to include the OpenSSL | ||
// headers or something for SSL_get_finished? | ||
|
@@ -46,8 +42,8 @@ getFeatureValue( | |
return {}; | ||
boost::smatch match; | ||
boost::regex rx(feature + "=([^;\\s]+)"); | ||
std::string const value = header->value(); | ||
if (boost::regex_search(value, match, rx)) | ||
std::string const allFeatures = std::string{header->value()}; | ||
if (boost::regex_search(allFeatures, match, rx)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you call the overload of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting observation! boost provides the following typedefs for the
I need to use this overload for the regex_search function.
How can I work around this? |
||
return {match[1]}; | ||
return {}; | ||
} | ||
|
@@ -243,7 +239,7 @@ verifyHandshake( | |
{ | ||
std::uint32_t nid; | ||
|
||
if (!beast::lexicalCastChecked(nid, std::string(iter->value()))) | ||
if (!beast::lexicalCastChecked(nid, iter->value())) | ||
throw std::runtime_error("Invalid peer network identifier"); | ||
|
||
if (networkID && nid != *networkID) | ||
|
@@ -252,8 +248,7 @@ verifyHandshake( | |
|
||
if (auto const iter = headers.find("Network-Time"); iter != headers.end()) | ||
{ | ||
auto const netTime = | ||
[str = std::string(iter->value())]() -> TimeKeeper::time_point { | ||
auto const netTime = [str = iter->value()]() -> TimeKeeper::time_point { | ||
TimeKeeper::duration::rep val; | ||
|
||
if (beast::lexicalCastChecked(val, str)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,6 @@ | |
#include <ripple/server/SimpleWriter.h> | ||
|
||
#include <boost/algorithm/string/predicate.hpp> | ||
#include <boost/utility/in_place_factory.hpp> | ||
|
||
namespace ripple { | ||
|
||
|
@@ -829,7 +828,7 @@ OverlayImpl::getOverlayInfo() | |
auto version{sp->getVersion()}; | ||
if (!version.empty()) | ||
// Could move here if Json::value supported moving from strings | ||
pv[jss::version] = version; | ||
pv[jss::version] = std::string{version}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good place here for that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm okay |
||
} | ||
|
||
std::uint32_t minSeq, maxSeq; | ||
|
@@ -997,9 +996,9 @@ OverlayImpl::processValidatorList( | |
return true; | ||
}; | ||
|
||
auto key = req.target().substr(prefix.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd personally leave this alone. You're adding complexity for no real reason here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I leave type-deduction to auto, I'm not 100% sure if it is deduced as My observation is that construction of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sympathize with your position, @nbougalis. But I think perhaps the conversion can be done a bit more cleanly like this:
Since the FWIW, I have a theory regarding the garbage values at the end of If you construct a For more details see the description of constructor 4 on this page: https://en.cppreference.com/w/cpp/string/basic_string_view/basic_string_view The lesson from this is that the only situation where a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i missed this comment, thanks for the explanation Scott! yes, that makes sense |
||
std::string_view key = req.target().substr(prefix.size()); | ||
|
||
if (auto slash = key.find('/'); slash != boost::string_view::npos) | ||
if (auto slash = key.find('/'); slash != std::string_view::npos) | ||
{ | ||
auto verString = key.substr(0, slash); | ||
if (!boost::conversion::try_lexical_convert(verString, version)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to construct then assign to it. You can simply construct it:
The generated code is probably identical, but I think simply constructing the string is easier to read.