mirror of https://github.com/aria2/aria2
Made decoderawstring return pair of iterators, not string.
parent
d1d4903665
commit
7d68c40a77
|
@ -86,6 +86,11 @@ public:
|
||||||
|
|
||||||
String(const unsigned char* data, size_t length);
|
String(const unsigned char* data, size_t length);
|
||||||
|
|
||||||
|
template<typename InputIterator>
|
||||||
|
String(InputIterator first, InputIterator last)
|
||||||
|
: str_(first, last)
|
||||||
|
{}
|
||||||
|
|
||||||
String();
|
String();
|
||||||
|
|
||||||
~String();
|
~String();
|
||||||
|
@ -104,6 +109,12 @@ public:
|
||||||
|
|
||||||
static SharedHandle<String> g(const unsigned char* data, size_t length);
|
static SharedHandle<String> g(const unsigned char* data, size_t length);
|
||||||
|
|
||||||
|
template<typename InputIterator>
|
||||||
|
static SharedHandle<String> g(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
return SharedHandle<String>(new String(first, last));
|
||||||
|
}
|
||||||
|
|
||||||
virtual void accept(ValueBaseVisitor& visitor) const;
|
virtual void accept(ValueBaseVisitor& visitor) const;
|
||||||
private:
|
private:
|
||||||
ValueType str_;
|
ValueType str_;
|
||||||
|
|
|
@ -57,7 +57,7 @@ decodeiter
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
std::pair<std::string, InputIterator>
|
std::pair<std::pair<InputIterator, InputIterator>, InputIterator>
|
||||||
decoderawstring(InputIterator first, InputIterator last)
|
decoderawstring(InputIterator first, InputIterator last)
|
||||||
{
|
{
|
||||||
InputIterator i = first;
|
InputIterator i = first;
|
||||||
|
@ -77,7 +77,7 @@ decoderawstring(InputIterator first, InputIterator last)
|
||||||
len, static_cast<int>(last-i)),
|
len, static_cast<int>(last-i)),
|
||||||
error_code::BENCODE_PARSE_ERROR);
|
error_code::BENCODE_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
return std::make_pair(std::string(i, i+len), i+len);
|
return std::make_pair(std::make_pair(i, i+len), i+len);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -86,8 +86,9 @@ template<typename InputIterator>
|
||||||
std::pair<SharedHandle<ValueBase>, InputIterator>
|
std::pair<SharedHandle<ValueBase>, InputIterator>
|
||||||
decodestring(InputIterator first, InputIterator last)
|
decodestring(InputIterator first, InputIterator last)
|
||||||
{
|
{
|
||||||
std::pair<std::string, InputIterator> r = decoderawstring(first, last);
|
std::pair<std::pair<InputIterator, InputIterator>, InputIterator> r =
|
||||||
return std::make_pair(String::g(r.first), r.second);
|
decoderawstring(first, last);
|
||||||
|
return std::make_pair(String::g(r.first.first, r.first.second), r.second);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -121,10 +122,11 @@ decodedict
|
||||||
if(*first == 'e') {
|
if(*first == 'e') {
|
||||||
return std::make_pair(dict, ++first);
|
return std::make_pair(dict, ++first);
|
||||||
} else {
|
} else {
|
||||||
std::pair<std::string, InputIterator> keyp = decoderawstring(first, last);
|
std::pair<std::pair<InputIterator, InputIterator>, InputIterator> keyp =
|
||||||
|
decoderawstring(first, last);
|
||||||
std::pair<SharedHandle<ValueBase>, InputIterator> r =
|
std::pair<SharedHandle<ValueBase>, InputIterator> r =
|
||||||
decodeiter(keyp.second, last, depth);
|
decodeiter(keyp.second, last, depth);
|
||||||
dict->put(keyp.first, r.first);
|
dict->put(std::string(keyp.first.first, keyp.first.second), r.first);
|
||||||
first = r.second;
|
first = r.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue