当前位置: 首页>>代码示例>>C++>>正文


C++ CStr::Parse方法代码示例

本文整理汇总了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&param=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

//.........这里部分代码省略.........
开发者ID:wheresjames,项目名称:winglib,代码行数:101,代码来源:ip_address.cpp


注:本文中的CStr::Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。