Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement path normalization #286

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

Implement path normalization #286

wants to merge 3 commits into from

Conversation

fzhinkin
Copy link
Collaborator

Closes #223

@fzhinkin fzhinkin marked this pull request as ready for review March 19, 2024 10:43
@fzhinkin fzhinkin requested a review from shanshin March 19, 2024 10:43
@fzhinkin fzhinkin linked an issue Mar 19, 2024 that may be closed by this pull request
@@ -174,3 +180,51 @@ private fun removeTrailingSeparatorsWindows(suffixLength: Int, path: String): St
}
return path.substring(0, idx)
}

internal fun Path.normalizedInternal(preserveDrive: Boolean, vararg separators: Char): String {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works incorrectly for UNC paths

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

}
val parts = stringRepresentation.split(*separators)
val constructedPath = mutableListOf<String>()
for (idx in parts.indices) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not for (part in parts)?

append(drive)
var skipFirstSeparator = true
if (isAbs) {
append(SystemPathSeparator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or skipFirstSeparator = false :)

@@ -174,3 +180,51 @@ private fun removeTrailingSeparatorsWindows(suffixLength: Int, path: String): St
}
return path.substring(0, idx)
}

internal fun Path.normalizedInternal(preserveDrive: Boolean, vararg separators: Char): String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

@fzhinkin fzhinkin marked this pull request as draft May 6, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support getting a canonical file Path
2 participants