Skip to content

Commit

Permalink
simplify IsPrefixOf, fixed inheritdoc and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
sova authored and ForNeVeR committed Jun 20, 2024
1 parent eba7b4e commit f00023e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ Aside from the strict types, the following features are supported for the paths:

(Note how `GetFileNameWithoutExtension()` works nicely together with `GetExtensionWithDot()` to reconstruct the resulting path from their concatenation, however weird the initial name was — no extension, trailing dot, no base name.)

### Unreleased

- `IPath::IsPrefixOf` to check path prefixes.
- `IPath::StartsWith` to check if the current path starts with a specified path.

Documentation
-------------
- [Contributor Guide][docs.contributing]
Expand Down
7 changes: 3 additions & 4 deletions TruePath/AbsolutePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ private AbsolutePath(string value, bool checkAbsoluteness)
/// <inheritdoc cref="IPath.FileName"/>
public string FileName => Underlying.FileName;

/// <inheritdoc cref="IPath.StartsWith"/>
/// <inheritdoc cref="IPath{TPath}.StartsWith(TPath)"/>
public bool StartsWith(AbsolutePath other) => Value.StartsWith(other.Value);

/// <inheritdoc cref="IPath.IsPrefixOf"/>
/// <inheritdoc cref="IPath{TPath}.IsPrefixOf(TPath)"/>
public bool IsPrefixOf(AbsolutePath other)
{
if (!(Value.Length <= other.Value.Length && other.Value.StartsWith(Value))) return false;
return other.Value.Length == Value.Length || other.Value[Value.Length] == Path.DirectorySeparatorChar;
return Value.Length <= other.Value.Length && other.Value.StartsWith(Value);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions TruePath/LocalPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public override int GetHashCode()
return !left.Equals(right);
}

/// <inheritdoc cref="IPath.StartsWith"/>
/// <inheritdoc cref="IPath{TPath}.StartsWith(TPath)"/>
public bool StartsWith(LocalPath other) => Value.StartsWith(other.Value);

/// <inheritdoc cref="IPath.IsPrefixOf"/>
/// <inheritdoc cref="IPath{TPath}.IsPrefixOf(TPath)"/>
public bool IsPrefixOf(LocalPath other)
{
if (!(Value.Length <= other.Value.Length && other.Value.StartsWith(Value))) return false;
Expand Down

0 comments on commit f00023e

Please sign in to comment.