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

AK: Rename FileSystemPath -> LexicalPath

And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
This commit is contained in:
Sergey Bugaev 2020-05-26 14:52:44 +03:00 committed by Andreas Kling
parent f746bbda17
commit 602c3fdb3a
44 changed files with 174 additions and 181 deletions

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <AK/Utf32View.h>
#include <LibCore/DirIterator.h>
@ -43,10 +43,10 @@ static Vector<u32> supported_emoji_codepoints()
Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots);
while (dt.has_next()) {
auto filename = dt.next_path();
auto fspath = FileSystemPath(filename);
if (fspath.extension() != "png")
auto lexical_path = LexicalPath(filename);
if (lexical_path.extension() != "png")
continue;
auto basename = fspath.basename();
auto basename = lexical_path.basename();
if (!basename.starts_with("U+"))
continue;
u32 codepoint = strtoul(basename.characters() + 2, nullptr, 16);

View file

@ -24,8 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/Function.h>
#include <AK/LexicalPath.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@ -142,9 +142,9 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
auto mkdir_action = Action::create("New directory...", Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) {
auto& input_box = add<InputBox>("Enter name:", "New directory");
if (input_box.exec() == InputBox::ExecOK && !input_box.text_value().is_empty()) {
auto new_dir_path = FileSystemPath(String::format("%s/%s",
m_model->root_path().characters(),
input_box.text_value().characters()))
auto new_dir_path = LexicalPath(String::format("%s/%s",
m_model->root_path().characters(),
input_box.text_value().characters()))
.string();
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {
@ -196,7 +196,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
auto& filter_model = (SortingProxyModel&)*m_view->model();
auto local_index = filter_model.map_to_target(index);
const FileSystemModel::Node& node = m_model->node(local_index);
FileSystemPath path { node.full_path(m_model) };
LexicalPath path { node.full_path(m_model) };
clear_preview();
@ -267,7 +267,7 @@ FilePicker::~FilePicker()
{
}
void FilePicker::set_preview(const FileSystemPath& path)
void FilePicker::set_preview(const LexicalPath& path)
{
if (path.has_extension(".png")) {
auto bitmap = Gfx::Bitmap::load_from_file(path.string());
@ -292,7 +292,7 @@ void FilePicker::clear_preview()
void FilePicker::on_file_return()
{
FileSystemPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters()));
LexicalPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters()));
if (FilePicker::file_exists(path.string()) && m_mode == Mode::Save) {
auto result = MessageBox::show("File already exists, overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel);

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/Optional.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/Dialog.h>
@ -45,10 +45,10 @@ public:
virtual ~FilePicker() override;
FileSystemPath selected_file() const { return m_selected_file; }
LexicalPath selected_file() const { return m_selected_file; }
private:
void set_preview(const FileSystemPath&);
void set_preview(const LexicalPath&);
void clear_preview();
void on_file_return();
@ -68,7 +68,7 @@ private:
RefPtr<MultiView> m_view;
NonnullRefPtr<FileSystemModel> m_model;
FileSystemPath m_selected_file;
LexicalPath m_selected_file;
RefPtr<TextBox> m_filename_textbox;
RefPtr<Label> m_preview_image_label;

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/FileSystemModel.h>
@ -162,24 +162,24 @@ String FileSystemModel::Node::full_path(const FileSystemModel& model) const
}
builder.append('/');
builder.append(name);
return canonicalized_path(builder.to_string());
return LexicalPath::canonicalized_path(builder.to_string());
}
ModelIndex FileSystemModel::index(const StringView& path, int column) const
{
FileSystemPath canonical_path(path);
LexicalPath lexical_path(path);
const Node* node = m_root;
if (canonical_path.string() == "/")
if (lexical_path.string() == "/")
return m_root->index(*this, column);
for (size_t i = 0; i < canonical_path.parts().size(); ++i) {
auto& part = canonical_path.parts()[i];
for (size_t i = 0; i < lexical_path.parts().size(); ++i) {
auto& part = lexical_path.parts()[i];
bool found = false;
for (auto& child : node->children) {
if (child.name == part) {
const_cast<Node&>(child).reify_if_needed(*this);
node = &child;
found = true;
if (i == canonical_path.parts().size() - 1)
if (i == lexical_path.parts().size() - 1)
return child.index(*this, column);
break;
}
@ -198,7 +198,7 @@ String FileSystemModel::full_path(const ModelIndex& index) const
}
FileSystemModel::FileSystemModel(const StringView& root_path, Mode mode)
: m_root_path(canonicalized_path(root_path))
: m_root_path(LexicalPath::canonicalized_path(root_path))
, m_mode(mode)
{
m_directory_icon = Icon::default_icon("filetype-folder");
@ -284,7 +284,7 @@ static String permission_string(mode_t mode)
void FileSystemModel::set_root_path(const StringView& root_path)
{
m_root_path = canonicalized_path(root_path);
m_root_path = LexicalPath::canonicalized_path(root_path);
update();
if (m_root->has_error()) {

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>