more work on minimizing shared object export symbol table
This commit is contained in:
parent
619c375528
commit
cafbf2ca1d
|
@ -57,6 +57,7 @@ set(sources
|
||||||
torrent_info
|
torrent_info
|
||||||
tracker_manager
|
tracker_manager
|
||||||
http_tracker_connection
|
http_tracker_connection
|
||||||
|
utf8
|
||||||
udp_tracker_connection
|
udp_tracker_connection
|
||||||
udp_socket
|
udp_socket
|
||||||
upnp
|
upnp
|
||||||
|
|
1
Jamfile
1
Jamfile
|
@ -492,6 +492,7 @@ SOURCES =
|
||||||
timestamp_history
|
timestamp_history
|
||||||
udp_socket
|
udp_socket
|
||||||
upnp
|
upnp
|
||||||
|
utf8
|
||||||
utp_socket_manager
|
utp_socket_manager
|
||||||
utp_stream
|
utp_stream
|
||||||
logger
|
logger
|
||||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/hasher.hpp"
|
#include "libtorrent/hasher.hpp"
|
||||||
#include "libtorrent/create_torrent.hpp"
|
#include "libtorrent/create_torrent.hpp"
|
||||||
#include "libtorrent/file.hpp"
|
#include "libtorrent/file.hpp"
|
||||||
|
#include "libtorrent/file_pool.hpp"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,6 @@ typedef boost::uint16_t UTF16;
|
||||||
typedef boost::uint8_t UTF8;
|
typedef boost::uint8_t UTF8;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#else
|
#else
|
||||||
#define TORRENT_EXPORT
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// msvc doesn't seem to have stdint.h
|
// msvc doesn't seem to have stdint.h
|
||||||
typedef unsigned __int32 UTF32;
|
typedef unsigned __int32 UTF32;
|
||||||
|
@ -132,19 +131,19 @@ typedef enum {
|
||||||
lenientConversion
|
lenientConversion
|
||||||
} ConversionFlags;
|
} ConversionFlags;
|
||||||
|
|
||||||
TORRENT_EXPORT ConversionResult ConvertUTF8toUTF16 (
|
ConversionResult ConvertUTF8toUTF16 (
|
||||||
const UTF8** sourceStart, const UTF8* sourceEnd,
|
const UTF8** sourceStart, const UTF8* sourceEnd,
|
||||||
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
|
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
|
||||||
|
|
||||||
TORRENT_EXPORT ConversionResult ConvertUTF16toUTF8 (
|
ConversionResult ConvertUTF16toUTF8 (
|
||||||
const UTF16** sourceStart, const UTF16* sourceEnd,
|
const UTF16** sourceStart, const UTF16* sourceEnd,
|
||||||
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
||||||
|
|
||||||
TORRENT_EXPORT ConversionResult ConvertUTF8toUTF32 (
|
ConversionResult ConvertUTF8toUTF32 (
|
||||||
const UTF8** sourceStart, const UTF8* sourceEnd,
|
const UTF8** sourceStart, const UTF8* sourceEnd,
|
||||||
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
|
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
|
||||||
|
|
||||||
TORRENT_EXPORT ConversionResult ConvertUTF32toUTF8 (
|
ConversionResult ConvertUTF32toUTF8 (
|
||||||
const UTF32** sourceStart, const UTF32* sourceEnd,
|
const UTF32** sourceStart, const UTF32* sourceEnd,
|
||||||
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/peer_id.hpp"
|
#include "libtorrent/peer_id.hpp"
|
||||||
#include "libtorrent/file_storage.hpp"
|
#include "libtorrent/file_storage.hpp"
|
||||||
#include "libtorrent/file_pool.hpp"
|
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
#include "libtorrent/storage.hpp"
|
#include "libtorrent/storage.hpp"
|
||||||
#include "libtorrent/hasher.hpp"
|
#include "libtorrent/hasher.hpp"
|
||||||
|
@ -188,8 +187,8 @@ namespace libtorrent
|
||||||
|
|
||||||
inline void nop(int i) {}
|
inline void nop(int i) {}
|
||||||
|
|
||||||
int TORRENT_EXPORT get_file_attributes(std::string const& p);
|
int get_file_attributes(std::string const& p);
|
||||||
std::string TORRENT_EXPORT get_symlink_path(std::string const& p);
|
std::string get_symlink_path(std::string const& p);
|
||||||
|
|
||||||
TORRENT_EXPORT void add_files_impl(file_storage& fs, std::string const& p
|
TORRENT_EXPORT void add_files_impl(file_storage& fs, std::string const& p
|
||||||
, std::string const& l, boost::function<bool(std::string)> pred
|
, std::string const& l, boost::function<bool(std::string)> pred
|
||||||
|
@ -253,35 +252,8 @@ namespace libtorrent
|
||||||
, filename(utf8), detail::default_pred, flags);
|
, filename(utf8), detail::default_pred, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Fun>
|
void TORRENT_EXPORT set_piece_hashes(create_torrent& t, std::wstring const& p
|
||||||
void set_piece_hashes(create_torrent& t, std::wstring const& p, Fun f
|
, boost::function<void(int)> const& f, error_code& ec);
|
||||||
, error_code& ec)
|
|
||||||
{
|
|
||||||
file_pool fp;
|
|
||||||
std::string utf8;
|
|
||||||
wchar_utf8(p, utf8);
|
|
||||||
boost::scoped_ptr<storage_interface> st(
|
|
||||||
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, utf8, fp
|
|
||||||
, std::vector<boost::uint8_t>()));
|
|
||||||
|
|
||||||
// calculate the hash for all pieces
|
|
||||||
int num = t.num_pieces();
|
|
||||||
std::vector<char> buf(t.piece_length());
|
|
||||||
for (int i = 0; i < num; ++i)
|
|
||||||
{
|
|
||||||
// read hits the disk and will block. Progress should
|
|
||||||
// be updated in between reads
|
|
||||||
st->read(&buf[0], i, 0, t.piece_size(i));
|
|
||||||
if (st->error())
|
|
||||||
{
|
|
||||||
ec = st->error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hasher h(&buf[0], t.piece_size(i));
|
|
||||||
t.set_hash(i, h.final());
|
|
||||||
f(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
template <class Fun>
|
template <class Fun>
|
||||||
|
|
|
@ -73,7 +73,7 @@ typedef boost::function<void(http_connection&, std::list<tcp::endpoint>&)> http_
|
||||||
|
|
||||||
// when bottled, the last two arguments to the handler
|
// when bottled, the last two arguments to the handler
|
||||||
// will always be 0
|
// will always be 0
|
||||||
struct TORRENT_EXPORT http_connection : boost::enable_shared_from_this<http_connection>, boost::noncopyable
|
struct TORRENT_EXTRA_EXPORT http_connection : boost::enable_shared_from_this<http_connection>, boost::noncopyable
|
||||||
{
|
{
|
||||||
http_connection(io_service& ios, connection_queue& cc
|
http_connection(io_service& ios, connection_queue& cc
|
||||||
, http_handler const& handler, bool bottled = true
|
, http_handler const& handler, bool bottled = true
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace libtorrent
|
||||||
// return true if the status code is a redirect
|
// return true if the status code is a redirect
|
||||||
bool is_redirect(int http_status);
|
bool is_redirect(int http_status);
|
||||||
|
|
||||||
class TORRENT_EXPORT http_parser
|
class TORRENT_EXTRA_EXPORT http_parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum flags_t { dont_parse_chunks = 1 };
|
enum flags_t { dont_parse_chunks = 1 };
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace libtorrent
|
||||||
struct session_impl;
|
struct session_impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TORRENT_EXPORT http_seed_connection
|
class TORRENT_EXTRA_EXPORT http_seed_connection
|
||||||
: public web_connection_base
|
: public web_connection_base
|
||||||
{
|
{
|
||||||
friend class invariant_access;
|
friend class invariant_access;
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace libtorrent
|
||||||
struct session_settings;
|
struct session_settings;
|
||||||
namespace aux { struct session_impl; }
|
namespace aux { struct session_impl; }
|
||||||
|
|
||||||
class TORRENT_EXPORT http_tracker_connection
|
class TORRENT_EXTRA_EXPORT http_tracker_connection
|
||||||
: public tracker_connection
|
: public tracker_connection
|
||||||
{
|
{
|
||||||
friend class tracker_manager;
|
friend class tracker_manager;
|
||||||
|
|
|
@ -68,8 +68,8 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
struct dht_tracker;
|
struct dht_tracker;
|
||||||
|
|
||||||
TORRENT_EXPORT void intrusive_ptr_add_ref(dht_tracker const*);
|
TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(dht_tracker const*);
|
||||||
TORRENT_EXPORT void intrusive_ptr_release(dht_tracker const*);
|
TORRENT_EXTRA_EXPORT void intrusive_ptr_release(dht_tracker const*);
|
||||||
|
|
||||||
struct dht_tracker
|
struct dht_tracker
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,7 +93,7 @@ struct key_desc_t
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
bool TORRENT_EXPORT verify_message(lazy_entry const* msg, key_desc_t const desc[]
|
bool TORRENT_EXTRA_EXPORT verify_message(lazy_entry const* msg, key_desc_t const desc[]
|
||||||
, lazy_entry const* ret[], int size , char* error, int error_size);
|
, lazy_entry const* ret[], int size , char* error, int error_size);
|
||||||
|
|
||||||
// this is the entry for every peer
|
// this is the entry for every peer
|
||||||
|
|
|
@ -48,8 +48,8 @@ struct msg;
|
||||||
struct traversal_algorithm;
|
struct traversal_algorithm;
|
||||||
|
|
||||||
// defined in rpc_manager.cpp
|
// defined in rpc_manager.cpp
|
||||||
TORRENT_EXPORT void intrusive_ptr_add_ref(observer const*);
|
TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(observer const*);
|
||||||
TORRENT_EXPORT void intrusive_ptr_release(observer const*);
|
TORRENT_EXTRA_EXPORT void intrusive_ptr_release(observer const*);
|
||||||
|
|
||||||
// intended struct layout (on 32 bit architectures)
|
// intended struct layout (on 32 bit architectures)
|
||||||
// offset size alignment field
|
// offset size alignment field
|
||||||
|
@ -64,8 +64,8 @@ TORRENT_EXPORT void intrusive_ptr_release(observer const*);
|
||||||
|
|
||||||
struct observer : boost::noncopyable
|
struct observer : boost::noncopyable
|
||||||
{
|
{
|
||||||
friend TORRENT_EXPORT void intrusive_ptr_add_ref(observer const*);
|
friend TORRENT_EXTRA_EXPORT void intrusive_ptr_add_ref(observer const*);
|
||||||
friend TORRENT_EXPORT void intrusive_ptr_release(observer const*);
|
friend TORRENT_EXTRA_EXPORT void intrusive_ptr_release(observer const*);
|
||||||
|
|
||||||
observer(boost::intrusive_ptr<traversal_algorithm> const& a
|
observer(boost::intrusive_ptr<traversal_algorithm> const& a
|
||||||
, udp::endpoint const& ep, node_id const& id)
|
, udp::endpoint const& ep, node_id const& id)
|
||||||
|
|
|
@ -83,7 +83,7 @@ struct routing_table_node
|
||||||
// bucket has failed, then it is put in the replacement
|
// bucket has failed, then it is put in the replacement
|
||||||
// cache (just like in the paper).
|
// cache (just like in the paper).
|
||||||
|
|
||||||
class TORRENT_EXPORT routing_table
|
class TORRENT_EXTRA_EXPORT routing_table
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
routing_table(node_id const& id, int bucket_size
|
routing_table(node_id const& id, int bucket_size
|
||||||
|
|
|
@ -65,7 +65,7 @@ struct null_observer : public observer
|
||||||
|
|
||||||
class routing_table;
|
class routing_table;
|
||||||
|
|
||||||
class TORRENT_EXPORT rpc_manager
|
class TORRENT_EXTRA_EXPORT rpc_manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef bool (*send_fun)(void* userdata, entry&, udp::endpoint const&, int);
|
typedef bool (*send_fun)(void* userdata, entry&, udp::endpoint const&, int);
|
||||||
|
|
|
@ -140,7 +140,7 @@ namespace libtorrent
|
||||||
{ return pb.block == block; }
|
{ return pb.block == block; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TORRENT_EXPORT peer_connection
|
class TORRENT_EXTRA_EXPORT peer_connection
|
||||||
: public bandwidth_socket
|
: public bandwidth_socket
|
||||||
, public boost::noncopyable
|
, public boost::noncopyable
|
||||||
{
|
{
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace libtorrent
|
||||||
// RSS feed. All user interaction with this object
|
// RSS feed. All user interaction with this object
|
||||||
// goes through the feed_handle, which makes sure all calls
|
// goes through the feed_handle, which makes sure all calls
|
||||||
// are posted to the network thread
|
// are posted to the network thread
|
||||||
struct TORRENT_EXPORT feed : boost::enable_shared_from_this<feed>
|
struct TORRENT_EXTRA_EXPORT feed : boost::enable_shared_from_this<feed>
|
||||||
{
|
{
|
||||||
friend void parse_feed(feed_state& f, int token, char const* name, char const* val);
|
friend void parse_feed(feed_state& f, int token, char const* name, char const* val);
|
||||||
|
|
||||||
|
|
|
@ -42,68 +42,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
|
|
||||||
#include "libtorrent/ConvertUTF.h"
|
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
inline int utf8_wchar(const std::string &utf8, std::wstring &wide)
|
TORRENT_EXPORT int utf8_wchar(const std::string &utf8, std::wstring &wide);
|
||||||
{
|
TORRENT_EXPORT int wchar_utf8(const std::wstring &wide, std::string &utf8);
|
||||||
// allocate space for worst-case
|
|
||||||
wide.resize(utf8.size());
|
|
||||||
wchar_t const* dst_start = wide.c_str();
|
|
||||||
char const* src_start = utf8.c_str();
|
|
||||||
ConversionResult ret;
|
|
||||||
if (sizeof(wchar_t) == sizeof(UTF32))
|
|
||||||
{
|
|
||||||
ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start
|
|
||||||
+ utf8.size(), (UTF32**)&dst_start, (UTF32*)dst_start + wide.size()
|
|
||||||
, lenientConversion);
|
|
||||||
wide.resize(dst_start - wide.c_str());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else if (sizeof(wchar_t) == sizeof(UTF16))
|
|
||||||
{
|
|
||||||
ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start
|
|
||||||
+ utf8.size(), (UTF16**)&dst_start, (UTF16*)dst_start + wide.size()
|
|
||||||
, lenientConversion);
|
|
||||||
wide.resize(dst_start - wide.c_str());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return sourceIllegal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int wchar_utf8(const std::wstring &wide, std::string &utf8)
|
|
||||||
{
|
|
||||||
// allocate space for worst-case
|
|
||||||
utf8.resize(wide.size() * 6);
|
|
||||||
if (wide.empty()) return 0;
|
|
||||||
char* dst_start = &utf8[0];
|
|
||||||
wchar_t const* src_start = wide.c_str();
|
|
||||||
ConversionResult ret;
|
|
||||||
if (sizeof(wchar_t) == sizeof(UTF32))
|
|
||||||
{
|
|
||||||
ret = ConvertUTF32toUTF8((const UTF32**)&src_start, (const UTF32*)src_start
|
|
||||||
+ wide.size(), (UTF8**)&dst_start, (UTF8*)dst_start + utf8.size()
|
|
||||||
, lenientConversion);
|
|
||||||
utf8.resize(dst_start - &utf8[0]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else if (sizeof(wchar_t) == sizeof(UTF16))
|
|
||||||
{
|
|
||||||
ret = ConvertUTF16toUTF8((const UTF16**)&src_start, (const UTF16*)src_start
|
|
||||||
+ wide.size(), (UTF8**)&dst_start, (UTF8*)dst_start + utf8.size()
|
|
||||||
, lenientConversion);
|
|
||||||
utf8.resize(dst_start - &utf8[0]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return sourceIllegal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // !BOOST_NO_STD_WSTRING
|
#endif // !BOOST_NO_STD_WSTRING
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ libtorrent_rasterbar_la_SOURCES = \
|
||||||
upnp.cpp \
|
upnp.cpp \
|
||||||
ut_metadata.cpp \
|
ut_metadata.cpp \
|
||||||
ut_pex.cpp \
|
ut_pex.cpp \
|
||||||
|
utf8.cpp \
|
||||||
utp_socket_manager.cpp \
|
utp_socket_manager.cpp \
|
||||||
utp_stream.cpp \
|
utp_stream.cpp \
|
||||||
web_peer_connection.cpp \
|
web_peer_connection.cpp \
|
||||||
|
|
|
@ -160,8 +160,39 @@ namespace libtorrent
|
||||||
char* m_piece;
|
char* m_piece;
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_piece_hashes(create_torrent& t, std::string const& p, boost::function<void(int)> f
|
#if TORRENT_USE_WSTRING
|
||||||
, error_code& ec)
|
void set_piece_hashes(create_torrent& t, std::wstring const& p
|
||||||
|
, boost::function<void(int)> const& f, error_code& ec)
|
||||||
|
{
|
||||||
|
file_pool fp;
|
||||||
|
std::string utf8;
|
||||||
|
wchar_utf8(p, utf8);
|
||||||
|
boost::scoped_ptr<storage_interface> st(
|
||||||
|
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, utf8, fp
|
||||||
|
, std::vector<boost::uint8_t>()));
|
||||||
|
|
||||||
|
// calculate the hash for all pieces
|
||||||
|
int num = t.num_pieces();
|
||||||
|
std::vector<char> buf(t.piece_length());
|
||||||
|
for (int i = 0; i < num; ++i)
|
||||||
|
{
|
||||||
|
// read hits the disk and will block. Progress should
|
||||||
|
// be updated in between reads
|
||||||
|
st->read(&buf[0], i, 0, t.piece_size(i));
|
||||||
|
if (st->error())
|
||||||
|
{
|
||||||
|
ec = st->error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hasher h(&buf[0], t.piece_size(i));
|
||||||
|
t.set_hash(i, h.final());
|
||||||
|
f(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void set_piece_hashes(create_torrent& t, std::string const& p
|
||||||
|
, boost::function<void(int)> f, error_code& ec)
|
||||||
{
|
{
|
||||||
file_pool fp;
|
file_pool fp;
|
||||||
boost::scoped_ptr<storage_interface> st(
|
boost::scoped_ptr<storage_interface> st(
|
||||||
|
|
|
@ -510,7 +510,7 @@ namespace libtorrent
|
||||||
return url.substr(pos, url.find('&', pos) - pos);
|
return url.substr(pos, url.find('&', pos) - pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXPORT std::string to_hex(std::string const& s)
|
TORRENT_EXTRA_EXPORT std::string to_hex(std::string const& s)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
|
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
|
||||||
|
@ -521,7 +521,7 @@ namespace libtorrent
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXPORT void to_hex(char const *in, int len, char* out)
|
TORRENT_EXTRA_EXPORT void to_hex(char const *in, int len, char* out)
|
||||||
{
|
{
|
||||||
for (char const* end = in + len; in < end; ++in)
|
for (char const* end = in + len; in < end; ++in)
|
||||||
{
|
{
|
||||||
|
@ -539,7 +539,7 @@ namespace libtorrent
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXPORT bool is_hex(char const *in, int len)
|
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len)
|
||||||
{
|
{
|
||||||
for (char const* end = in + len; in < end; ++in)
|
for (char const* end = in + len; in < end; ++in)
|
||||||
{
|
{
|
||||||
|
@ -549,7 +549,7 @@ namespace libtorrent
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out)
|
TORRENT_EXTRA_EXPORT bool from_hex(char const *in, int len, char* out)
|
||||||
{
|
{
|
||||||
for (char const* end = in + len; in < end; ++in, ++out)
|
for (char const* end = in + len; in < end; ++in, ++out)
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,7 +92,7 @@ namespace libtorrent
|
||||||
// fixes invalid UTF-8 sequences and
|
// fixes invalid UTF-8 sequences and
|
||||||
// replaces characters that are invalid
|
// replaces characters that are invalid
|
||||||
// in paths
|
// in paths
|
||||||
TORRENT_EXPORT bool verify_encoding(std::string& target, bool fix_paths = false)
|
TORRENT_EXTRA_EXPORT bool verify_encoding(std::string& target, bool fix_paths = false)
|
||||||
{
|
{
|
||||||
std::string tmp_path;
|
std::string tmp_path;
|
||||||
bool valid_encoding = true;
|
bool valid_encoding = true;
|
||||||
|
@ -213,7 +213,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXPORT std::string sanitize_path(std::string const& p)
|
TORRENT_EXTRA_EXPORT std::string sanitize_path(std::string const& p)
|
||||||
{
|
{
|
||||||
std::string new_path;
|
std::string new_path;
|
||||||
std::string split = split_path(p);
|
std::string split = split_path(p);
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (c) 2012, Arvid Norberg
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of the author nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived
|
||||||
|
from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libtorrent/config.hpp"
|
||||||
|
#include "libtorrent/utf8.hpp"
|
||||||
|
#include "libtorrent/ConvertUTF.h"
|
||||||
|
|
||||||
|
// on windows we need these functions for
|
||||||
|
// convert_to_native and convert_from_native
|
||||||
|
#if TORRENT_USE_WSTRING || defined TORRENT_WINDOWS
|
||||||
|
|
||||||
|
namespace libtorrent
|
||||||
|
{
|
||||||
|
int utf8_wchar(const std::string &utf8, std::wstring &wide)
|
||||||
|
{
|
||||||
|
// allocate space for worst-case
|
||||||
|
wide.resize(utf8.size());
|
||||||
|
wchar_t const* dst_start = wide.c_str();
|
||||||
|
char const* src_start = utf8.c_str();
|
||||||
|
ConversionResult ret;
|
||||||
|
if (sizeof(wchar_t) == sizeof(UTF32))
|
||||||
|
{
|
||||||
|
ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start
|
||||||
|
+ utf8.size(), (UTF32**)&dst_start, (UTF32*)dst_start + wide.size()
|
||||||
|
, lenientConversion);
|
||||||
|
wide.resize(dst_start - wide.c_str());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else if (sizeof(wchar_t) == sizeof(UTF16))
|
||||||
|
{
|
||||||
|
ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start
|
||||||
|
+ utf8.size(), (UTF16**)&dst_start, (UTF16*)dst_start + wide.size()
|
||||||
|
, lenientConversion);
|
||||||
|
wide.resize(dst_start - wide.c_str());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return sourceIllegal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int wchar_utf8(const std::wstring &wide, std::string &utf8)
|
||||||
|
{
|
||||||
|
// allocate space for worst-case
|
||||||
|
utf8.resize(wide.size() * 6);
|
||||||
|
if (wide.empty()) return 0;
|
||||||
|
char* dst_start = &utf8[0];
|
||||||
|
wchar_t const* src_start = wide.c_str();
|
||||||
|
ConversionResult ret;
|
||||||
|
if (sizeof(wchar_t) == sizeof(UTF32))
|
||||||
|
{
|
||||||
|
ret = ConvertUTF32toUTF8((const UTF32**)&src_start, (const UTF32*)src_start
|
||||||
|
+ wide.size(), (UTF8**)&dst_start, (UTF8*)dst_start + utf8.size()
|
||||||
|
, lenientConversion);
|
||||||
|
utf8.resize(dst_start - &utf8[0]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else if (sizeof(wchar_t) == sizeof(UTF16))
|
||||||
|
{
|
||||||
|
ret = ConvertUTF16toUTF8((const UTF16**)&src_start, (const UTF16*)src_start
|
||||||
|
+ wide.size(), (UTF8**)&dst_start, (UTF8*)dst_start + utf8.size()
|
||||||
|
, lenientConversion);
|
||||||
|
utf8.resize(dst_start - &utf8[0]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return sourceIllegal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ enum
|
||||||
// into account. if lhs is close to UINT_MAX and rhs
|
// into account. if lhs is close to UINT_MAX and rhs
|
||||||
// is close to 0, lhs is assumed to have wrapped and
|
// is close to 0, lhs is assumed to have wrapped and
|
||||||
// considered smaller
|
// considered smaller
|
||||||
TORRENT_EXPORT bool compare_less_wrap(boost::uint32_t lhs, boost::uint32_t rhs, boost::uint32_t mask)
|
TORRENT_EXTRA_EXPORT bool compare_less_wrap(boost::uint32_t lhs, boost::uint32_t rhs, boost::uint32_t mask)
|
||||||
{
|
{
|
||||||
// distance walking from lhs to rhs, downwards
|
// distance walking from lhs to rhs, downwards
|
||||||
boost::uint32_t dist_down = (lhs - rhs) & mask;
|
boost::uint32_t dist_down = (lhs - rhs) & mask;
|
||||||
|
|
Loading…
Reference in New Issue