本文整理汇总了C++中utf8_string::get_length方法的典型用法代码示例。如果您正苦于以下问题:C++ utf8_string::get_length方法的具体用法?C++ utf8_string::get_length怎么用?C++ utf8_string::get_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8_string
的用法示例。
在下文中一共展示了utf8_string::get_length方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
shared_ptr<regex_node> csu::parse_literal(const utf8_string& regex, uint& position)
//parse a regex literal
{
list< shared_ptr<regex_node> > chars;
position+=1;
while(position<regex.get_length())
{
if(regex[position]=="\"")
{
auto a=shared_ptr<regex_node>(new concat_node(chars));
return a;
}
else if(regex[position]=="\\")//escape char
{
position+=1;
if(position==regex.get_length())
{
throw gen_exception("REGEX ERROR: escape charector at end of string");
}
else if( regex[position]=="\"" )
{
shared_ptr<regex_node> new_node(new multi_span(code_point(0x0022)));
chars.push_back(new_node);
}
else if(regex[position]=="\\")
{
shared_ptr<regex_node> new_node(new multi_span(code_point(0x005C)));
chars.push_back(new_node);
}
else if(regex[position]=="n")
{
shared_ptr<regex_node> new_node(new multi_span(code_point(0x000A)));
chars.push_back(new_node);
}
else if(regex[position]=="t")
{
shared_ptr<regex_node> new_node(new multi_span(code_point(0x0009)));
chars.push_back(new_node);
}
else
{
throw gen_exception("REGEX ERROR: unrecognized escape charector");
}
position+=1;
}
else
{
shared_ptr<regex_node> new_node(new multi_span(regex[position]));
chars.push_back(new_node);
position+=1;
}
}
throw gen_exception("REGEX ERROR: literal not terminated by \"");
}
示例2: make_pair
std::pair<int, int> NFA_automation::run(const utf8_string& input, bool print_status)
{
uint position_matched=0;
int accepting_info=-1;
uint current_position=0;
fill(current_states.begin(), current_states.end(), false);
current_states[0]=true;
while(true)
{
// test if we want to continue
bool cont=false;
for(bool in_state : current_states)
{
if(in_state)
{
cont=true;
break;
}
}
if(not cont) break; //if cont is false, then we have no active states
if(print_status) cout<<"ITER"<<endl;
// make epsilon transitions
bool made_epsilon_transition=false;
for(uint state_index=0; state_index!=num_states; state_index+=1)
{
if(not current_states[state_index]) continue;
if(states[state_index]->accepting_info>-1 and (current_position>position_matched or states[state_index]->accepting_info<accepting_info ) )
{
position_matched=current_position;
accepting_info=states[state_index]->accepting_info;
if( print_status) cout<<"accepted:"<<accepting_info<<" at "<<position_matched<<endl;
}
if(print_status) cout<<"transitions on epsilon:"<<endl;
made_epsilon_transition=made_epsilon_transition or enter_states(current_states, states[state_index]->get_transitions(NFA_state::epsilon) );
}
if(made_epsilon_transition) continue; //repeat last bit until no epsilon transitions
//make transitions based upon next charector
fill(new_states.begin(), new_states.end(), false);
if(current_position<input.get_length())
{
for(uint state_index=0; state_index!=num_states; state_index+=1)
{
if(not current_states[state_index]) continue;
if(print_status) cout<<"Transitions on "<<input[current_position]<<endl;
enter_states(new_states, states[state_index]->get_transitions(input[current_position]));
}
current_position+=1;
}
current_states=new_states;
}
return make_pair(position_matched, accepting_info);
}
示例3: put
void ring_buffer::put(utf8_string& data)
//put data at end of buffer
{
if(data.get_length()==0) return;
if( (n_nodes-length_loaded)<= data.get_length())//check to see if we have enough space
{
add_nodes(data.get_length()-(n_nodes-length_loaded)+1);
}
for(auto& charector : data)
{
empty_node->charector=charector;
empty_node=empty_node->next;
length_loaded++;
}
has_read_EOF=false;
}
示例4: count_whitespace
//functions for parsing regex into a regex AST
void csu::count_whitespace(const utf8_string& regex, uint& position)
//counts the amount of whitespace following(including) position
{
for( ; position<regex.get_length(); position++ )
{
if(not (regex[position]=="\n" or regex[position]=="\r" or regex[position]==" ") )
{
return;
}
}
}
示例5: ret
shared_ptr<regex_node> csu::parse_concat_node(const utf8_string& regex, uint& position)
//parses a series of regex nodes, forming them into a concat_node Will raise a gen_exception if regex can't be read
{
shared_ptr<concat_node> ret(new concat_node());
while(position<regex.get_length())
{
if(regex[position]==")")
{
break;
}
shared_ptr<regex_node> out=parse_single_node(regex, position);
if(not out)
{
return out;
}
ret->add_node(out);
}
return ret;
}
示例6: insert
void ring_buffer::insert(utf8_string& data)
//place data before end_node
{
if(data.get_length()==0) return;
//create new nodes and insert charectors
auto previous_node=end_node->previous;
auto before_data=previous_node;
for(auto& charector : data)
{
ring_buffer_node* new_node=new ring_buffer_node();
new_node->charector=charector;
previous_node->next=new_node;
new_node->previous=previous_node;
previous_node=new_node;
length_loaded++;
}
previous_node->next=end_node;
end_node->previous=previous_node;
end_node=before_data->next;
has_read_EOF=false;
}
示例7: gen_exception
shared_ptr<regex_node> csu::parse_single_node(const utf8_string& regex, uint& position)
//parse regex for single regexes. Will raise a gen_exception if regex can't be read
{
count_whitespace(regex, position);
std::shared_ptr<regex_node> new_node;
if( regex[position]=="\"" ) //we have a literal
{
new_node=parse_literal(regex, position);
if(not new_node)
{
return new_node;
}
if(not (regex[position]=="\""))
{
throw gen_exception("REGEX ERROR: literal is not ended by a '\"'");
}
position+=1;
}
else if(regex[position]=="(") //we have a group
{
position+=1;
new_node=parse_concat_node(regex, position);
if(not new_node)
{
throw gen_exception("REGEX ERROR: expected a regex group after '('");
}
if(not (regex[position]==")"))
{
throw gen_exception("REGEX ERROR: regex group not ended with a ')'");
}
position+=1;
}
else if(regex[position]=="[") //we have a class
{
position+=1;
new_node=parse_class(regex, position);
if(not new_node)
{
throw gen_exception("REGEX ERROR: expected a regex class inside of '['");
}
if(not (regex[position]=="]"))
{
throw gen_exception("REGEX ERROR: regex class not ended with a ']'");
}
position+=1;
}
else if(not regex[position].in(special_regex_charectors) ) //just a charector with no special significance
{
new_node=shared_ptr<regex_node>( new multi_span(regex[position]) );
position+=1;
}
else if(regex[position]=="\\") //escape char
{
if(regex[position+1].in(special_regex_charectors))
{
new_node=shared_ptr<regex_node>( new multi_span(regex[position]) );
position+=2;
}
else if(regex[position+1]=="t")
{
code_point tab(0x0009);
new_node=shared_ptr<regex_node>( new multi_span(tab) );
position+=2;
}
else if(regex[position+1]=="n")
{
code_point NL(0x000A);
new_node=shared_ptr<regex_node>( new multi_span(NL) );
position+=2;
}
else
{
throw gen_exception("REGEX ERROR: unrecognized escape charector");
}
}
else if(regex[position]==".")
{
code_point B(0x000000);
code_point E(0x1FFFFF);
new_node=shared_ptr<regex_node>( new multi_span({B},{E}) );
position+=1;
}
else
{
throw gen_exception("REGEX ERROR: unrecognized charector in regex:", regex[position]);
}
count_whitespace(regex, position);
if(position==regex.get_length())
{
return new_node;
}
//check for trailing operators
if(regex[position]=="?")
{
position+=1;
new_node=shared_ptr<regex_node>( new option_node(new_node) );
return new_node;
//.........这里部分代码省略.........