1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 22:45:06 +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

@ -68,7 +68,7 @@ void GTextEditor::create_actions()
void GTextEditor::set_text(const StringView& text)
{
if (is_single_line() && text.length() == m_lines[0]->length() && !memcmp(text.characters(), m_lines[0]->characters(), text.length()))
if (is_single_line() && text.length() == m_lines[0]->length() && !memcmp(text.characters_without_null_termination(), m_lines[0]->characters(), text.length()))
return;
m_selection.clear();
@ -783,14 +783,14 @@ void GTextEditor::Line::clear()
void GTextEditor::Line::set_text(const StringView& text)
{
if (text.length() == length() && !memcmp(text.characters(), characters(), length()))
if (text.length() == length() && !memcmp(text.characters_without_null_termination(), characters(), length()))
return;
if (text.is_empty()) {
clear();
return;
}
m_text.resize(text.length() + 1);
memcpy(m_text.data(), text.characters(), text.length() + 1);
memcpy(m_text.data(), text.characters_without_null_termination(), text.length() + 1);
}
int GTextEditor::Line::width(const Font& font) const
@ -844,7 +844,7 @@ void GTextEditor::Line::truncate(int length)
bool GTextEditor::write_to_file(const StringView& path)
{
int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
int fd = open(String(path).characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
perror("open");
return false;