本文整理汇总了C++中token::clean方法的典型用法代码示例。如果您正苦于以下问题:C++ token::clean方法的具体用法?C++ token::clean怎么用?C++ token::clean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类token
的用法示例。
在下文中一共展示了token::clean方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_operator
int parse_operator(string &str, string::iterator i_iter, token &output)
{
bool is_error = false;
output.clean();
if(i_iter != str.end())
{
switch(*i_iter)
{
case '+': output._typeid = OPER_ADD; break;
case '-': output._typeid = OPER_SUB; break;
case '*': output._typeid = OPER_MULT;break;
case '/': output._typeid = OPER_DIV; break;
case '=': output._typeid = OPER_EQU; break;
case '(': output._typeid = OPER_LPAR;break;
case '{': output._typeid = OPER_LPAR;break;
case ')': output._typeid = OPER_RPAR;break;
case '}': output._typeid = OPER_RPAR;break;
case '!': if((i_iter+1) != str.end() && *(i_iter + 1) == '=') output._typeid = OPER_NOTEQ;break;
default: is_error = true; break;
}
}else{
is_error = true;
}
if(is_error){
return -1;
}else if(output._typeid != OPER_NOTEQ){
output.elemt = *i_iter;
return 1;
}else{
output.elemt = "!=";
return 2;
}
}
示例2: parse_string
int parse_string(string &str, string::iterator i_iter, token& output)
{
const int s_input = 0;
const int s_exit = 1;
const int s_note = 2;
output.clean();
bool flag = false;
bool is_error = false;
vector <char> o;
string::iterator iter = i_iter;
int state = s_input;
if(*iter != '"'){
state = s_exit;
}else{
++iter;
}
while(flag == false)
{
switch(state)
{
case s_input:
if(iter == str.end()){
state = s_exit;
}else if(*iter == '\\'){
state = s_note;
}else if(*iter == '"'){
state = s_exit;
}else{
o.push_back(*iter++);
}
break;
case s_exit:
if(iter == i_iter) is_error = true;
flag = true;
break;
case s_note:
if((iter + 1) != str.end() && *(iter + 1) == '"'){
o.push_back(*(iter + 1 ));
iter += 2;
}else if((iter + 1) != str.end() && *(iter + 1) == 'n'){
o.push_back('\n');
iter += 2;
}else if((iter + 1) != str.end() && *(iter + 1) == 't'){
o.push_back('\t');
iter += 2;
}
state = s_input;
break;
}
}
if(is_error)
{
return -1;
}else{
output.elemt = string(o.begin(), o.end());
output._typeid = TYPE_STR;
return iter - i_iter;
}
}
示例3: parse_digit
int parse_digit(string &str, string::iterator i_iter, token& output)
{
output.clean();
const int s_input = 0;
const int s_exit = 1;
const int s_point = 2;
bool flag = false;
bool is_error = false;
bool is_point = false;
vector<char> o;
string::iterator iter = i_iter;
int state = s_input;
while(flag == false)
{
switch(state)
{
case s_input:
if(iter == str.end()){
state = s_exit;
}else if(*iter == '.'){
state = s_point;
}else if(is_digit(*iter) == false){
state = s_exit;
}else{
o.push_back(*iter++);
}
break;
case s_exit:
flag = true;
if(iter == i_iter) is_error = true;
break;
case s_point:
if(is_point){
is_error = true;
state = s_exit;
}else{
is_point = true;
o.push_back(*iter++);
state = s_input;
}
break;
}
}
if(is_error){
return -1;
}else{
output.elemt = string(o.begin(), o.end());
if(is_point){
output._typeid = TYPE_REAL;
}else{
output._typeid = TYPE_NUM;
}
return iter - i_iter;
}
}
示例4: parse_end
int parse_end(string &str, string::iterator i_iter, token &output)
{
output.clean();
if(i_iter != str.end())
{
if(is_end(*i_iter)){
output.elemt = ";";
output._typeid = END;
return 1;
}
}
return -1;
}
示例5: parse_identity
int parse_identity(string &str, string::iterator i_iter, token& output)
{
output.clean();
const int s_input = 0;
const int s_exit = 1;
bool flag = false;
bool is_error = false;
vector<char> o;
string::iterator iter = i_iter;
int state = s_input;
if(is_digit(*iter) == true) state = s_exit;
while(flag == false)
{
switch(state)
{
case s_input:
if(iter == str.end()){
state = s_exit;
}if(is_charactor(*iter) == false && is_digit(*iter) == false)
{
state = s_exit;
}else{
o.push_back(*iter++);
}
break;
case s_exit:
if(iter == i_iter) is_error = true;
flag = true;
break;
}
}
if(is_error){
return -1;
}else{
output.elemt = string(o.begin(), o.end());
output._typeid = ID;
return iter - i_iter;
}
}