As per Vas Crabb, readding overloads that take a std::string& parameter for the result

This commit is contained in:
Nathan Woods 2016-07-04 23:22:37 -04:00
parent 0d4151e366
commit bdf2059bf4
4 changed files with 48 additions and 8 deletions

View File

@ -156,7 +156,7 @@ void device_image_interface::device_compute_hash(hash_collection &hashes, const
image_error_t device_image_interface::set_image_filename(const char *filename)
{
m_image_name = filename;
m_working_directory = util::zippath_parent(filename);
util::zippath_parent(m_working_directory, filename);
m_basename.assign(m_image_name);
int loc1 = m_image_name.find_last_of('\\');

View File

@ -61,7 +61,7 @@ menu_control_device_image::menu_control_device_image(mame_ui_manager &mui, rende
if (image->exists())
{
m_current_file.assign(image->filename());
m_current_directory = util::zippath_parent(m_current_file.c_str());
util::zippath_parent(m_current_directory, m_current_file.c_str());
} else
m_current_directory.assign(image->working_directory());

View File

@ -140,12 +140,11 @@ static void parse_parent_path(const char *path, int *beginpos, int *endpos)
// zippath_parent - retrieves the parent directory
// -------------------------------------------------
std::string zippath_parent(const char *path)
std::string &zippath_parent(std::string &dst, const char *path)
{
int pos;
parse_parent_path(path, &pos, nullptr);
std::string dst;
if (pos >= 0)
dst.assign(path, pos + 1);
else
@ -155,6 +154,19 @@ std::string zippath_parent(const char *path)
// -------------------------------------------------
// zippath_parent - retrieves the parent directory
// -------------------------------------------------
std::string zippath_parent(const char *path)
{
std::string result;
zippath_parent(result, path);
return result;
}
// -------------------------------------------------
// zippath_parent_basename - retrieves the parent
// directory basename
@ -171,9 +183,8 @@ std::string zippath_parent(const char *path)
* @return A std::string&
*/
std::string zippath_parent_basename(const char *path)
std::string &zippath_parent_basename(std::string &dst, const char *path)
{
std::string dst;
int beginpos, endpos;
parse_parent_path(path, &beginpos, &endpos);
dst.copy((char*)(path + beginpos + 1), endpos - beginpos);
@ -182,6 +193,20 @@ std::string zippath_parent_basename(const char *path)
// -------------------------------------------------
// zippath_parent_basename - retrieves the parent
// directory basename
// -------------------------------------------------
std::string zippath_parent_basename(const char *path)
{
std::string result;
zippath_parent_basename(result, path);
return result;
}
// -------------------------------------------------
// zippath_combine - combines two paths
// -------------------------------------------------
@ -198,9 +223,8 @@ std::string zippath_parent_basename(const char *path)
* @return A std::string&
*/
std::string zippath_combine(const char *path1, const char *path2)
std::string &zippath_combine(std::string &dst, const char *path1, const char *path2)
{
std::string dst;
if (!strcmp(path2, "."))
{
dst.assign(path1);
@ -226,6 +250,19 @@ std::string zippath_combine(const char *path1, const char *path2)
// -------------------------------------------------
// zippath_combine - combines two paths
// -------------------------------------------------
std::string zippath_combine(const char *path1, const char *path2)
{
std::string result;
zippath_combine(result, path1, path2);
return result;
}
/***************************************************************************
FILE OPERATIONS
***************************************************************************/

View File

@ -34,12 +34,15 @@ class zippath_directory;
// ----- path operations -----
// retrieves the parent directory
std::string &zippath_parent(std::string &dst, const char *path);
std::string zippath_parent(const char *path);
// retrieves the parent directory basename
std::string &zippath_parent_basename(std::string &dst, const char *path);
std::string zippath_parent_basename(const char *path);
// combines two paths
std::string &zippath_combine(std::string &dst, const char *path1, const char *path2);
std::string zippath_combine(const char *path1, const char *path2);