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


C++ string_type::cbegin方法代码示例

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


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

示例1: error_code

pfs::error_code ubjson_ostream<OStreamType, JsonType>::write_string (string_type const & s, bool with_prefix)
{
    if (with_prefix) {
        // Using size is safe here (no matter the string encoding)
        if (s.size() == 1 && *s.cbegin() <= numeric_limits<int8_t>::max()) {
            _os << static_cast<int8_t>('C');
            _os << static_cast<int8_t>(*s.cbegin());
        } else {
            _os << static_cast<int8_t>('S');
            write_integer(static_cast<typename json_type::integer_type>(s.size()), true);
            _os << s.utf8();
        }
    } else {
        write_integer(static_cast<typename json_type::integer_type>(s.size()), true);
        _os << s;
    }

    return pfs::error_code();
}
开发者ID:semenovf,项目名称:pfs,代码行数:19,代码来源:ubjson_ostream.hpp

示例2: tokenize

/** Tokenize the expression.
	@return a TokenList containing the tokens from 'expression'. 
	@param expression [in] The expression to tokenize.
	@note Tokenizer dictionary may be updated if expression contains variables.
	@note Will throws 'BadCharacter' if the expression contains an un-tokenizable character.
	*/
TokenList Tokenizer::tokenize( string_type const& expression ) {
	TokenList tokenizedExpression;
	auto currentChar = expression.cbegin();

	for(;;) 
	{
		// strip whitespace
		while( currentChar != end(expression) && isspace(*currentChar) )
			++currentChar;

		// check of end of expression
		if( currentChar == end(expression) ) break;

		// check for a number
		if( isdigit( *currentChar ) ) {
			tokenizedExpression.push_back( _get_number( currentChar, expression ) );
			continue;
		}
		//check if left parenthesis
		if (*currentChar == '(') {
			tokenizedExpression.push_back(make<LeftParenthesis>());
			++currentChar;
			continue;
		}
		//check if right parenthesis
		if (*currentChar == ')') {
			tokenizedExpression.push_back(make<RightParenthesis>());
			++currentChar;
			continue;
		}
		//check if multiplication 
		if (*currentChar == '*') {
			tokenizedExpression.push_back(make<Multiplication>());
			++currentChar;
			continue;
		}
		//check if division
		if (*currentChar == '/') {
			tokenizedExpression.push_back(make<Division>());
			++currentChar;
			continue;
		}
		//chck if argument seperator
		if (*currentChar == ',') {
			tokenizedExpression.push_back(make<ArgumentSeparator>());
			++currentChar;
			continue;
		}
		//check for factorial or inequality operator
		if (*currentChar == '!') {
			if (next(currentChar) != end(expression)) {
				if (*next(currentChar) == '=') { //if next character is =, make inequality operator
					tokenizedExpression.push_back(make<Inequality>());
					currentChar++;
					currentChar++;
					continue;
				}
			}
			//if is not inequality operator, must be factorial operator
			tokenizedExpression.push_back(make<Factorial>());
			currentChar++;
			continue;
		}
		//check for addition or identity operator
		if (*currentChar == '+') {
			++currentChar;
			if (!tokenizedExpression.empty()) {
				if (is<RightParenthesis>(tokenizedExpression.back()) || is<Operand>(tokenizedExpression.back()) || is<Factorial>(tokenizedExpression.back())) {
					//if + relates to another token, must be an addition operator
					tokenizedExpression.push_back(make<Addition>()); 
				}
				else { //is an identity operator
					tokenizedExpression.push_back(make<Identity>());
				}
			}
			else { //in an empty expression must be identity operator
				tokenizedExpression.push_back(make<Identity>());
			}
			continue;
		}
		//check for subtraction or negatino operator
		if (*currentChar == '-') {
			++currentChar;
			if (!tokenizedExpression.empty()) {
				if (is<RightParenthesis>(tokenizedExpression.back()) || is<Operand>(tokenizedExpression.back()) || is<Factorial>(tokenizedExpression.back())) {
					tokenizedExpression.push_back(make<Subtraction>()); // same as addition, if related to operand, is subtraction
				}
				else {
					tokenizedExpression.push_back(make<Negation>()); //must be negation
				}
			}
			else {//empty expression, must be negation operator
				tokenizedExpression.push_back(make<Negation>());
			}
//.........这里部分代码省略.........
开发者ID:andrewsiegner,项目名称:CPPExpressionEvaluator,代码行数:101,代码来源:tokenizer.cpp


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