mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 07:38:10 +00:00
Kernel: Add KLexicalPath
This adds KLexicalPath, which are a few static functions which aim to mostly emulate AK::LexicalPath. They are however constrained to work with absolute paths only, containing no '.' or '..' path segments and no consecutive slashes. This way, it is possible to avoid use StringView for the return values and thus avoid allocating new String objects. As explained above, the functions are currently very strict about the allowed input paths. This seems to not be a problem currently. Since the functions VERIFY this, potential bugs caused by this will become immediately obvious.
This commit is contained in:
parent
75ba74a216
commit
87a62f4def
3 changed files with 78 additions and 0 deletions
19
Kernel/KLexicalPath.h
Normal file
19
Kernel/KLexicalPath.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Max Wipfli <max.wipfli@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace Kernel::KLexicalPath {
|
||||
|
||||
bool is_absolute(StringView const&);
|
||||
bool is_canonical(StringView const&);
|
||||
StringView basename(StringView const&);
|
||||
StringView dirname(StringView const&);
|
||||
Vector<StringView> parts(StringView const&);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue