我们是祖国的好娃娃:关于把VC中的函数改写成PASCAL函数

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 13:43:50
这里有一段VC的函数 ,谁能把它用DELPHI语言写出来,或帮我注释一下也可以,谢谢.
const pair<bool,string> post_decode( const string::const_iterator& begin, const string::const_iterator& end )
{
pair<bool,string> ret;
ret.first = false;
string& rs = ret.second;
rs.reserve( distance(begin,end) );

for( string::const_iterator p=begin; p!=end; ++p )
{
// 为了速度,这里忽略合法性验证
if( *p == '+' )
rs += ' ';
else if( *p == '%' )
{
++p; if( p == end ) return ret; char c1 = *p - '0'; if( c1 > 9 ) c1 -= 7;
++p; if( p == end ) return ret; char c2 = *p - '0'; if( c2 > 9 ) c2 -= 7;
rs += ( (c1<<4) | c2 );
}
else
rs += *p;
}
ret.first = true;
return ret;
}
const pair<bool,string> post_decode( const string& scr )
{
return post_decode( scr.begin(), scr.end() );
}

// 对整个post进行解码
const pair<bool,map<string,string> > post_decodes( const string::const_iterator& begin, const string::const_iterator& end )
{
pair<bool,map<string,string> > ret;
ret.first = false;
map<string,string>& hs = ret.second;

string::const_iterator p=begin,p1=begin,p2=begin;
for( ; p!=end; ++p )
{
if( *p == '=' )
{
p2 = p;
}
else if( *p == '&' )
{
if( p1 >= p2 ) // error
return ret;
const pair<bool,string> _key = post_decode( p1, p2 );
if( !_key.first || _key.second.empty() ) return ret;
++p2;
const pair<bool,string> _val = post_decode( p2, p );
if( !_val.first ) return ret;
p1 = p;
++p1;

hs[ _key.second ] = _val.second;
}
}
if( p2 != begin )
{
if( p1 >= p2 ) // error
return ret;
const pair<bool,string> _key = post_decode( p1, p2 );
if( !_key.first || _key.second.empty() ) return ret;
++p2;
const pair<bool,string> _val = post_decode( p2, p );
if( !_val.first ) return ret;

hs[ _key.second ] = _val.second;
}
ret.first = true;
return ret;
}
const pair<bool,map<string,string> > post_decodes( const string& scr )
{
return post_decodes( scr.begin(), scr.end() );
}