我有一个程序可以迭代文本并将单词和带下划线的单词组放入数组中......代码如下:
//loop for all text in rich edit control
for(int i = 0; i < text.GetLength(); i++)
{
rEditCtrl.SetSel(i, i + 1); //from start to end character
rEditCtrl.GetSelectionCharFormat(cf);
if(cf.dwEffects & CFE_UNDERLINE) //check whether underline character
{
if(!groupMode) {
groupMode = true;
}
isSpace = false;
if(!word.IsEmpty()) {
std::pair <CString,bool> group;
group = std::make_pair(word,false);
groups.push_back(group);
word = "";
}
underlined = underlined + rEditCtrl.GetSelText();
}
else {
if(groupMode) {
rEditCtrl.SetSel(i, i + 1); //from start to end character
if(rEditCtrl.GetSelText() == " ") {
underlined = underlined + rEditCtrl.GetSelText();
}
else {
word = word + rEditCtrl.GetSelText();
}
groupMode = false;
if(!underlined.IsEmpty()) {
std::pair <CString,bool> group;
group = std::make_pair(underlined,true);
groups.push_back(group);
underlined = "";
}
}
else {
if(!isSpace) {
rEditCtrl.SetSel(i, i + 1); //from start to end character
if(rEditCtrl.GetSelText() == " ") {
isSpace = true;
}
else if(rEditCtrl.GetSelText() == "\r") {
if(!word.IsEmpty()) {
std::pair <CString,bool> group;
group = std::make_pair(word,false);
groups.push_back(group);
word = "";
}
}
else {
if(word == "\r") {
std::pair <CString,bool> group;
group = std::make_pair(word,false);
groups.push_back(group);
word = "";
}
}
word = word + rEditCtrl.GetSelText();
}
else if(isSpace) {
rEditCtrl.SetSel(i, i + 1); //from start to end character
if(rEditCtrl.GetSelText() != " ") {
isSpace = false;
if(!word.IsEmpty() && !AllSpaces(word)) {
std::pair <CString,bool> group;
group = std::make_pair(word,false);
groups.push_back(group);
word = "";
}
}
word = word + rEditCtrl.GetSelText();
}
}
}
}
我想知道是否有一种显而易见的方法来提高我所缺少的代码的效率,或者我是否已经使用并行来获得速度的任何提升......如果并行性是要走的路......我会怎么处理这个问题?我只能想到将文本分成两部分,从开始和结束开始,并在中间相遇?你怎么看?