本文整理汇总了C++中CStr::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ CStr::Parse方法的具体用法?C++ CStr::Parse怎么用?C++ CStr::Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStr
的用法示例。
在下文中一共展示了CStr::Parse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseUrl
// Assuming formating like...
// http://user:[email protected]/directory/somefile.php?param=1¶m=2
CPropertyBag CIpAddress::ParseUrl( oexCSTR pUrl, oexUINT uMaxBufferSize )
{
// Ensure a valid pointer
if ( !pUrl )
return CPropertyBag();
// NULL terminated string? tsk, tsk...
if ( 0 >= uMaxBufferSize )
uMaxBufferSize = zstr::Length( pUrl );
// Anything to parse?
if ( !uMaxBufferSize )
return CPropertyBag();
// Propety bag object
CPropertyBag pb;
// Read into a string object
CStr str( pUrl, uMaxBufferSize );
// pb[ oexT( "scheme" ) ].ToString() = str.Parse( oexT( "://" ) );
// Read in the scheme
oexINT nScheme = str.FindSubStr( oexT( "://" ), 3 );
if ( 0 <= nScheme && nScheme == str.FindSubStr( oexT( ":" ), 1 ) )
pb[ oexT( "scheme" ) ].ToString() = str.SubStr( 0, nScheme ),
str.LTrim( nScheme + 3 );
// Trim off leading forward slashes
// str.LTrim( oexT( ":" ) );
// str.LTrim( oexT( "/" ) );
// Is there a username / password?
CStr tmp = str.Parse( oexT( "@" ) );
if ( tmp.Length() )
{
// Skip the @
str++;
// Divide username and password
CStr s = tmp.Parse( oexT( ":" ) );
if ( s.Length () )
{ pb[ oexT( "username" ) ].ToString() = s;
tmp++; pb[ oexT( "password" ) ].ToString() = tmp;
} // end if
else
pb[ oexT( "username" ) ].ToString() = tmp;
} // end if
// Parse the host
tmp = str.Parse( oexT( "/" ) );
if ( tmp.Length() )
{
CStr s = tmp.Parse( oexT( ":" ) );
if ( s.Length () )
{ pb[ oexT( "host" ) ].ToString() = s;
tmp++; pb[ oexT( "port" ) ].ToString() = tmp;
} // end if
else
pb[ oexT( "host" ) ].ToString() = tmp;
} // end if
// Grab the next token
tmp = str.Parse( oexT( "?" ) );
if ( tmp.Length() )
{
// Host or path?
if ( !pb.IsKey( oexT( "host" ) ) )
pb[ oexT( "host" ) ].ToString() = tmp;
else
pb[ oexT( "path" ) ].ToString() = tmp;
// Parse extra part
if ( str.Length() )
{
// Trim separator if any
if ( oexT( '?' ) == *str.Ptr() )
{
str.LTrim( 1 );
// Anything left over?
if ( str.Length() )
pb[ oexT( "extra" ) ].ToString() = str.Parse( oexT( "#" ) );
// Check for fragment
if ( oexT( '#' ) == *str.Ptr() )
{
// Strip off sep
str.LTrim( 1 );
// Check for fragment
if ( str.Length() )
pb[ oexT( "fragment" ) ].ToString() = str;
} // end if
//.........这里部分代码省略.........