Skip to content

Commit

Permalink
Removed the function GetExtensionFromPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Dec 19, 2024
1 parent a7e5f05 commit 27b3948
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ - (IBAction)OnSearch:(id) [[maybe_unused]] _sender

- (VFSHostPtr)spawnArchiveFromPath:(const char *)_path inVFS:(const VFSHostPtr &)_host
{
char extension[MAXPATHLEN];
if( !GetExtensionFromPath(_path, extension) )
const std::string_view extension = nc::utility::PathManip::Extension(_path);
if( extension.empty() )
return nullptr;

if( !nc::panel::IsExtensionInArchivesWhitelist(extension) )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) 2013-2019 Michael Kazakov. Subject to GNU General Public License version 3.
// Copyright (C) 2013-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#include <VFS/VFS.h>
#include <Operations/CopyingOptions.h>
#include <string_view>

@class PanelController;
class ExternalEditorStartupInfo;
Expand Down Expand Up @@ -45,7 +46,7 @@ class FileOpener
bool IsEligbleToTryToExecuteInConsole(const VFSListingItem &_item);
nc::ops::CopyingOptions MakeDefaultFileCopyOptions();
nc::ops::CopyingOptions MakeDefaultFileMoveOptions();
bool IsExtensionInArchivesWhitelist(const char *_ext) noexcept;
bool IsExtensionInArchivesWhitelist(std::string_view _ext) noexcept;
bool ShowQuickLookAsFloatingPanel() noexcept;

} // namespace nc::panel
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ bool IsEligbleToTryToExecuteInConsole(const VFSListingItem &_item)
return options;
}

bool IsExtensionInArchivesWhitelist(const char *_ext) noexcept
bool IsExtensionInArchivesWhitelist(std::string_view _ext) noexcept
{
if( !_ext )
if( _ext.empty() )
return false;
[[clang::no_destroy]] static const utility::ExtensionsLowercaseList archive_extensions(
GlobalConfig().GetString(g_ConfigArchivesExtensionsWhiteList));
Expand Down
6 changes: 0 additions & 6 deletions Source/Utility/include/Utility/PathManip.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ bool GetFilenameFromRelPath(const char *_path, char *_buf);
*/
bool GetDirectoryContainingItemFromRelPath(const char *_path, char *_buf);

/**
* GetExtensionFromPath works with absolute paths and will not work with some relative paths like
* "filename.txt". It will not extract extensions from filenames like ".filename" or "filename."
*/
bool GetExtensionFromPath(const char *_path, char *_buf);

// prefer PathManip::EnsureTrailingSlash() instead, semantically equal
inline std::string EnsureTrailingSlash(std::string _s)
{
Expand Down
16 changes: 0 additions & 16 deletions Source/Utility/source/PathManip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ bool GetDirectoryContainingItemFromRelPath(const char *_path, char *_buf)
return true;
}

bool GetExtensionFromPath(const char *_path, char *_buf)
{
const char *last_sl = strrchr(_path, '/');
const char *last_dot = strrchr(_path, '.');
if( !last_sl || !last_dot )
return false;
if( last_dot == last_sl + 1 )
return false;
if( last_dot == _path + strlen(_path) - 1 )
return false;
if( last_dot < last_sl )
return false;
strcpy(_buf, last_dot + 1);
return true;
}

bool GetDirectoryNameFromPath(const char *_path, char *_dir_out, [[maybe_unused]] size_t _dir_size)
{
const char *second_sep = strrchr(_path, '/');
Expand Down

0 comments on commit 27b3948

Please sign in to comment.