1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 20:04:59 +00:00
serenity/Userland/DevTools/HackStudio/CodeDocument.cpp
Max Wipfli fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00

37 lines
756 B
C++

/*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CodeDocument.h"
namespace HackStudio {
NonnullRefPtr<CodeDocument> CodeDocument::create(const String& file_path, Client* client)
{
return adopt_ref(*new CodeDocument(file_path, client));
}
NonnullRefPtr<CodeDocument> CodeDocument::create(Client* client)
{
return adopt_ref(*new CodeDocument(client));
}
CodeDocument::CodeDocument(const String& file_path, Client* client)
: TextDocument(client)
, m_file_path(file_path)
{
m_language = language_from_file_extension(LexicalPath::extension(file_path));
}
CodeDocument::CodeDocument(Client* client)
: TextDocument(client)
{
}
CodeDocument::~CodeDocument()
{
}
}