1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:18:11 +00:00

AK: Use size_t for the length of strings

Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
This commit is contained in:
Andreas Kling 2019-12-09 17:45:40 +01:00
parent 1726c17d0d
commit 6f4c380d95
54 changed files with 387 additions and 377 deletions

View file

@ -100,17 +100,17 @@ static Vector<String> split_on_whitespace(const StringView& string)
return {};
Vector<String> v;
int substart = 0;
for (int i = 0; i < string.length(); ++i) {
size_t substart = 0;
for (size_t i = 0; i < string.length(); ++i) {
char ch = string.characters_without_null_termination()[i];
if (isspace(ch)) {
int sublen = i - substart;
size_t sublen = i - substart;
if (sublen != 0)
v.append(string.substring_view(substart, sublen));
substart = i + 1;
}
}
int taillen = string.length() - substart;
size_t taillen = string.length() - substart;
if (taillen != 0)
v.append(string.substring_view(substart, taillen));
return v;

View file

@ -68,7 +68,7 @@ int DOMTreeModel::column_count(const GModelIndex&) const
static String with_whitespace_collapsed(const StringView& string)
{
StringBuilder builder;
for (int i = 0; i < string.length(); ++i) {
for (size_t i = 0; i < string.length(); ++i) {
if (isspace(string[i])) {
builder.append(' ');
while (i < string.length()) {

View file

@ -20,7 +20,7 @@ LayoutText::~LayoutText()
static bool is_all_whitespace(const String& string)
{
for (int i = 0; i < string.length(); ++i) {
for (size_t i = 0; i < string.length(); ++i) {
if (!isspace(string[i]))
return false;
}

View file

@ -135,15 +135,15 @@ public:
bool next_is(const char* str) const
{
int len = strlen(str);
for (int i = 0; i < len; ++i) {
size_t len = strlen(str);
for (size_t i = 0; i < len; ++i) {
if (peek(i) != str[i])
return false;
}
return true;
}
char peek(int offset = 0) const
char peek(size_t offset = 0) const
{
if ((index + offset) < css.length())
return css[index + offset];
@ -169,7 +169,7 @@ public:
bool consume_whitespace_or_comments()
{
int original_index = index;
size_t original_index = index;
bool in_comment = false;
for (; index < css.length(); ++index) {
char ch = peek();
@ -582,7 +582,7 @@ private:
CurrentRule current_rule;
Vector<char> buffer;
int index = 0;
size_t index = 0;
StringView css;
};

View file

@ -129,8 +129,8 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
}
};
for (int i = 0; i < html.length(); ++i) {
auto peek = [&](int offset) -> char {
for (size_t i = 0; i < html.length(); ++i) {
auto peek = [&](size_t offset) -> char {
if (i + offset >= html.length())
return '\0';
return html[i + offset];
@ -356,7 +356,7 @@ RefPtr<Document> parse_html_document(const StringView& html, const URL& url)
String escape_html_entities(const StringView& html)
{
StringBuilder builder;
for (int i = 0; i < html.length(); ++i) {
for (size_t i = 0; i < html.length(); ++i) {
if (html[i] == '<')
builder.append("&lt;");
else if (html[i] == '>')