Skip to content

Commit 2bb9ca1

Browse files
committed
adjust code style and improve code documentation slightly
1 parent 85debda commit 2bb9ca1

15 files changed

+168
-175
lines changed

code/MsgTemplate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424

2525
MsgTemplate::MsgTemplate()
2626
: m_Tags(std::map<std::string, std::string>()), m_Template("")
27-
{ }
27+
{
28+
}
2829

2930
MsgTemplate::MsgTemplate(const std::string& tplText)
3031
: m_Tags(std::map<std::string, std::string>()), m_Template(tplText)
31-
{ }
32+
{
33+
}
3234

3335
bool MsgTemplate::loadFromFile(const std::string& fileName)
3436
{

code/bbcode/AdvancedTemplateBBCode.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,37 @@
2424
AdvancedTemplateBBCode::AdvancedTemplateBBCode(const std::string& code, const MsgTemplate& tpl, const std::string& inner, const std::string& attr)
2525
: SimpleTemplateBBCode(code, tpl, inner), m_AttrName(attr)
2626
{
27-
2827
}
2928

3029
void AdvancedTemplateBBCode::applyToText(std::string& text) const
3130
{
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() + "]";
3433
std::string::size_type pos = find_ci(text, code);
3534
std::string::size_type bracket_pos = std::string::npos;
3635
std::string::size_type end_pos = std::string::npos;
3736
MsgTemplate tpl = getTemplate();
38-
while (pos!=std::string::npos)
37+
while (pos != std::string::npos)
3938
{
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)
4647
{
47-
if ((attr_text[0]=='"') and (attr_text[attr_text.length()-1]=='"'))
48+
if ((attr_text[0] == '"') && (attr_text[attr_text.length()-1] == '"'))
4849
{
49-
attr_text.erase(attr_text.length()-1, 1);
50+
attr_text.erase(attr_text.length() - 1, 1);
5051
attr_text.erase(0, 1);
5152
}
5253
}
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));
5455
tpl.addReplacement(getInnerName(), transformInner(inner_text), false);
5556
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());
5758
pos = find_ci(text, code, pos);
58-
}//while
59+
}
5960
}

code/bbcode/AdvancedTemplateBBCode.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "SimpleTemplateBBCode.hpp"
2525

2626
/** \brief AdvancedTemplateBBCode:
27-
struct for BB codes that use templates (class MsgTemplate) for the
27+
Struct for BB codes that use templates (class MsgTemplate) for the
2828
proper replacement of BB code. However, this class will just handle
2929
"advanced" BB codes of the form "[TAG=value]content[/TAG]" and NOT the
3030
simpler codes of the form "[TAG]content[/TAG]". See SimpleTemplateBBCode
@@ -40,22 +40,18 @@ struct AdvancedTemplateBBCode: public SimpleTemplateBBCode
4040
* \param inner name of the template tag for the inner code
4141
* \param attr name of the template tag for the attribute value
4242
*/
43-
AdvancedTemplateBBCode(const std::string& code, const MsgTemplate& tpl, const std::string& inner="inner", const std::string& attr="attribute");
43+
AdvancedTemplateBBCode(const std::string& code, const MsgTemplate& tpl, const std::string& inner = "inner", const std::string& attr = "attribute");
4444

4545

46-
/** destructor */
47-
virtual ~AdvancedTemplateBBCode() {}
48-
49-
50-
/** \brief "applies" the BB code to the given text, i.e. transforms the BB code
51-
* into its HTML representation
46+
/** \brief "Applies" the BB code to the given text, i.e. transforms the BB code
47+
* into its (X)HTML representation.
5248
*
5349
* \param text the message text that (may) contain the BB code
5450
*/
5551
virtual void applyToText(std::string& text) const;
5652
protected:
57-
/** \brief applies a transformation (if any) to the attribute value of the BB code
58-
* during translation
53+
/** \brief Applies a transformation (if any) to the attribute value of the BB code
54+
* during translation.
5955
*
6056
* \param attr the attribute value
6157
*/
@@ -65,6 +61,6 @@ struct AdvancedTemplateBBCode: public SimpleTemplateBBCode
6561
}
6662
private:
6763
std::string m_AttrName;
68-
};//struct
64+
}; // struct
6965

