Some improvements to clean_file_name() and clean_file_path() functions.
This commit is contained in:
parent
b1c2ecee3f
commit
4f114738e2
@ -442,30 +442,39 @@ CLEAN_FILE_NAME[] =
|
|||||||
|
|
||||||
QString MUtils::clean_file_name(const QString &name)
|
QString MUtils::clean_file_name(const QString &name)
|
||||||
{
|
{
|
||||||
QString str = name.simplified();
|
QRegExp regExp("\"(.+)\"");
|
||||||
|
regExp.setMinimal(true);
|
||||||
|
|
||||||
|
QString str = QString(name).replace(regExp, "``\\1´´").trimmed();
|
||||||
for(size_t i = 0; CLEAN_FILE_NAME[i].search; i++)
|
for(size_t i = 0; CLEAN_FILE_NAME[i].search; i++)
|
||||||
{
|
{
|
||||||
str.replace(CLEAN_FILE_NAME[i].search, CLEAN_FILE_NAME[i].replace);
|
str.replace(CLEAN_FILE_NAME[i].search, CLEAN_FILE_NAME[i].replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegExp regExp("\"(.+)\"");
|
while(str.endsWith(QLatin1Char('.')))
|
||||||
regExp.setMinimal(true);
|
{
|
||||||
str.replace(regExp, "`\\1´");
|
str.chop(1);
|
||||||
|
str = str.trimmed();
|
||||||
return str.simplified();
|
}
|
||||||
|
|
||||||
|
return str.trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MUtils::clean_file_path(const QString &path)
|
QString MUtils::clean_file_path(const QString &path)
|
||||||
{
|
{
|
||||||
QStringList parts = path.simplified().replace("\\", "/").split("/", QString::SkipEmptyParts);
|
const bool root = path.startsWith(QLatin1Char('/')) || path.startsWith(QLatin1Char('\\'));
|
||||||
|
QStringList parts = QDir::fromNativeSeparators(path.trimmed()).split(QLatin1Char('/'), QString::SkipEmptyParts);
|
||||||
|
|
||||||
for(int i = 0; i < parts.count(); i++)
|
for(int i = 0; i < parts.count(); i++)
|
||||||
{
|
{
|
||||||
|
if((i == 0) && (!root) && (parts[i].length() == 2) && parts[i][0].isLetter() && (parts[i][1] == QLatin1Char(':')))
|
||||||
|
{
|
||||||
|
continue; //handle case "c:\"
|
||||||
|
}
|
||||||
parts[i] = MUtils::clean_file_name(parts[i]);
|
parts[i] = MUtils::clean_file_name(parts[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts.join("/");
|
return root ? parts.join(QLatin1String("/")).prepend(QLatin1Char('/')) : parts.join(QLatin1String("/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user