本文整理汇总了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();
}
示例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>());
}
//.........这里部分代码省略.........