1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +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

@ -33,7 +33,7 @@ String MDCodeBlock::render_to_html() const
builder.appendf("<code style=\"white-space: pre;\" class=\"%s\">", style_language.characters());
// TODO: This should also be done in other places.
for (int i = 0; i < m_code.length(); i++)
for (size_t i = 0; i < m_code.length(); i++)
if (m_code[i] == '<')
builder.append("&lt;");
else if (m_code[i] == '>')

View file

@ -38,14 +38,14 @@ bool MDHeading::parse(Vector<StringView>::ConstIterator& lines)
const StringView& line = *lines;
for (m_level = 0; m_level < line.length(); m_level++)
if (line[m_level] != '#')
for (m_level = 0; m_level < (int)line.length(); m_level++)
if (line[(size_t)m_level] != '#')
break;
if (m_level >= line.length() || line[m_level] != ' ')
if (m_level >= (int)line.length() || line[(size_t)m_level] != ' ')
return false;
StringView title_view = line.substring_view(m_level + 1, line.length() - m_level - 1);
StringView title_view = line.substring_view((size_t)m_level + 1, line.length() - (size_t)m_level - 1);
bool success = m_text.parse(title_view);
ASSERT(success);

View file

@ -49,7 +49,7 @@ bool MDList::parse(Vector<StringView>::ConstIterator& lines)
break;
bool appears_unordered = false;
int offset = 0;
size_t offset = 0;
if (line.length() > 2)
if (line[1] == ' ' && (line[0] == '*' || line[0] == '-')) {
appears_unordered = true;
@ -57,7 +57,7 @@ bool MDList::parse(Vector<StringView>::ConstIterator& lines)
}
bool appears_ordered = false;
for (int i = 0; i < 10 && i < line.length(); i++) {
for (size_t i = 0; i < 10 && i < line.length(); i++) {
char ch = line[i];
if ('0' <= ch && ch <= '9')
continue;

View file

@ -4,7 +4,7 @@
static String unescape(const StringView& text)
{
StringBuilder builder;
for (int i = 0; i < text.length(); ++i) {
for (size_t i = 0; i < text.length(); ++i) {
if (text[i] == '\\' && i != text.length() - 1) {
builder.append(text[i + 1]);
i++;
@ -125,10 +125,10 @@ String MDText::render_for_terminal() const
bool MDText::parse(const StringView& str)
{
Style current_style;
int current_span_start = 0;
size_t current_span_start = 0;
int first_span_in_the_current_link = -1;
auto append_span_if_needed = [&](int offset) {
auto append_span_if_needed = [&](size_t offset) {
if (current_span_start != offset) {
Span span {
unescape(str.substring_view(current_span_start, offset - current_span_start)),
@ -138,7 +138,7 @@ bool MDText::parse(const StringView& str)
}
};
for (int offset = 0; offset < str.length(); offset++) {
for (size_t offset = 0; offset < str.length(); offset++) {
char ch = str[offset];
bool is_escape = ch == '\\';
@ -179,7 +179,7 @@ bool MDText::parse(const StringView& str)
offset++;
ASSERT(str[offset] == '(');
offset++;
int start_of_href = offset;
size_t start_of_href = offset;
do
offset++;