mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:27:35 +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:
parent
567551bc12
commit
0e75aba7c3
21 changed files with 57 additions and 46 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue