QDir类cleanPath函数用法
通過規則處理讓源路徑成為最短等價路徑
處理規則如下
1.使用單斜線取代多斜線
2.取消每個包含.名稱的路徑
3.取消內部包含..的路徑
4.取消/..根路徑的元素,使用/替換
這個過程是循環執行的,直到路徑符合所有規則
示例
QStringList ls;ls << "a/c" << "a//c" << "a/c/." << "a/c/b/.." << "/../a/c" << "/../a/b/../././/c" << "";for (auto& t : ls){QString k = QDir::cleanPath(t);qDebug() << k << "\r\n";}輸出如下:
?
?而/../a/c其實就是/a/c, Qt官方幫助手冊中提到如下:
Returns path with directory separators normalized (that is, platform-native separators converted to "/") and redundant ones removed, and "."s and ".."s resolved (as far as possible).
Symbolic links are kept. This function does not return the canonical path, but rather the simplest version of the input. For example, "./local" becomes "local", "local/../bin" becomes "bin" and "/local/usr/../bin" becomes "/local/bin".
紅色的表示:在不影響正確的情況,在返回的路徑中,盡量保留? . 和 ..
這也就是輸出/../a/c而不是/a/c的原因。
?
總結
以上是生活随笔為你收集整理的QDir类cleanPath函数用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QFontDatabase: Canno
- 下一篇: 影响计算机性能的关键部位是什么