1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:38:10 +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

@ -6,32 +6,32 @@
class GTextPosition {
public:
GTextPosition() {}
GTextPosition(int line, int column)
GTextPosition(size_t line, size_t column)
: m_line(line)
, m_column(column)
{
}
bool is_valid() const { return m_line >= 0 && m_column >= 0; }
bool is_valid() const { return m_line != 0xffffffffu && m_column != 0xffffffffu; }
int line() const { return m_line; }
int column() const { return m_column; }
size_t line() const { return m_line; }
size_t column() const { return m_column; }
void set_line(int line) { m_line = line; }
void set_column(int column) { m_column = column; }
void set_line(size_t line) { m_line = line; }
void set_column(size_t column) { m_column = column; }
bool operator==(const GTextPosition& other) const { return m_line == other.m_line && m_column == other.m_column; }
bool operator!=(const GTextPosition& other) const { return m_line != other.m_line || m_column != other.m_column; }
bool operator<(const GTextPosition& other) const { return m_line < other.m_line || (m_line == other.m_line && m_column < other.m_column); }
private:
int m_line { -1 };
int m_column { -1 };
size_t m_line { 0xffffffff };
size_t m_column { 0xffffffff };
};
inline const LogStream& operator<<(const LogStream& stream, const GTextPosition& value)
{
if (!value.is_valid())
return stream << "GTextPosition(Invalid)";
return stream << String::format("(%d,%d)", value.line(), value.column());
return stream << String::format("(%zu,%zu)", value.line(), value.column());
}