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


C++ iterator::substr方法代码示例

本文整理汇总了C++中stringlist::iterator::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::substr方法的具体用法?C++ iterator::substr怎么用?C++ iterator::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stringlist::iterator的用法示例。


在下文中一共展示了iterator::substr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse_error

Command::Command(const char* first, const char* last) throw(parse_error)
		: from(INVALID_SID), to(INVALID_SID), dirty(false), full(first, last)
{
	initNumPosParams();
	// optimize later
	// this is lazy due to a DC++ bug that sends empty parameters...
	// ideally, we should not be using it
	StringList sl = Util::lazyStringTokenize(full);
	full += '\n';
	if(full.size() < 5 || sl[0].size() != 4)
		throw parse_error("invalid message type");
	action = sl[0][0];
	cmd = (CmdInt)(stringToFourCC(sl[0]) & 0xFFFFFF00);
	StringList::size_type loc;	// message parameters start at this index

	switch(action) {
	case 'F':
		from = ADC::toSid(sl[1]);
		features = sl[2];
		checkFeatures();
		loc = 3;
		break;
	case 'D':
	case 'E':
		from = ADC::toSid(sl[1]);
		to = ADC::toSid(sl[2]);
		loc = 3;
		break;
	case 'B':
	case 'S':
		from = ADC::toSid(sl[1]);
		loc = 2;
		break;
	case 'I':
	case 'H':
	case 'L':
		loc = 1;
		break;
	default:
		throw parse_error(string("invalid action type '") + action + '\'');
	}

	if (loc >= sl.size())
		throw parse_error("not enough tokens for message type");
	if (numPosParams.count(cmd)) {
		// known command -- check that positional and named params are correct
		if (loc + numPosParams[cmd] > sl.size())
			throw parse_error("missing parameters");
		for (StringList::iterator i = sl.begin() + loc + numPosParams[cmd]; i != sl.end(); ++i) {
			// param name parts can't be escaped chars
			if (i->size() < 2 || ADC::CSE(i->substr(0, 2)).size() != 2)
				throw parse_error("invalid named parameter: " + *i);
		}
	}
	params.resize(sl.size() - loc);
	transform(sl.begin() + loc, sl.end(), params.begin(), &ADC::CSE);
}
开发者ID:pseudonym,项目名称:qhub,代码行数:57,代码来源:Command.cpp

示例2: HandleRequest

// creates a page based on user input -- either displays data from
//   form or presents a form for users to submit data.
ResponseCode FormTester::HandleRequest ( HttpRequest * ipoHttpRequest,
        HttpResponse * ipoHttpResponse )
{
    char psHtml[ 5000 ];


    // if we got data from the user, show it
    if ( ipoHttpRequest->oFormValueMap [ "user" ].sBody.length ( ) ||
            ipoHttpRequest->oFormValueMap [ "existinguser" ].sBody.length ( ) ) {

        std::string sName;

        sName = ipoHttpRequest->oFormValueMap [ "existinguser" ].sBody;
        if ( ipoHttpRequest->oFormValueMap [ "user" ].sBody.length() ) {
            sName = ipoHttpRequest->oFormValueMap [ "user" ].sBody;
        }

        fprintf ( stderr, "Got name of %s\n", sName.c_str ( ) );

        char * psHtml = new char [ 5000 ];
        sprintf ( psHtml, "<html><head><title>StringList</title></head>\n<body>Hi %s</body></html>", sName.c_str ( ) );
        oNameList.push_back ( sName );

        ipoHttpResponse->SetBody( psHtml, strlen( psHtml ) );
        return HTTPRESPONSECODE_200_OK;

    } else {

        // otherwise, present the form to the user to fill in
        fprintf ( stderr, "Got no form data\n" );

        // create the options for the dropdown box
        char * psOptions;
        if ( oNameList.size ( ) > 0 )
            psOptions = new char [ oNameList.size ( ) * 200 ];
        else
            psOptions = new char [1];

        psOptions [ 0 ] = '\0';

        for ( StringList::iterator oCurrentName = oNameList.begin();
                oCurrentName != oNameList.end ( );
                oCurrentName++ ) {

            char psOption [ 200 ];
            sprintf ( psOption, "<option>%s\n",
                      oCurrentName->substr ( 0, 150 ).c_str ( ) );
            strcat ( psOptions, psOption );

        }

        sprintf ( psHtml, "<html><head><title>StringList</title></head> <body>Please log in<P> <form action = \"/\" method=GET> User name: <input type = text  name = user><BR> <select name = existinguser width = 20> %s </select> <input type = submit> </form>\n",
                  psOptions );

        delete[] psOptions;

        ipoHttpResponse->SetBody( psHtml, strlen( psHtml ) );
        return HTTPRESPONSECODE_200_OK;

    }

}
开发者ID:F420,项目名称:mtasa-blue,代码行数:64,代码来源:ehs_formtest.cpp


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