You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
@@ -38,9 +38,11 @@ VARIANT_ENUM_CAST(XMLParser::NodeType);
|
||||
|
||||
static bool _equalsn(const CharType *str1, const CharType *str2, int len) {
|
||||
int i;
|
||||
for (i = 0; i < len && str1[i] && str2[i]; ++i)
|
||||
if (str1[i] != str2[i])
|
||||
for (i = 0; i < len && str1[i] && str2[i]; ++i) {
|
||||
if (str1[i] != str2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// if one (or both) of the strings was smaller then they
|
||||
// are only equal if they have the same length
|
||||
@@ -51,8 +53,9 @@ String XMLParser::_replace_special_characters(const String &origstr) {
|
||||
int pos = origstr.find("&");
|
||||
int oldPos = 0;
|
||||
|
||||
if (pos == -1)
|
||||
if (pos == -1) {
|
||||
return origstr;
|
||||
}
|
||||
|
||||
String newstr;
|
||||
|
||||
@@ -83,8 +86,9 @@ String XMLParser::_replace_special_characters(const String &origstr) {
|
||||
pos = origstr.find("&", pos);
|
||||
}
|
||||
|
||||
if (oldPos < origstr.length() - 1)
|
||||
if (oldPos < origstr.length() - 1) {
|
||||
newstr += (origstr.substr(oldPos, origstr.length() - oldPos));
|
||||
}
|
||||
|
||||
return newstr;
|
||||
}
|
||||
@@ -99,12 +103,15 @@ bool XMLParser::_set_text(char *start, char *end) {
|
||||
// only white space, so that this text won't be reported
|
||||
if (end - start < 3) {
|
||||
char *p = start;
|
||||
for (; p != end; ++p)
|
||||
if (!_is_white_space(*p))
|
||||
for (; p != end; ++p) {
|
||||
if (!_is_white_space(*p)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (p == end)
|
||||
if (p == end) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// set current text to the parsed text, and replace xml special characters
|
||||
@@ -125,8 +132,9 @@ void XMLParser::_parse_closing_xml_element() {
|
||||
++P;
|
||||
const char *pBeginClose = P;
|
||||
|
||||
while (*P != '>')
|
||||
while (*P != '>') {
|
||||
++P;
|
||||
}
|
||||
|
||||
node_name = String::utf8(pBeginClose, (int)(P - pBeginClose));
|
||||
#ifdef DEBUG_XML
|
||||
@@ -140,15 +148,17 @@ void XMLParser::_ignore_definition() {
|
||||
|
||||
char *F = P;
|
||||
// move until end marked with '>' reached
|
||||
while (*P != '>')
|
||||
while (*P != '>') {
|
||||
++P;
|
||||
}
|
||||
node_name.parse_utf8(F, P - F);
|
||||
++P;
|
||||
}
|
||||
|
||||
bool XMLParser::_parse_cdata() {
|
||||
if (*(P + 1) != '[')
|
||||
if (*(P + 1) != '[') {
|
||||
return false;
|
||||
}
|
||||
|
||||
node_type = NODE_CDATA;
|
||||
|
||||
@@ -159,8 +169,9 @@ bool XMLParser::_parse_cdata() {
|
||||
++count;
|
||||
}
|
||||
|
||||
if (!*P)
|
||||
if (!*P) {
|
||||
return true;
|
||||
}
|
||||
|
||||
char *cDataBegin = P;
|
||||
char *cDataEnd = nullptr;
|
||||
@@ -176,10 +187,11 @@ bool XMLParser::_parse_cdata() {
|
||||
++P;
|
||||
}
|
||||
|
||||
if (cDataEnd)
|
||||
if (cDataEnd) {
|
||||
node_name = String::utf8(cDataBegin, (int)(cDataEnd - cDataBegin));
|
||||
else
|
||||
} else {
|
||||
node_name = "";
|
||||
}
|
||||
#ifdef DEBUG_XML
|
||||
print_line("XML CDATA: " + node_name);
|
||||
#endif
|
||||
@@ -197,10 +209,11 @@ void XMLParser::_parse_comment() {
|
||||
|
||||
// move until end of comment reached
|
||||
while (count) {
|
||||
if (*P == '>')
|
||||
if (*P == '>') {
|
||||
--count;
|
||||
else if (*P == '<')
|
||||
} else if (*P == '<') {
|
||||
++count;
|
||||
}
|
||||
|
||||
++P;
|
||||
}
|
||||
@@ -222,46 +235,52 @@ void XMLParser::_parse_opening_xml_element() {
|
||||
const char *startName = P;
|
||||
|
||||
// find end of element
|
||||
while (*P != '>' && !_is_white_space(*P))
|
||||
while (*P != '>' && !_is_white_space(*P)) {
|
||||
++P;
|
||||
}
|
||||
|
||||
const char *endName = P;
|
||||
|
||||
// find attributes
|
||||
while (*P != '>') {
|
||||
if (_is_white_space(*P))
|
||||
if (_is_white_space(*P)) {
|
||||
++P;
|
||||
else {
|
||||
} else {
|
||||
if (*P != '/') {
|
||||
// we've got an attribute
|
||||
|
||||
// read the attribute names
|
||||
const char *attributeNameBegin = P;
|
||||
|
||||
while (!_is_white_space(*P) && *P != '=')
|
||||
while (!_is_white_space(*P) && *P != '=') {
|
||||
++P;
|
||||
}
|
||||
|
||||
const char *attributeNameEnd = P;
|
||||
++P;
|
||||
|
||||
// read the attribute value
|
||||
// check for quotes and single quotes, thx to murphy
|
||||
while ((*P != '\"') && (*P != '\'') && *P)
|
||||
while ((*P != '\"') && (*P != '\'') && *P) {
|
||||
++P;
|
||||
}
|
||||
|
||||
if (!*P) // malformatted xml file
|
||||
if (!*P) { // malformatted xml file
|
||||
return;
|
||||
}
|
||||
|
||||
const char attributeQuoteChar = *P;
|
||||
|
||||
++P;
|
||||
const char *attributeValueBegin = P;
|
||||
|
||||
while (*P != attributeQuoteChar && *P)
|
||||
while (*P != attributeQuoteChar && *P) {
|
||||
++P;
|
||||
}
|
||||
|
||||
if (!*P) // malformatted xml file
|
||||
if (!*P) { // malformatted xml file
|
||||
return;
|
||||
}
|
||||
|
||||
const char *attributeValueEnd = P;
|
||||
++P;
|
||||
@@ -304,16 +323,19 @@ void XMLParser::_parse_current_node() {
|
||||
node_offset = P - data;
|
||||
|
||||
// more forward until '<' found
|
||||
while (*P != '<' && *P)
|
||||
while (*P != '<' && *P) {
|
||||
++P;
|
||||
}
|
||||
|
||||
if (!*P)
|
||||
if (!*P) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (P - start > 0) {
|
||||
// we found some text, store it
|
||||
if (_set_text(start, P))
|
||||
if (_set_text(start, P)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
++P;
|
||||
@@ -327,8 +349,9 @@ void XMLParser::_parse_current_node() {
|
||||
_ignore_definition();
|
||||
break;
|
||||
case '!':
|
||||
if (!_parse_cdata())
|
||||
if (!_parse_cdata()) {
|
||||
_parse_comment();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_parse_opening_xml_element();
|
||||
@@ -417,8 +440,9 @@ String XMLParser::get_attribute_value(int p_idx) const {
|
||||
|
||||
bool XMLParser::has_attribute(const String &p_name) const {
|
||||
for (int i = 0; i < attributes.size(); i++) {
|
||||
if (attributes[i].name == p_name)
|
||||
if (attributes[i].name == p_name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -447,8 +471,9 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const {
|
||||
}
|
||||
}
|
||||
|
||||
if (idx < 0)
|
||||
if (idx < 0) {
|
||||
return "";
|
||||
}
|
||||
return attributes[idx].value;
|
||||
}
|
||||
|
||||
@@ -496,8 +521,9 @@ Error XMLParser::open(const String &p_path) {
|
||||
|
||||
void XMLParser::skip_section() {
|
||||
// skip if this element is empty anyway.
|
||||
if (is_empty())
|
||||
if (is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// read until we've reached the last element in this section
|
||||
int tagcount = 1;
|
||||
@@ -506,14 +532,16 @@ void XMLParser::skip_section() {
|
||||
if (get_node_type() == XMLParser::NODE_ELEMENT &&
|
||||
!is_empty()) {
|
||||
++tagcount;
|
||||
} else if (get_node_type() == XMLParser::NODE_ELEMENT_END)
|
||||
} else if (get_node_type() == XMLParser::NODE_ELEMENT_END) {
|
||||
--tagcount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XMLParser::close() {
|
||||
if (data)
|
||||
if (data) {
|
||||
memdelete_arr(data);
|
||||
}
|
||||
data = nullptr;
|
||||
length = 0;
|
||||
P = nullptr;
|
||||
@@ -535,6 +563,7 @@ XMLParser::XMLParser() {
|
||||
}
|
||||
|
||||
XMLParser::~XMLParser() {
|
||||
if (data)
|
||||
if (data) {
|
||||
memdelete_arr(data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user