I have written the code below to highlight words in quite large documents. Problem is:
1. It needs to be case insensitive, ie: "dog" or "Dog" should match "dog"
2. It currently matches words inside other words
Can anyone help?
Many thanks
void highlightTerms(vector<string> finalWords, string *source){
for (int i = 0; i != finalWords.size(); ++i) {
string::size_type spos = 0;
string what = finalWords[i];
string startTag = "<font color=\"red\">";
string endTag = "</font>";
string del = " .?;|!\n\"";/* delimeter points to end the tagging*/
while((spos = source->find(what,spos)) != string::npos){
bool is_word = true;
if(is_word){
source->insert(spos,startTag);
spos += startTag.length();
spos = source->find_first_of(del,spos);
if(spos != string::npos){source->insert(spos,endTag);}
if((spos += endTag.length()) >= source->length()) break;
}
}
}
}