7066
#endif // ADVANCEDTEMPLATEBBCODE_HPP

code/bbcode/BBCode.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
struct BBCode
2929
{
3030
public:
31-
/** \brief constructor
31+
/** \brief Creates a new BB code.
3232
*
3333
* \param code "name" of the code, i.e. "b" for [B]bold text[/B]
3434
*/
@@ -37,19 +37,18 @@ struct BBCode
3737
{ }
3838

3939

40-
/** destructor */
41-
virtual ~BBCode() {}
40+
virtual ~BBCode() = default;
4241

4342

44-
/** \brief returns the code's "name"
43+
/** \brief Gets the code's "name".
4544
*/
4645
inline const std::string& getName() const
4746
{
4847
return m_Name;
4948
}
5049

51-
/** \brief "applies" the BB code to the given text, i.e. transforms the BB code
52-
* into its HTML representation
50+
/** \brief "Applies" the BB code to the given text, i.e. transforms the BB code
51+
* into its (X)HTML representation.
5352
*
5453
* \param text the message text that (may) contain the BB code
5554
*/
@@ -64,6 +63,6 @@ struct BBCode
6463
#endif
6564
private:
6665
std::string m_Name;
67-
};//struct
66+
}; // struct
6867

6968
#endif // BBCODE_HPP

code/bbcode/CustomizedSimpleBBCode.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ CustomizedSimpleBBCode::CustomizedSimpleBBCode(const std::string& code, const st
2828

2929
void CustomizedSimpleBBCode::applyToText(std::string& text) const
3030
{
31-
const std::string code = "["+getName()+"]";
32-
const std::string end_code = "[/"+getName()+"]";
31+
const std::string code = "[" + getName() + "]";
32+
const std::string end_code = "[/" + getName() + "]";
3333
std::string::size_type pos = find_ci(text, code);
3434
std::string::size_type end_pos = std::string::npos;
35-
while (pos!=std::string::npos)
35+
while (pos != std::string::npos)
3636
{
37-
end_pos = find_ci(text, end_code, pos+1);
38-
if (end_pos==std::string::npos) return;
37+
end_pos = find_ci(text, end_code, pos + 1);
38+
if (end_pos == std::string::npos)
39+
return;
3940
text.replace(end_pos, end_code.length(), m_After);
4041
text.replace(pos, code.length(), m_Before);
4142
pos = find_ci(text, code, pos);
42-
}//while
43+
}
4344
}

code/bbcode/CustomizedSimpleBBCode.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
/** \brief CustomizedSimpleBBCode:
29-
like SimpleBBCode, but with a custom replacement for opening and closing
29+
Like SimpleBBCode, but with a custom replacement for opening and closing
3030
tags.
3131
*/
3232
struct CustomizedSimpleBBCode: public BBCode
@@ -41,18 +41,14 @@ struct CustomizedSimpleBBCode: public BBCode
4141
CustomizedSimpleBBCode(const std::string& code, const std::string& before, const std::string& after);
4242

4343

44-
/** destructor */
45-
virtual ~CustomizedSimpleBBCode() {}
46-
47-
48-
/** \brief "applies" the BB code to the given text, i.e. transforms the BB code
49-
* into its HTML representation
44+
/** \brief "Applies" the BB code to the given text, i.e. transforms the BB code
45+
* into its (X)HTML representation.
5046
*
5147
* \param text the message text that (may) contain the BB code
5248
*/
5349
virtual void applyToText(std::string& text) const;
5450
private:
5551
std::string m_Before, m_After;
56-
};//struct
52+
}; // struct
5753

