Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/util/path.cpp
Show All 28 Lines | |||||
29 | 29 | | |||
30 | using namespace KDevelop; | 30 | using namespace KDevelop; | ||
31 | 31 | | |||
32 | namespace { | 32 | namespace { | ||
33 | 33 | | |||
34 | inline bool isWindowsDriveLetter(const QString& segment) | 34 | inline bool isWindowsDriveLetter(const QString& segment) | ||
35 | { | 35 | { | ||
36 | #ifdef Q_OS_WIN | 36 | #ifdef Q_OS_WIN | ||
37 | return segment.size() == 2 && segment.at(0).isLetter() && segment.at(1) == ':'; | 37 | return segment.size() == 2 && segment.at(0).isLetter() && segment.at(1) == QLatin1Char(':'); | ||
38 | #else | 38 | #else | ||
39 | Q_UNUSED(segment); | 39 | Q_UNUSED(segment); | ||
40 | return false; | 40 | return false; | ||
41 | #endif | 41 | #endif | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | inline bool isAbsolutePath(const QString& path) | 44 | inline bool isAbsolutePath(const QString& path) | ||
45 | { | 45 | { | ||
46 | if (path.startsWith('/')) { | 46 | if (path.startsWith(QLatin1Char('/'))) { | ||
47 | return true; // Even on Windows: Potentially a path of a remote URL | 47 | return true; // Even on Windows: Potentially a path of a remote URL | ||
48 | } | 48 | } | ||
49 | 49 | | |||
50 | #ifdef Q_OS_WIN | 50 | #ifdef Q_OS_WIN | ||
51 | return path.size() >= 2 && path.at(0).isLetter() && path.at(1) == ':'; | 51 | return path.size() >= 2 && path.at(0).isLetter() && path.at(1) == QLatin1Char(':'); | ||
52 | #else | 52 | #else | ||
53 | return false; | 53 | return false; | ||
54 | #endif | 54 | #endif | ||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | QString KDevelop::toUrlOrLocalFile(const QUrl& url, QUrl::FormattingOptions options) | 59 | QString KDevelop::toUrlOrLocalFile(const QUrl& url, QUrl::FormattingOptions options) | ||
60 | { | 60 | { | ||
61 | const auto str = url.toString(options | QUrl::PreferLocalFile); | 61 | const auto str = url.toString(options | QUrl::PreferLocalFile); | ||
62 | #ifdef Q_OS_WIN | 62 | #ifdef Q_OS_WIN | ||
63 | // potentially strip leading slash | 63 | // potentially strip leading slash | ||
64 | if (url.isLocalFile() && !str.isEmpty() && str[0] == '/') { | 64 | if (url.isLocalFile() && !str.isEmpty() && str[0] == QLatin1Char('/')) { | ||
65 | return str.mid(1); // expensive copying, but we'd like toString(...) to properly format everything first | 65 | return str.mid(1); // expensive copying, but we'd like toString(...) to properly format everything first | ||
66 | } | 66 | } | ||
67 | #endif | 67 | #endif | ||
68 | return str; | 68 | return str; | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | Path::Path() | 71 | Path::Path() | ||
72 | { | 72 | { | ||
Show All 26 Lines | 82 | { | |||
99 | if (!url.isLocalFile()) { | 99 | if (!url.isLocalFile()) { | ||
100 | // handle remote urls | 100 | // handle remote urls | ||
101 | QString urlPrefix; | 101 | QString urlPrefix; | ||
102 | urlPrefix += url.scheme(); | 102 | urlPrefix += url.scheme(); | ||
103 | urlPrefix += QLatin1String("://"); | 103 | urlPrefix += QLatin1String("://"); | ||
104 | const QString user = url.userName(); | 104 | const QString user = url.userName(); | ||
105 | if (!user.isEmpty()) { | 105 | if (!user.isEmpty()) { | ||
106 | urlPrefix += user; | 106 | urlPrefix += user; | ||
107 | urlPrefix += '@'; | 107 | urlPrefix += QLatin1Char('@'); | ||
108 | } | 108 | } | ||
109 | urlPrefix += url.host(); | 109 | urlPrefix += url.host(); | ||
110 | if (url.port() != -1) { | 110 | if (url.port() != -1) { | ||
111 | urlPrefix += ':' + QString::number(url.port()); | 111 | urlPrefix += QLatin1Char(':') + QString::number(url.port()); | ||
112 | } | 112 | } | ||
113 | m_data << urlPrefix; | 113 | m_data << urlPrefix; | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | addPath(url.isLocalFile() ? url.toLocalFile() : url.path()); | 116 | addPath(url.isLocalFile() ? url.toLocalFile() : url.path()); | ||
117 | 117 | | |||
118 | // support for root paths, they are valid but don't really contain any data | 118 | // support for root paths, they are valid but don't really contain any data | ||
119 | if (m_data.isEmpty() || (isRemote() && m_data.size() == 1)) { | 119 | if (m_data.isEmpty() || (isRemote() && m_data.size() == 1)) { | ||
Show All 37 Lines | 139 | { | |||
157 | } | 157 | } | ||
158 | 158 | | |||
159 | // build string representation | 159 | // build string representation | ||
160 | QString res; | 160 | QString res; | ||
161 | res.reserve(totalLength); | 161 | res.reserve(totalLength); | ||
162 | 162 | | |||
163 | #ifdef Q_OS_WIN | 163 | #ifdef Q_OS_WIN | ||
164 | if (start == 0 && isLocalFile) { | 164 | if (start == 0 && isLocalFile) { | ||
165 | Q_ASSERT(data.at(0).endsWith(':')); // assume something along "C:" | 165 | Q_ASSERT(data.at(0).endsWith(QLatin1Char(':'))); // assume something along "C:" | ||
166 | res += data.at(0); | 166 | res += data.at(0); | ||
167 | start++; | 167 | start++; | ||
168 | } | 168 | } | ||
169 | #endif | 169 | #endif | ||
170 | 170 | | |||
171 | for (int i = start; i < size; ++i) { | 171 | for (int i = start; i < size; ++i) { | ||
172 | if (i || isLocalFile) { | 172 | if (i || isLocalFile) { | ||
173 | res += '/'; | 173 | res += QLatin1Char('/'); | ||
174 | } | 174 | } | ||
175 | 175 | | |||
176 | res += data.at(i); | 176 | res += data.at(i); | ||
177 | } | 177 | } | ||
178 | 178 | | |||
179 | return res; | 179 | return res; | ||
180 | } | 180 | } | ||
181 | 181 | | |||
▲ Show 20 Lines • Show All 332 Lines • Show Last 20 Lines |