Commit 7daf1c58 authored by Daniel Teske's avatar Daniel Teske Committed by hjk
Browse files

Introduce Utils::FileName class



Change-Id: I1a0573ad8fcf2efc945ea74d9f9851ea7762a210
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 0697fc5e
......@@ -407,4 +407,95 @@ TempFileSaver::~TempFileSaver()
QFile::remove(m_fileName);
}
#ifdef Q_OS_WIN
Qt::CaseSensitivity FileName::cs = Qt::CaseInsensitive;
#else
Qt::CaseSensitivity FileName::cs = Qt::CaseSensitive;
#endif
FileName::FileName()
: QString()
{
}
FileName::FileName(const QFileInfo &info)
: QString(info.absoluteFilePath())
{
}
QString FileName::toString() const
{
return QString(*this);
}
FileName FileName::fromString(const QString &filename)
{
return FileName(filename);
}
FileName::FileName(const QString &string)
: QString(string)
{
}
bool FileName::operator==(const FileName &other) const
{
return QString::compare(*this, other, cs) == 0;
}
bool FileName::operator<(const FileName &other) const
{
return QString::compare(*this, other, cs) < 0;
}
bool FileName::operator<=(const FileName &other) const
{
return QString::compare(*this, other, cs) <= 0;
}
bool FileName::operator>(const FileName &other) const
{
return other < *this;
}
bool FileName::operator>=(const FileName &other) const
{
return other <= *this;
}
bool FileName::startsWith(const QString &s) const
{
return QString::startsWith(s, cs);
}
bool FileName::endsWith(const QString &s) const
{
return QString::endsWith(s, cs);
}
FileName FileName::left(int n) const
{
return FileName(QString::left(n));
}
FileName FileName::mid(int position, int n) const
{
return FileName(QString::mid(position, n));
}
FileName FileName::right(int n) const
{
return FileName(QString::right(n));
}
} // namespace Utils
uint qHash(const Utils::FileName &a)
{
#ifdef Q_OS_WIN
return qHash(a.toString().toUpper());
#else
return qHash(a.toString());
#endif
}
......@@ -38,6 +38,7 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QIODevice>
#include <QtCore/QXmlStreamWriter> // Mac.
#include <QtCore/QFileInfo>
QT_BEGIN_NAMESPACE
class QFile;
......@@ -139,6 +140,38 @@ private:
bool m_autoRemove;
};
class QTCREATOR_UTILS_EXPORT FileName : private QString
{
public:
FileName();
explicit FileName(const QFileInfo &info);
QString toString() const;
static FileName fromString(const QString &filename);
bool operator==(const FileName &other) const;
bool operator<(const FileName &other) const;
bool operator<=(const FileName &other) const;
bool operator>(const FileName &other) const;
bool operator>=(const FileName &other) const;
bool startsWith(const QString &s) const;
bool endsWith(const QString &s) const;
FileName left(int n) const Q_REQUIRED_RESULT;
FileName mid(int position, int n = -1) const Q_REQUIRED_RESULT;
FileName right(int n) const Q_REQUIRED_RESULT;
using QString::size;
using QString::count;
using QString::length;
using QString::isEmpty;
private:
static Qt::CaseSensitivity cs;
FileName(const QString &string);
};
} // namespace Utils
QTCREATOR_UTILS_EXPORT uint qHash(const Utils::FileName &a);
#endif // FILEUTILS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment