replaced std::isdigit with is_digit, to avoid asserts on windows and locale dependency. Fixes #484

This commit is contained in:
Arvid Norberg 2009-02-18 06:01:24 +00:00
parent 25dd5c86b9
commit afd04635e9
6 changed files with 23 additions and 32 deletions

View File

@ -80,17 +80,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#if defined(_MSC_VER)
namespace std
{
using ::isdigit;
using ::atoi;
};
#define for if (false) {} else for
#endif
#include "libtorrent/escape_string.hpp"
namespace libtorrent
{
@ -341,7 +331,7 @@ namespace libtorrent
// ----------------------------------------------
// string
default:
if (isdigit((unsigned char)*in))
if (is_digit((unsigned char)*in))
{
std::string len_s = read_until(in, end, ':', err);
if (err)

View File

@ -42,7 +42,9 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> to_string(size_type n);
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> TORRENT_EXPORT to_string(size_type n);
bool TORRENT_EXPORT is_digit(char c);
bool TORRENT_EXPORT isprint(char c);
std::string TORRENT_EXPORT unescape_string(std::string const& s);
std::string TORRENT_EXPORT escape_string(const char* str, int len);

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/escape_string.hpp"
namespace libtorrent
{
@ -168,8 +169,6 @@ namespace libtorrent
inline std::istream& operator>>(std::istream& is, big_number& peer)
{
using namespace std;
for (big_number::iterator i = peer.begin();
i != peer.end(); ++i)
{
@ -182,11 +181,11 @@ namespace libtorrent
|| ((c[1] < '0' || c[1] > '9') && (c[1] < 'a' || c[1] > 'f'))
|| is.fail())
{
is.setstate(ios_base::failbit);
is.setstate(std::ios_base::failbit);
return is;
}
*i = ((isdigit(c[0])?c[0]-'0':c[0]-'a'+10) << 4)
+ (isdigit(c[1])?c[1]-'0':c[1]-'a'+10);
*i = ((is_digit(c[0])?c[0]-'0':c[0]-'a'+10) << 4)
+ (is_digit(c[1])?c[1]-'0':c[1]-'a'+10);
}
return is;
}

View File

@ -69,6 +69,16 @@ namespace libtorrent
return ret;
}
bool is_digit(char c)
{
return c >= '0' && c <= '9';
}
bool isprint(char c)
{
return c >= 32 && c < 127;
}
std::string unescape_string(std::string const& s)
{
std::string ret;

View File

@ -48,28 +48,19 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/identify_client.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/escape_string.hpp"
namespace
{
using namespace libtorrent;
bool is_digit(char c)
{
return c >= '0' && c <= '9';
}
int decode_digit(char c)
{
if (is_digit(c)) return c - '0';
return unsigned(c) - 'A' + 10;
}
bool isprint(char c)
{
return c >= 32 && c < 127;
}
// takes a peer id and returns a valid boost::optional
// object if the peer id matched the azureus style encoding
// the returned fingerprint contains information about the

View File

@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/lazy_entry.hpp"
#include "libtorrent/escape_string.hpp"
#include <iostream>
#include <iomanip>
#include <cstring>
@ -58,8 +59,7 @@ namespace libtorrent
{
while (start < end && *start != delimiter)
{
using namespace std;
if (!isdigit(*start)) { return 0; }
if (!is_digit(*start)) { return 0; }
val *= 10;
val += *start - '0';
++start;
@ -154,8 +154,7 @@ namespace libtorrent
}
default:
{
using namespace std;
if (!isdigit(t)) return fail_bdecode(ret);
if (!is_digit(t)) return fail_bdecode(ret);
boost::int64_t len = t - '0';
start = parse_int(start, end, ':', len);