本文整理汇总了C++中bdecode_node::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ bdecode_node::clear方法的具体用法?C++ bdecode_node::clear怎么用?C++ bdecode_node::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bdecode_node
的用法示例。
在下文中一共展示了bdecode_node::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bdecode
int bdecode(char const* start, char const* end, bdecode_node& ret
, error_code& ec, int* error_pos, int depth_limit, int token_limit)
{
ec.clear();
ret.clear();
if (end - start > bdecode_token::max_offset)
{
if (error_pos) *error_pos = 0;
ec = make_error_code(bdecode_errors::limit_exceeded);
return -1;
}
// this is the stack of bdecode_token indices, into m_tokens.
// sp is the stack pointer, as index into the array, stack
int sp = 0;
stack_frame* stack = TORRENT_ALLOCA(stack_frame, depth_limit);
char const* const orig_start = start;
if (start == end) return 0;
while (start <= end)
{
if (start >= end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
if (sp >= depth_limit)
TORRENT_FAIL_BDECODE(bdecode_errors::depth_exceeded);
--token_limit;
if (token_limit < 0)
TORRENT_FAIL_BDECODE(bdecode_errors::limit_exceeded);
// look for a new token
const char t = *start;
const int current_frame = sp;
// if we're currently parsing a dictionary, assert that
// every other node is a string.
if (current_frame > 0
&& ret.m_tokens[stack[current_frame-1].token].type == bdecode_token::dict)
{
if (stack[current_frame-1].state == 0)
{
// the current parent is a dict and we are parsing a key.
// only allow a digit (for a string) or 'e' to terminate
if (!numeric(t) && t != 'e')
TORRENT_FAIL_BDECODE(bdecode_errors::expected_digit);
}
}
switch (t)
{
case 'd':
stack[sp++] = ret.m_tokens.size();
// we push it into the stack so that we know where to fill
// in the next_node field once we pop this node off the stack.
// i.e. get to the node following the dictionary in the buffer
ret.m_tokens.push_back(bdecode_token(start - orig_start
, bdecode_token::dict));
++start;
break;
case 'l':
stack[sp++] = ret.m_tokens.size();
// we push it into the stack so that we know where to fill
// in the next_node field once we pop this node off the stack.
// i.e. get to the node following the list in the buffer
ret.m_tokens.push_back(bdecode_token(start - orig_start
, bdecode_token::list));
++start;
break;
case 'i':
{
char const* int_start = start;
bdecode_errors::error_code_enum e = bdecode_errors::no_error;
// +1 here to point to the first digit, rather than 'i'
start = check_integer(start + 1, end, e);
if (e)
{
// in order to gracefully terminate the tree,
// make sure the end of the previous token is set correctly
if (error_pos) *error_pos = start - orig_start;
error_pos = NULL;
start = int_start;
TORRENT_FAIL_BDECODE(e);
}
ret.m_tokens.push_back(bdecode_token(int_start - orig_start
, 1, bdecode_token::integer, 1));
TORRENT_ASSERT(*start == 'e');
// skip 'e'
++start;
break;
}
case 'e':
{
// this is the end of a list or dict
if (sp == 0)
TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
//.........这里部分代码省略.........