forked from premiere/premiere-libtorrent
added string_ends_with to replace boost (#1034)
added string_ends_with to replace boost
This commit is contained in:
parent
c05e29c48e
commit
227b630bd1
|
@ -51,4 +51,3 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_STRING_UTIL_HPP_INCLUDED
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/string_view.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -63,6 +64,8 @@ namespace libtorrent
|
|||
|
||||
TORRENT_EXTRA_EXPORT void url_random(char* begin, char* end);
|
||||
|
||||
TORRENT_EXTRA_EXPORT bool string_ends_with(string_view s1, string_view s2);
|
||||
|
||||
struct listen_interface_t
|
||||
{
|
||||
std::string device;
|
||||
|
@ -79,7 +82,7 @@ namespace libtorrent
|
|||
TORRENT_EXTRA_EXPORT std::string print_listen_interfaces(
|
||||
std::vector<listen_interface_t> const& in);
|
||||
|
||||
// this parses the string that's used as the liste_interfaces setting.
|
||||
// this parses the string that's used as the listen_interfaces setting.
|
||||
// it is a comma-separated list of IP or device names with ports. For
|
||||
// example: "eth0:6881,eth1:6881" or "127.0.0.1:6881"
|
||||
TORRENT_EXTRA_EXPORT void parse_comma_separated_string_port(
|
||||
|
@ -112,10 +115,9 @@ namespace libtorrent
|
|||
|
||||
#if TORRENT_USE_I2P
|
||||
|
||||
bool is_i2p_url(std::string const& url);
|
||||
TORRENT_EXTRA_EXPORT bool is_i2p_url(std::string const& url);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/parse_url.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
|
||||
#include <tuple> // for tie
|
||||
#include <cstdlib> // for malloc
|
||||
#include <cstring> // for memmov/strcpy/strlen
|
||||
|
||||
|
@ -113,6 +113,9 @@ namespace libtorrent
|
|||
|
||||
bool string_begins_no_case(char const* s1, char const* s2)
|
||||
{
|
||||
TORRENT_ASSERT(s1 != nullptr);
|
||||
TORRENT_ASSERT(s2 != nullptr);
|
||||
|
||||
while (*s1 != 0)
|
||||
{
|
||||
if (to_lower(*s1) != to_lower(*s2)) return false;
|
||||
|
@ -124,6 +127,9 @@ namespace libtorrent
|
|||
|
||||
bool string_equal_no_case(char const* s1, char const* s2)
|
||||
{
|
||||
TORRENT_ASSERT(s1 != nullptr);
|
||||
TORRENT_ASSERT(s2 != nullptr);
|
||||
|
||||
while (to_lower(*s1) == to_lower(*s2))
|
||||
{
|
||||
if (*s1 == 0) return true;
|
||||
|
@ -146,6 +152,11 @@ namespace libtorrent
|
|||
*begin++ = printable[random(sizeof(printable) - 2)];
|
||||
}
|
||||
|
||||
bool string_ends_with(string_view s1, string_view s2)
|
||||
{
|
||||
return s1.size() >= s2.size() && std::equal(s2.rbegin(), s2.rend(), s1.rbegin());
|
||||
}
|
||||
|
||||
char* allocate_string_copy(char const* str)
|
||||
{
|
||||
if (str == nullptr) return nullptr;
|
||||
|
@ -398,8 +409,7 @@ namespace libtorrent
|
|||
error_code ec;
|
||||
std::tie(ignore, ignore, hostname, ignore, ignore)
|
||||
= parse_url_components(url, ec);
|
||||
char const* top_domain = std::strrchr(hostname.c_str(), '.');
|
||||
return top_domain && std::strcmp(top_domain, ".i2p") == 0;
|
||||
return string_ends_with(hostname, ".i2p");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,9 +47,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#if TORRENT_USE_I2P
|
||||
# include <boost/algorithm/string/predicate.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_USE_OPENSSL
|
||||
#include "libtorrent/ssl_stream.hpp"
|
||||
|
@ -3317,11 +3314,11 @@ namespace libtorrent
|
|||
continue;
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
if (r.i2pconn && boost::algorithm::ends_with(i->hostname, ".i2p"))
|
||||
if (r.i2pconn && string_ends_with(i->hostname, ".i2p"))
|
||||
{
|
||||
// this is an i2p name, we need to use the sam connection
|
||||
// this is an i2p name, we need to use the SAM connection
|
||||
// to do the name lookup
|
||||
if (boost::algorithm::ends_with(i->hostname, ".b32.i2p"))
|
||||
if (string_ends_with(i->hostname, ".b32.i2p"))
|
||||
{
|
||||
ADD_OUTSTANDING_ASYNC("torrent::on_i2p_resolve");
|
||||
r.i2pconn->async_name_lookup(i->hostname.c_str()
|
||||
|
|
|
@ -106,9 +106,21 @@ TORRENT_TEST(string_equal_no_case)
|
|||
TEST_CHECK(string_equal_no_case("foobar", "foobar"));
|
||||
TEST_CHECK(!string_equal_no_case("foobar", "foobar "));
|
||||
TEST_CHECK(!string_equal_no_case("foobar", "F00"));
|
||||
TEST_CHECK(!string_equal_no_case("foobar", "foo"));
|
||||
TEST_CHECK(!string_equal_no_case("foo", "foobar"));
|
||||
|
||||
TEST_CHECK(string_begins_no_case("foobar", "FoobAR --"));
|
||||
TEST_CHECK(string_begins_no_case("foo", "foobar"));
|
||||
TEST_CHECK(!string_begins_no_case("foobar", "F00"));
|
||||
TEST_CHECK(!string_begins_no_case("foobar", "foo"));
|
||||
|
||||
TEST_CHECK(string_ends_with("foobar", "bar"));
|
||||
TEST_CHECK(string_ends_with("name.txt", ".txt"));
|
||||
TEST_CHECK(string_ends_with("name.a.b", ".a.b"));
|
||||
TEST_CHECK(!string_ends_with("-- FoobAR", "foobar"));
|
||||
TEST_CHECK(!string_ends_with("foobar", "F00"));
|
||||
TEST_CHECK(!string_ends_with("foobar", "foo"));
|
||||
TEST_CHECK(!string_ends_with("foo", "foobar"));
|
||||
}
|
||||
|
||||
TORRENT_TEST(to_string)
|
||||
|
@ -366,3 +378,12 @@ TORRENT_TEST(tokenize)
|
|||
, convert_to_native("foo") + convert_to_native("bar"));
|
||||
}
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
TORRENT_TEST(i2p_url)
|
||||
{
|
||||
TEST_CHECK(is_i2p_url("http://a.i2p/a"));
|
||||
TEST_CHECK(!is_i2p_url("http://a.I2P/a"));
|
||||
TEST_CHECK(!is_i2p_url("http://c.i3p"));
|
||||
TEST_CHECK(!is_i2p_url("http://i2p/foo bar"));
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue