mirror of https://github.com/stella-emu/stella.git
Yet more conversion of 'const char*' to string_view.
This commit is contained in:
parent
1fa2e98988
commit
ff0bbf525f
|
@ -281,11 +281,8 @@ cerr << "\n\n\n";
|
|||
return _realNode ? _realNode->getParent() : nullptr;
|
||||
}
|
||||
|
||||
const char* const start = _path.c_str();
|
||||
const char* const end = lastPathComponent(_path);
|
||||
|
||||
cerr << "new zip: " << string(start, end - start - 1) << "\n\n\n";
|
||||
return make_unique<FSNodeZIP>(string(start, end - start - 1));
|
||||
cerr << "new zip: " << stemPathComponent(_path) << "\n\n\n";
|
||||
return make_unique<FSNodeZIP>(stemPathComponent(_path));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -498,24 +498,31 @@ class AbstractFSNode
|
|||
*/
|
||||
virtual size_t write(const stringstream& buffer) const { return 0; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Returns the last component of a given path.
|
||||
*
|
||||
* @param str String containing the path.
|
||||
* @return Pointer to the first char of the last component inside str.
|
||||
* @param s String containing the path.
|
||||
* @return View of the last component inside s.
|
||||
*/
|
||||
static const char* lastPathComponent(string_view str)
|
||||
static constexpr string_view lastPathComponent(string_view s)
|
||||
{
|
||||
if(str.empty())
|
||||
return "";
|
||||
if(s.empty()) return EmptyString;
|
||||
const auto pos = s.find_last_of("/\\", s.size() - 2);
|
||||
return s.substr(pos + 1);
|
||||
}
|
||||
|
||||
const char* const start = str.data();
|
||||
const char* cur = start + str.size() - 2;
|
||||
|
||||
while (cur >= start && !(*cur == '/' || *cur == '\\'))
|
||||
--cur;
|
||||
|
||||
return cur + 1;
|
||||
/**
|
||||
* Returns the part *before* the last component of a given path.
|
||||
*
|
||||
* @param s String containing the path.
|
||||
* @return View of the preceding (before the last) component inside s.
|
||||
*/
|
||||
static constexpr string_view stemPathComponent(string_view s)
|
||||
{
|
||||
if(s.empty()) return EmptyString;
|
||||
const auto pos = s.find_last_of("/\\", s.size() - 2);
|
||||
return s.substr(0, pos + 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include "LauncherFileListWidget.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
LauncherFileListWidget::LauncherFileListWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int x, int y, int w, int h)
|
||||
LauncherFileListWidget::LauncherFileListWidget(GuiObject* boss,
|
||||
const GUI::Font& font, int x, int y, int w, int h)
|
||||
: FileListWidget(boss, font, x, y, w, h)
|
||||
{
|
||||
// This widget is special, in that it catches signals and redirects them
|
||||
|
|
|
@ -121,10 +121,7 @@ AbstractFSNodePtr FSNodePOSIX::getParent() const
|
|||
if (_path == ROOT_DIR)
|
||||
return nullptr;
|
||||
|
||||
const char* const start = _path.c_str();
|
||||
const char* const end = lastPathComponent(_path);
|
||||
|
||||
return make_unique<FSNodePOSIX>(string(start, static_cast<size_t>(end - start)));
|
||||
return make_unique<FSNodePOSIX>(stemPathComponent(_path));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -102,14 +102,8 @@ AbstractFSNodePtr FSNodeWINDOWS::getParent() const
|
|||
{
|
||||
if (_isPseudoRoot)
|
||||
return nullptr;
|
||||
|
||||
if (_path.size() > 3)
|
||||
{
|
||||
const char* const start = _path.c_str();
|
||||
const char* const end = lastPathComponent(_path);
|
||||
|
||||
return make_unique<FSNodeWINDOWS>(string(start, static_cast<size_t>(end - start)));
|
||||
}
|
||||
else if (_path.size() > 3)
|
||||
return make_unique<FSNodeWINDOWS>(stemPathComponent(_path));
|
||||
else
|
||||
return make_unique<FSNodeWINDOWS>();
|
||||
}
|
||||
|
@ -123,11 +117,11 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const
|
|||
TCHAR drive_buffer[100];
|
||||
GetLogicalDriveStrings(sizeof(drive_buffer) / sizeof(TCHAR), drive_buffer);
|
||||
|
||||
char drive_name[2] = { '\0', '\0' };
|
||||
for (TCHAR *current_drive = drive_buffer; *current_drive;
|
||||
current_drive += _tcslen(current_drive) + 1)
|
||||
{
|
||||
FSNodeWINDOWS entry;
|
||||
char drive_name[2] = { '\0', '\0' };
|
||||
|
||||
drive_name[0] = current_drive[0];
|
||||
entry._displayName = drive_name;
|
||||
|
|
Loading…
Reference in New Issue