Skip to content

Commit

Permalink
Added Reverse function
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Mar 4, 2023
1 parent 150fca4 commit 19e1633
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T

## [Unreleased]

### Added
- Added `Reverse` function

## [1.12.2] - 2023-02-21

### Changed
Expand Down
5 changes: 5 additions & 0 deletions src/LinkDotNet.StringBuilder/ValueStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ public readonly void Dispose()
}
}

/// <summary>
/// Reverses the sequence of elements in this instance.
/// </summary>
public readonly void Reverse() => buffer[..bufferPosition].Reverse();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Grow(int capacity = 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,14 @@ public void ConcatShouldHandleNullValues()

ValueStringBuilder.Concat(array!).Should().Be(string.Empty);
}

[Fact]
public void ShouldReverseString()
{
using var builder = new ValueStringBuilder("Hello");

builder.Reverse();

builder.ToString().Should().Be("olleH");
}
}

0 comments on commit 19e1633

Please sign in to comment.