Use string length() instead of size() as it was intended in HTMLParser, and BBCodeParser.

This commit is contained in:
Relintai 2022-08-20 21:57:50 +02:00
parent 5a5fbc8e4d
commit 62b0d5572e
2 changed files with 37 additions and 37 deletions

View File

@ -277,12 +277,12 @@ void BBCodeParserTag::process() {
return; return;
} }
if (_data.size() < 2) { if (_data.length() < 2) {
return; return;
} }
ERR_FAIL_COND(_data[0] != '['); ERR_FAIL_COND(_data[0] != '[');
ERR_FAIL_COND(_data[_data.size() - 1] != ']'); ERR_FAIL_COND(_data[_data.length() - 1] != ']');
int start_index = 1; int start_index = 1;
if (_data[1] == '/') { if (_data[1] == '/') {
@ -292,17 +292,17 @@ void BBCodeParserTag::process() {
} else { } else {
String tag_text; String tag_text;
if (_data[_data.size() - 2] == '/') { if (_data[_data.length() - 2] == '/') {
// will catch all that looks like <br/> // will catch all that looks like <br/>
// tags that look like <br> will be caught later in a post process, in a way // tags that look like <br> will be caught later in a post process, in a way
// which also tries to catch erroneously not closed tags that supposed to be closed // which also tries to catch erroneously not closed tags that supposed to be closed
_type = BBCodeParserTag::BBCODE_PARSER_TAG_TYPE_SELF_CLOSING_TAG; _type = BBCodeParserTag::BBCODE_PARSER_TAG_TYPE_SELF_CLOSING_TAG;
tag_text = _data.substr(1, _data.size() - 3); tag_text = _data.substr(1, _data.length() - 3);
} else { } else {
_type = BBCodeParserTag::BBCODE_PARSER_TAG_TYPE_OPENING_TAG; _type = BBCodeParserTag::BBCODE_PARSER_TAG_TYPE_OPENING_TAG;
tag_text = _data.substr(1, _data.size() - 2); tag_text = _data.substr(1, _data.length() - 2);
} }
int fspc_index = tag_text.find_char(' '); int fspc_index = tag_text.find_char(' ');
@ -329,12 +329,12 @@ void BBCodeParserTag::process() {
// grab the tag itself // grab the tag itself
_tag = tag_text.substr(0, fspc_index); _tag = tag_text.substr(0, fspc_index);
if (fspc_index + 1 == tag_text.size()) { if (fspc_index + 1 == tag_text.length()) {
// no args, but had a space like <br /> // no args, but had a space like <br />
return; return;
} }
String args = tag_text.substr(fspc_index + 1, tag_text.size() - fspc_index - 1); String args = tag_text.substr(fspc_index + 1, tag_text.length() - fspc_index - 1);
parse_args(args); parse_args(args);
} }
@ -342,7 +342,7 @@ void BBCodeParserTag::process() {
if (tag_end_index == -1) { if (tag_end_index == -1) {
// simple tag // simple tag
_tag = _data.substr(start_index, _data.size() - start_index - 1); _tag = _data.substr(start_index, _data.length() - start_index - 1);
return; return;
} }
} }
@ -351,7 +351,7 @@ void BBCodeParserTag::parse_args(const String &args) {
_attributes.clear(); _attributes.clear();
int i = 0; int i = 0;
while (i < args.size()) { while (i < args.length()) {
if (args[i] == ' ') { if (args[i] == ' ') {
//"trim" //"trim"
++i; ++i;
@ -364,7 +364,7 @@ void BBCodeParserTag::parse_args(const String &args) {
a.instance(); a.instance();
if (equals_index == -1) { if (equals_index == -1) {
a->set_attribute(args.substr(i, args.size() - i)); a->set_attribute(args.substr(i, args.length() - i));
a->set_single(true); a->set_single(true);
_attributes.push_back(a); _attributes.push_back(a);
@ -378,7 +378,7 @@ void BBCodeParserTag::parse_args(const String &args) {
int next_char_index = equals_index + 1; int next_char_index = equals_index + 1;
if (next_char_index >= args.size()) { if (next_char_index >= args.length()) {
// an attribute looks like this "... attrib=" // an attribute looks like this "... attrib="
_attributes.push_back(a); _attributes.push_back(a);
return; return;
@ -388,7 +388,7 @@ void BBCodeParserTag::parse_args(const String &args) {
while (args[next_char_index] == ' ') { while (args[next_char_index] == ' ') {
++next_char_index; ++next_char_index;
if (next_char_index >= args.size()) { if (next_char_index >= args.length()) {
// an attribute looks like this "... attrib= " // an attribute looks like this "... attrib= "
_attributes.push_back(a); _attributes.push_back(a);
return; return;
@ -409,7 +409,7 @@ void BBCodeParserTag::parse_args(const String &args) {
// missing closing ' or " if c is ' or " // missing closing ' or " if c is ' or "
// else missing parameter // else missing parameter
a->set_data(args.substr(next_char_index, args.size() - next_char_index)); a->set_data(args.substr(next_char_index, args.length() - next_char_index));
_attributes.push_back(a); _attributes.push_back(a);
return; return;
} }
@ -571,10 +571,10 @@ void BBCodeParser::parse(const String &data) {
Vector<Ref<BBCodeParserTag>> tags; Vector<Ref<BBCodeParserTag>> tags;
// split into tags // split into tags
for (int i = 0; i < data.size(); ++i) { for (int i = 0; i < data.length(); ++i) {
if (data[i] == '[') { if (data[i] == '[') {
// tag // tag
for (int j = i + 1; j < data.size(); ++j) { for (int j = i + 1; j < data.length(); ++j) {
if (data[j] == ']') { if (data[j] == ']') {
Ref<BBCodeParserTag> t; Ref<BBCodeParserTag> t;
t.instance(); t.instance();
@ -591,7 +591,7 @@ void BBCodeParser::parse(const String &data) {
} else { } else {
// content // content
for (int j = i + 1; j < data.size(); ++j) { for (int j = i + 1; j < data.length(); ++j) {
if (data[j] == '[') { if (data[j] == '[') {
Ref<BBCodeParserTag> t; Ref<BBCodeParserTag> t;
t.instance(); t.instance();

View File

@ -278,12 +278,12 @@ void HTMLParserTag::process() {
return; return;
} }
if (_data.size() < 2) { if (_data.length() < 2) {
return; return;
} }
ERR_FAIL_COND(_data[0] != '<'); ERR_FAIL_COND(_data[0] != '<');
ERR_FAIL_COND(_data[_data.size() - 1] != '>'); ERR_FAIL_COND(_data[_data.length() - 1] != '>');
int start_index = 1; int start_index = 1;
if (_data[1] == '/') { if (_data[1] == '/') {
@ -291,7 +291,7 @@ void HTMLParserTag::process() {
_type = HTMLParserTag::HTML_PARSER_TAG_TYPE_CLOSING_TAG; _type = HTMLParserTag::HTML_PARSER_TAG_TYPE_CLOSING_TAG;
} else if (_data[1] == '!') { } else if (_data[1] == '!') {
if (_data.size() < 8) { if (_data.length() < 8) {
return; return;
} }
@ -306,10 +306,10 @@ void HTMLParserTag::process() {
comment_start_index = 4; comment_start_index = 4;
} }
_tag = _data.substr(comment_start_index, _data.size() - comment_start_index - 3); _tag = _data.substr(comment_start_index, _data.length() - comment_start_index - 3);
} }
if (_data.size() < 11) { if (_data.length() < 11) {
return; return;
} }
@ -322,21 +322,21 @@ void HTMLParserTag::process() {
_type = HTMLParserTag::HTML_PARSER_TAG_TYPE_DOCTYPE; _type = HTMLParserTag::HTML_PARSER_TAG_TYPE_DOCTYPE;
_tag = _data.substr(doctype_start_index + 8, _data.size() - doctype_start_index - 8 - 1); _tag = _data.substr(doctype_start_index + 8, _data.length() - doctype_start_index - 8 - 1);
} else { } else {
String tag_text; String tag_text;
if (_data[_data.size() - 2] == '/') { if (_data[_data.length() - 2] == '/') {
// will catch all that looks like <br/> // will catch all that looks like <br/>
// tags that look like <br> will be caught later in a post process, in a way // tags that look like <br> will be caught later in a post process, in a way
// which also tries to catch erroneously not closed tags that supposed to be closed // which also tries to catch erroneously not closed tags that supposed to be closed
_type = HTMLParserTag::HTML_PARSER_TAG_TYPE_SELF_CLOSING_TAG; _type = HTMLParserTag::HTML_PARSER_TAG_TYPE_SELF_CLOSING_TAG;
tag_text = _data.substr(1, _data.size() - 3); tag_text = _data.substr(1, _data.length() - 3);
} else { } else {
_type = HTMLParserTag::HTML_PARSER_TAG_TYPE_OPENING_TAG; _type = HTMLParserTag::HTML_PARSER_TAG_TYPE_OPENING_TAG;
tag_text = _data.substr(1, _data.size() - 2); tag_text = _data.substr(1, _data.length() - 2);
} }
int fspc_index = tag_text.find_char(' '); int fspc_index = tag_text.find_char(' ');
@ -350,12 +350,12 @@ void HTMLParserTag::process() {
// grab the tag itself // grab the tag itself
_tag = tag_text.substr(0, fspc_index); _tag = tag_text.substr(0, fspc_index);
if (fspc_index + 1 == tag_text.size()) { if (fspc_index + 1 == tag_text.length()) {
// no args, but had a space like <br /> // no args, but had a space like <br />
return; return;
} }
String args = tag_text.substr(fspc_index + 1, tag_text.size() - fspc_index - 1); String args = tag_text.substr(fspc_index + 1, tag_text.length() - fspc_index - 1);
parse_args(args); parse_args(args);
} }
@ -363,7 +363,7 @@ void HTMLParserTag::process() {
if (tag_end_index == -1) { if (tag_end_index == -1) {
// simple tag // simple tag
_tag = _data.substr(start_index, _data.size() - start_index - 1); _tag = _data.substr(start_index, _data.length() - start_index - 1);
return; return;
} }
} }
@ -372,7 +372,7 @@ void HTMLParserTag::parse_args(const String &args) {
_attributes.clear(); _attributes.clear();
int i = 0; int i = 0;
while (i < args.size()) { while (i < args.length()) {
if (args[i] == ' ') { if (args[i] == ' ') {
//"trim" //"trim"
++i; ++i;
@ -385,7 +385,7 @@ void HTMLParserTag::parse_args(const String &args) {
a.instance(); a.instance();
if (equals_index == -1) { if (equals_index == -1) {
a->set_attribute(args.substr(i, args.size() - i)); a->set_attribute(args.substr(i, args.length() - i));
a->set_single(true); a->set_single(true);
_attributes.push_back(a); _attributes.push_back(a);
@ -399,7 +399,7 @@ void HTMLParserTag::parse_args(const String &args) {
int next_char_index = equals_index + 1; int next_char_index = equals_index + 1;
if (next_char_index >= args.size()) { if (next_char_index >= args.length()) {
// an attribute looks like this "... attrib=" // an attribute looks like this "... attrib="
_attributes.push_back(a); _attributes.push_back(a);
return; return;
@ -409,7 +409,7 @@ void HTMLParserTag::parse_args(const String &args) {
while (args[next_char_index] == ' ') { while (args[next_char_index] == ' ') {
++next_char_index; ++next_char_index;
if (next_char_index >= args.size()) { if (next_char_index >= args.length()) {
// an attribute looks like this "... attrib= " // an attribute looks like this "... attrib= "
_attributes.push_back(a); _attributes.push_back(a);
return; return;
@ -430,7 +430,7 @@ void HTMLParserTag::parse_args(const String &args) {
// missing closing ' or " if c is ' or " // missing closing ' or " if c is ' or "
// else missing parameter // else missing parameter
a->set_data(args.substr(next_char_index, args.size() - next_char_index - 1)); a->set_data(args.substr(next_char_index, args.length() - next_char_index - 1));
_attributes.push_back(a); _attributes.push_back(a);
return; return;
} }
@ -625,7 +625,7 @@ void HTMLParser::parse(const String &data) {
int state = STATE_NONE; int state = STATE_NONE;
// split into tags // split into tags
for (int i = 0; i < data.size(); ++i) { for (int i = 0; i < data.length(); ++i) {
if (state == STATE_NONE) { if (state == STATE_NONE) {
if (data[i] == '<') { if (data[i] == '<') {
// tag // tag
@ -636,7 +636,7 @@ void HTMLParser::parse(const String &data) {
// no else, we need to process the tag istelf! // no else, we need to process the tag istelf!
} }
for (int j = i + 1; j < data.size(); ++j) { for (int j = i + 1; j < data.length(); ++j) {
if (data[j] == '>') { if (data[j] == '>') {
Ref<HTMLParserTag> t; Ref<HTMLParserTag> t;
t.instance(); t.instance();
@ -653,7 +653,7 @@ void HTMLParser::parse(const String &data) {
} else { } else {
// content // content
for (int j = i + 1; j < data.size(); ++j) { for (int j = i + 1; j < data.length(); ++j) {
if (data[j] == '<') { if (data[j] == '<') {
Ref<HTMLParserTag> t; Ref<HTMLParserTag> t;
t.instance(); t.instance();
@ -672,7 +672,7 @@ void HTMLParser::parse(const String &data) {
// script tag content // script tag content
bool done = false; bool done = false;
for (int j = i; j < data.size(); ++j) { for (int j = i; j < data.length(); ++j) {
char c = data[j]; char c = data[j];
if (c != '<' && c != '-') { if (c != '<' && c != '-') {