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

Add subpath #202

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions JShim/Sun/NIO/FS/WindowsPath.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

using System;
using System.Collections.Generic;
using System.Text;

using Java.NIO.File;

namespace Sun.NIO.FS
Expand All @@ -11,6 +13,11 @@ namespace Sun.NIO.FS
public class WindowsPath : Path
{
public const string DefaultRoot = @"C:\";
public static readonly char[] Separators =
{
System.IO.Path.DirectorySeparatorChar,
System.IO.Path.AltDirectorySeparatorChar
};

// The maximum path that does not require long path prefix. On Windows
// the maximum path is 260 minus 1 (NUL) but for directories it is 260
Expand Down Expand Up @@ -212,17 +219,25 @@ public bool StartsWith(string other)

public Path SubPath(int beginIndex, int endIndex)
{
throw new NotImplementedException();
string[] subpaths = this.path.Split(Separators);
StringBuilder sb = new StringBuilder();
for(int i = beginIndex; i < endIndex; i++)
{
sb.Append(System.IO.Path.DirectorySeparatorChar);
sb.Append(subpaths[i]);
}
string path = sb.ToString();
return new WindowsPath(fs, type, root, path);
}

public Path ToAbsolutePath()
{
{
string root = !string.IsNullOrEmpty(this.root)?
this.root :
DefaultRoot;

string path = this.path.StartsWith(root)?
this.path.Replace(root, string.Empty) :
string path = this.path.StartsWith(root)?
this.path.Replace(root, string.Empty) :
this.path;

return new WindowsPath(fs, WindowsPathType.Absolute, root, path);
Expand Down