Rename "fromNativePath" to "toUniformPath"

Unlike "toNativePath" which name clearly reflects the function result
"fromNativePath" has no such clear meaning.
Since this function converts path into uniform format "toUniformPath"
is better name.
This commit is contained in:
Vladimir Golovnev (Glassez)
2019-06-16 20:14:15 +03:00
parent 206bb018dd
commit 8e65317d61
17 changed files with 54 additions and 47 deletions

View File

@@ -60,17 +60,12 @@
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
/**
* Converts a path to a string suitable for display.
* This function makes sure the directory separator used is consistent
* with the OS being run.
*/
QString Utils::Fs::toNativePath(const QString &path)
{
return QDir::toNativeSeparators(path);
}
QString Utils::Fs::fromNativePath(const QString &path)
QString Utils::Fs::toUniformPath(const QString &path)
{
return QDir::fromNativeSeparators(path);
}
@@ -87,7 +82,7 @@ QString Utils::Fs::fileExtension(const QString &filename)
QString Utils::Fs::fileName(const QString &filePath)
{
const QString path = fromNativePath(filePath);
const QString path = toUniformPath(filePath);
const int slashIndex = path.lastIndexOf('/');
if (slashIndex == -1)
return path;
@@ -96,7 +91,7 @@ QString Utils::Fs::fileName(const QString &filePath)
QString Utils::Fs::folderName(const QString &filePath)
{
const QString path = fromNativePath(filePath);
const QString path = toUniformPath(filePath);
const int slashIndex = path.lastIndexOf('/');
if (slashIndex == -1)
return path;
@@ -248,7 +243,7 @@ qint64 Utils::Fs::freeDiskSpaceOnPath(const QString &path)
QString Utils::Fs::branchPath(const QString &filePath, QString *removed)
{
QString ret = fromNativePath(filePath);
QString ret = toUniformPath(filePath);
if (ret.endsWith('/'))
ret.chop(1);
const int slashIndex = ret.lastIndexOf('/');

View File

@@ -39,8 +39,20 @@ namespace Utils
{
namespace Fs
{
/**
* Converts a path to a string suitable for display.
* This function makes sure the directory separator used is consistent
* with the OS being run.
*/
QString toNativePath(const QString &path);
QString fromNativePath(const QString &path);
/**
* Converts a path to a string suitable for processing.
* This function makes sure the directory separator used is independent
* from the OS being run so it is the same on all supported platforms.
* Slash ('/') is used as "uniform" directory separator.
*/
QString toUniformPath(const QString &path);
QString fileExtension(const QString &filename);
QString fileName(const QString &filePath);
QString folderName(const QString &filePath);