Improve the old del_tags function used to fix the previous color buttons bug,

...because it was really too messy and used isalpha() which was
inaccurate to check special format characters

and I am not sure if it was safe with exotic locale.
This commit is contained in:
Ali El Gariani 2007-07-20 03:15:55 +00:00
parent 219d6c12a0
commit 81e25996cd

View file

@ -118,33 +118,29 @@ static std::string::const_iterator parse_markup(std::string::const_iterator i1,
// Copy string but without tags at the begining
std::string del_tags(std::string name){
std::stringstream str;
bool not_colour = true;
bool not_name = true;
std::stringstream str;
bool color_block = false;
bool text_started = false;
std::string::const_iterator it;
for (it = name.begin(); it != name.end(); it++){
// Start of RGB definition block, so stop react on numbers
if (not_name && *it == '<'){
not_colour = false;
}
// Ending of RGB block
if (*it == '>'){
not_colour = true;
}
// Number outside colour block
if (not_name && not_colour && isdigit(*it)){
not_name = false;
}
// On the first analphabet character we stop react on specials characters
if (not_name && isalpha(*it)){
not_name = false;
}
if (!not_name){
str << *it;
if (!text_started) {
if (color_block) {
if (!isdigit(*it) && *it != ',' && *it != ' ') {
// '>' or bad RGB values, close the block
color_block = false;
}
continue;
} else if (*it == '<') {
// Start of RGB definition block
color_block = true;
continue;
} else if (is_format_char(*it)) {
//other format char
continue;
}
text_started = true;
}
str << *it;
}
return str.str();
}