From 4b1d9cb760226fcf2b9d99d98ff4e46423cedfef Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 23 Oct 2013 05:19:52 +0000 Subject: [PATCH] make lazy_bdecode a bit more self-contained --- src/lazy_bdecode.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index f0951bb35..e6e8e4735 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -54,6 +54,8 @@ namespace libtorrent if (error_pos) *error_pos = start - orig_start; \ return -1; \ } + namespace { bool numeric(char c) { return c >= '0' && c <= '9'; } } + // fills in 'val' with what the string between start and the // first occurance of the delimiter is interpreted as an int. // return the pointer to the delimiter, or 0 if there is a @@ -62,7 +64,7 @@ namespace libtorrent { while (start < end && *start != delimiter) { - if (!is_digit(*start)) { return 0; } + if (!numeric(*start)) { return 0; } val *= 10; val += *start - '0'; ++start; @@ -119,7 +121,7 @@ namespace libtorrent stack.pop_back(); continue; } - if (!is_digit(t)) TORRENT_FAIL_BDECODE(bdecode_errors::expected_string); + if (!numeric(t)) TORRENT_FAIL_BDECODE(bdecode_errors::expected_string); boost::int64_t len = t - '0'; start = parse_int(start, end, ':', len); if (start == 0 || start + len + 3 > end || *start != ':') @@ -176,7 +178,7 @@ namespace libtorrent } default: { - if (!is_digit(t)) + if (!numeric(t)) TORRENT_FAIL_BDECODE(bdecode_errors::expected_value); boost::int64_t len = t - '0'; @@ -495,8 +497,8 @@ namespace libtorrent char const* str = e.string_ptr(); for (int i = 0; i < e.string_length(); ++i) { - using namespace std; - if (is_print((unsigned char)str[i])) continue; + char c = str[i]; + if (c >= 32 && c < 127) continue; printable = false; break; }