1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

StringView: Rename characters() to characters_without_null_termination().

This should make you think twice before trying to use the const char* from
a StringView as if it's a null-terminated string.
This commit is contained in:
Andreas Kling 2019-07-08 15:38:44 +02:00
parent 567551bc12
commit 0e75aba7c3
21 changed files with 57 additions and 46 deletions

View file

@ -571,7 +571,7 @@ void Painter::draw_text(const Rect& rect, const StringView& text, const Font& fo
int new_width = font.width("...");
if (new_width < text_width) {
for (int i = 0; i < final_text.length(); ++i) {
int glyph_width = font.glyph_width(final_text.characters()[i]);
int glyph_width = font.glyph_width(final_text.characters_without_null_termination()[i]);
// NOTE: Glyph spacing should not be added after the last glyph on the line,
// but since we are here because the last glyph does not actually fit on the line,
// we don't have to worry about spacing.
@ -582,7 +582,7 @@ void Painter::draw_text(const Rect& rect, const StringView& text, const Font& fo
new_width += glyph_width + glyph_spacing;
}
StringBuilder builder;
builder.append(StringView(final_text.characters(), new_length));
builder.append(StringView(final_text.characters_without_null_termination(), new_length));
builder.append("...");
elided_text = builder.to_string();
final_text = elided_text;
@ -609,7 +609,7 @@ void Painter::draw_text(const Rect& rect, const StringView& text, const Font& fo
int space_width = font.glyph_width(' ') + font.glyph_spacing();
for (ssize_t i = 0; i < final_text.length(); ++i) {
char ch = final_text.characters()[i];
char ch = final_text.characters_without_null_termination()[i];
if (ch == ' ') {
point.move_by(space_width, 0);
continue;