|
24 | 24 | AdvancedTemplateBBCode::AdvancedTemplateBBCode(const std::string& code, const MsgTemplate& tpl, const std::string& inner, const std::string& attr) |
25 | 25 | : SimpleTemplateBBCode(code, tpl, inner), m_AttrName(attr) |
26 | 26 | { |
27 | | - |
28 | 27 | } |
29 | 28 |
|
30 | 29 | void AdvancedTemplateBBCode::applyToText(std::string& text) const |
31 | 30 | { |
32 | | - const std::string code = "["+getName()+"="; |
33 | | - const std::string end_code = "[/"+getName()+"]"; |
| 31 | + const std::string code = "[" + getName() + "="; |
| 32 | + const std::string end_code = "[/" + getName() + "]"; |
34 | 33 | std::string::size_type pos = find_ci(text, code); |
35 | 34 | std::string::size_type bracket_pos = std::string::npos; |
36 | 35 | std::string::size_type end_pos = std::string::npos; |
37 | 36 | MsgTemplate tpl = getTemplate(); |
38 | | - while (pos!=std::string::npos) |
| 37 | + while (pos != std::string::npos) |
39 | 38 | { |
40 | | - bracket_pos = find_ci(text, "]", pos+1); |
41 | | - if (bracket_pos==std::string::npos) return; |
42 | | - end_pos = find_ci(text, end_code, bracket_pos+1); |
43 | | - if (end_pos==std::string::npos) return; |
44 | | - std::string attr_text = text.substr(pos+code.length(), bracket_pos-(pos+code.length())); |
45 | | - if (attr_text.length()>1) |
| 39 | + bracket_pos = find_ci(text, "]", pos + 1); |
| 40 | + if (bracket_pos == std::string::npos) |
| 41 | + return; |
| 42 | + end_pos = find_ci(text, end_code, bracket_pos + 1); |
| 43 | + if (end_pos == std::string::npos) |
| 44 | + return; |
| 45 | + std::string attr_text = text.substr(pos + code.length(), bracket_pos - (pos + code.length())); |
| 46 | + if (attr_text.length() > 1) |
46 | 47 | { |
47 | | - if ((attr_text[0]=='"') and (attr_text[attr_text.length()-1]=='"')) |
| 48 | + if ((attr_text[0] == '"') && (attr_text[attr_text.length()-1] == '"')) |
48 | 49 | { |
49 | | - attr_text.erase(attr_text.length()-1, 1); |
| 50 | + attr_text.erase(attr_text.length() - 1, 1); |
50 | 51 | attr_text.erase(0, 1); |
51 | 52 | } |
52 | 53 | } |
53 | | - const std::string inner_text = text.substr(bracket_pos+1, end_pos-(bracket_pos+1)); |
| 54 | + const std::string inner_text = text.substr(bracket_pos + 1, end_pos - (bracket_pos + 1)); |
54 | 55 | tpl.addReplacement(getInnerName(), transformInner(inner_text), false); |
55 | 56 | tpl.addReplacement(m_AttrName, transformAttribute(attr_text), false); |
56 | | - text.replace(pos, end_pos+end_code.length()-pos, tpl.show()); |
| 57 | + text.replace(pos, end_pos + end_code.length() - pos, tpl.show()); |
57 | 58 | pos = find_ci(text, code, pos); |
58 | | - }//while |
| 59 | + } |
59 | 60 | } |
0 commit comments