5854
#endif // CUSTOMIZEDSIMPLEBBCODE_HPP

code/bbcode/HorizontalRuleBBCode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
HorizontalRuleBBCode::HorizontalRuleBBCode(const std::string& code, const HTMLStandard standard)
2525
: BBCode(code), m_standard(standard)
26-
{ }
26+
{
27+
}
2728

2829
void HorizontalRuleBBCode::applyToText(std::string& text) const
2930
{

code/bbcode/ListBBCode.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,22 @@ struct ListBBCode: public BBCode
4141
ListBBCode(const std::string& code, bool unordered=true);
4242

4343

44-
/** destructor */
45-
virtual ~ListBBCode() {}
46-
47-
48-
/** \brief "applies" the BB code to the given text, i.e. transforms the BB code
49-
* into its HTML representation
44+
/** \brief "Applies" the BB code to the given text, i.e. transforms the BB code
45+
* into its (X)HTML representation.
5046
*
5147
* \param text the message text that (may) contain the BB code
5248
*/
5349
virtual void applyToText(std::string& text) const;
5450

5551

56-
/** returns true, if the code creates an unordered list */
52+
/** Returns true, if the code creates an unordered list. */
5753
inline bool createsUnordered() const
5854
{
5955
return m_Unordered;
6056
}
6157
private:
6258
bool actualApply(std::string& text, const std::string::size_type offset) const;
6359
bool m_Unordered;
64-
};//struct
60+
}; // struct
6561

6662
#endif // LISTBBCODE_HPP

code/bbcode/SimpleBBCode.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424
SimpleBBCode::SimpleBBCode(const std::string& code)
2525
: BBCode(toLowerString(code))
2626
{
27-
2827
}
2928

3029
void SimpleBBCode::applyToText(std::string& text) const
3130
{
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() + "]";
3433
std::string::size_type pos = find_ci(text, code);
3534
std::string::size_type end_pos = std::string::npos;
36-
while (pos!=std::string::npos)
35+
while (pos != std::string::npos)
3736
{
38-
end_pos = find_ci(text, end_code, pos+1);
39-
if (end_pos==std::string::npos) return;
40-
text.replace(pos, code.length(), "<"+getName()+">");
41-
text.replace(end_pos, end_code.length(), "</"+getName()+">");
37+
end_pos = find_ci(text, end_code, pos + 1);
38+
if (end_pos == std::string::npos)
39+
return;
40+
text.replace(pos, code.length(), "<" + getName() + ">");
41+
text.replace(end_pos, end_code.length(), "</" + getName() + ">");
4242
pos = find_ci(text, code, pos);
43-
}//while
43+
}
4444
}

code/bbcode/SimpleBBCode.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727

2828
/* struct SimpleBBCode:
29-
handles "simple" BB codes, where the square brackets can be transformed
29+
Handles "simple" BB codes, where the square brackets can be transformed
3030
to < or > to produce the proper HTML code, e.g. where
31-
"[TAG]content[/TAG]" becomes "<tag>content</tag>"
31+
"[TAG]content[/TAG]" becomes "<tag>content</tag>".
3232
*/
3333
struct SimpleBBCode: public BBCode
3434
{
@@ -39,15 +39,13 @@ struct SimpleBBCode: public BBCode
3939
*/
4040
SimpleBBCode(const std::string& code);
4141

42-
/** destructor */
43-
virtual ~SimpleBBCode() {}
4442

45-
/** \brief "applies" the BB code to the given text, i.e. transforms the BB code
46-
* into its HTML representation
43+
/** \brief "Applies" the BB code to the given text, i.e. transforms the BB code
44+
* into its (X)HTML representation.
4745
*
4846
* \param text - the message text that (may) contain the BB code
4947
*/
5048
virtual void applyToText(std::string& text) const;
51-
};//struct SimpleBBCode
49+
}; // struct
5250

5351
#endif // SIMPLEBBCODE_HPP

0 commit comments

Comments
 (0)