diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-09 17:45:40 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-09 17:51:21 +0100 |
commit | 6f4c380d95429ef4615f0a9f40d6fec9e1469764 (patch) | |
tree | 545bbb6260bcbf427e48e98fd6bbebb989bf0590 /Libraries/LibMarkdown | |
parent | 1726c17d0d4325f11124e270ae1658110af606d0 (diff) | |
download | serenity-6f4c380d95429ef4615f0a9f40d6fec9e1469764.zip |
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.
Diffstat (limited to 'Libraries/LibMarkdown')
-rw-r--r-- | Libraries/LibMarkdown/MDCodeBlock.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibMarkdown/MDHeading.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibMarkdown/MDList.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibMarkdown/MDText.cpp | 10 |
4 files changed, 12 insertions, 12 deletions
diff --git a/Libraries/LibMarkdown/MDCodeBlock.cpp b/Libraries/LibMarkdown/MDCodeBlock.cpp index 61d518e177..cf5c01fdad 100644 --- a/Libraries/LibMarkdown/MDCodeBlock.cpp +++ b/Libraries/LibMarkdown/MDCodeBlock.cpp @@ -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("<"); else if (m_code[i] == '>') diff --git a/Libraries/LibMarkdown/MDHeading.cpp b/Libraries/LibMarkdown/MDHeading.cpp index 37c15db49b..77e8a70ac6 100644 --- a/Libraries/LibMarkdown/MDHeading.cpp +++ b/Libraries/LibMarkdown/MDHeading.cpp @@ -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); diff --git a/Libraries/LibMarkdown/MDList.cpp b/Libraries/LibMarkdown/MDList.cpp index c6072b98f6..096d8caac5 100644 --- a/Libraries/LibMarkdown/MDList.cpp +++ b/Libraries/LibMarkdown/MDList.cpp @@ -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; diff --git a/Libraries/LibMarkdown/MDText.cpp b/Libraries/LibMarkdown/MDText.cpp index 3912e122b1..795a74da1f 100644 --- a/Libraries/LibMarkdown/MDText.cpp +++ b/Libraries/LibMarkdown/MDText.cpp @@ -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++; |