mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Improve URL string conversions and ostream support
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "../strings/String.h"
|
#include "../strings/String.h"
|
||||||
|
|
||||||
|
#include <ios>
|
||||||
|
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
|
||||||
/** A URL.
|
/** A URL.
|
||||||
@@ -90,7 +92,10 @@ public:
|
|||||||
String userinfo () const;
|
String userinfo () const;
|
||||||
|
|
||||||
/** Retrieve the full URL as a single string. */
|
/** Retrieve the full URL as a single string. */
|
||||||
String full () const;
|
/** @{ */
|
||||||
|
String toString () const;
|
||||||
|
std::string to_string() const;
|
||||||
|
/** @} */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_scheme;
|
String m_scheme;
|
||||||
@@ -105,14 +110,18 @@ private:
|
|||||||
|
|
||||||
/** URL comparisons. */
|
/** URL comparisons. */
|
||||||
/** @{ */
|
/** @{ */
|
||||||
inline bool operator== (URL const& lhs, URL const& rhs) { return lhs.full() == rhs.full(); }
|
inline bool operator== (URL const& lhs, URL const& rhs) { return lhs.toString() == rhs.toString(); }
|
||||||
inline bool operator!= (URL const& lhs, URL const& rhs) { return ! (lhs.full() == rhs.full()); }
|
inline bool operator!= (URL const& lhs, URL const& rhs) { return ! (lhs.toString() == rhs.toString()); }
|
||||||
inline bool operator< (URL const& lhs, URL const& rhs) { return lhs.full() < rhs.full(); }
|
inline bool operator< (URL const& lhs, URL const& rhs) { return lhs.toString() < rhs.toString(); }
|
||||||
inline bool operator> (URL const& lhs, URL const& rhs) { return rhs.full() < lhs.full(); }
|
inline bool operator> (URL const& lhs, URL const& rhs) { return rhs.toString() < lhs.toString(); }
|
||||||
inline bool operator<= (URL const& lhs, URL const& rhs) { return ! (rhs.full() < lhs.full()); }
|
inline bool operator<= (URL const& lhs, URL const& rhs) { return ! (rhs.toString() < lhs.toString()); }
|
||||||
inline bool operator>= (URL const& lhs, URL const& rhs) { return ! (lhs.full() < rhs.full()); }
|
inline bool operator>= (URL const& lhs, URL const& rhs) { return ! (lhs.toString() < rhs.toString()); }
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/** Output stream conversion. */
|
||||||
|
std::ostream& operator<< (std::ostream& os, URL const& url);
|
||||||
|
|
||||||
|
/** boost::hash support */
|
||||||
extern std::size_t hash_value (beast::URL const& url);
|
extern std::size_t hash_value (beast::URL const& url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ public:
|
|||||||
{
|
{
|
||||||
ParsedURL result (url);
|
ParsedURL result (url);
|
||||||
expect (result.error () == 0);
|
expect (result.error () == 0);
|
||||||
expect (result.url ().full () == url);
|
expect (result.url ().toString () == url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testURL ()
|
void testURL ()
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ String URL::userinfo () const
|
|||||||
|
|
||||||
foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
|
foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
|
||||||
*/
|
*/
|
||||||
String URL::full () const
|
String URL::toString () const
|
||||||
{
|
{
|
||||||
String s;
|
String s;
|
||||||
|
|
||||||
@@ -153,11 +153,22 @@ String URL::full () const
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string URL::to_string() const
|
||||||
|
{
|
||||||
|
return toString().toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<< (std::ostream &os, URL const& url)
|
||||||
|
{
|
||||||
|
os << url.to_string();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
std::size_t hash_value (URL const& v)
|
std::size_t hash_value (URL const& v)
|
||||||
{
|
{
|
||||||
return std::size_t (v.full().hash());
|
return std::size_t (v.toString().hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,17 +37,17 @@ public:
|
|||||||
|
|
||||||
String name ()
|
String name ()
|
||||||
{
|
{
|
||||||
return "URL: '" + m_url.full() + "'";
|
return "URL: '" + m_url.toString() + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
String uniqueID ()
|
String uniqueID ()
|
||||||
{
|
{
|
||||||
return "URL," + m_url.full();
|
return "URL," + m_url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
String createParam ()
|
String createParam ()
|
||||||
{
|
{
|
||||||
return m_url.full();
|
return m_url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancel ()
|
void cancel ()
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
journal.error <<
|
journal.error <<
|
||||||
"HTTP GET to " << m_url.full().toStdString() <<
|
"HTTP GET to " << m_url <<
|
||||||
" failed: '" << httpResult.first.message () << "'";
|
" failed: '" << httpResult.first.message () << "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user