Skip to content

Commit 3839884

Browse files
authored
Merge pull request #6 from rameel/stringview-enhancement
StringView enhancement
2 parents 986fbae + 1d48242 commit 3839884

4 files changed

Lines changed: 373 additions & 17 deletions

File tree

Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
4+
</PropertyGroup>
5+
</Project>

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Ramstack.Structures is a .NET library providing various data structures and utilities.
44

5+
[![.NET](https://github.com/rameel/ramstack.structures/actions/workflows/test.yml/badge.svg)](https://github.com/rameel/ramstack.structures/actions/workflows/test.yml)
6+
57
## Installation
68

79
To install the `Ramstack.Structures` [NuGet package](https://www.nuget.org/packages/Ramstack.Structures) to your project, use the following command:
@@ -43,6 +45,16 @@ foreach (ref readonly HeavyStruct s in view)
4345
...
4446
}
4547
```
48+
## Changelog
49+
50+
### 1.2.0
51+
- Add `Trim` overloads to `StringView` class
52+
53+
## Supported versions
54+
55+
| | Version |
56+
|------|---------|
57+
| .NET | 6, 7, 8 |
4658

4759
## Contributions
4860

Ramstack.Structures.Tests/Text/StringViewTests.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@ public void TrimStart(string value, int index, int length)
6060
Is.EqualTo(value.AsSpan(index, length).TrimStart().ToString()));
6161
}
6262

63+
[TestCase("", '-')]
64+
[TestCase("--------", '-')]
65+
[TestCase("--++value", '-')]
66+
[TestCase("--++value", '+')]
67+
[TestCase(" value", '-')]
68+
[TestCase(" value", ' ')]
69+
[TestCase("value", '-')]
70+
public void TrimStart_TrimChar(string value, char trimChar)
71+
{
72+
Assert.That(
73+
value.AsView().TrimStart(trimChar).ToString(),
74+
Is.EqualTo(value.TrimStart(trimChar)));
75+
}
76+
77+
[TestCase("", "-+")]
78+
[TestCase("--++--++-", "-+")]
79+
[TestCase("--++value", "-+")]
80+
[TestCase("--++value", "?=")]
81+
[TestCase(" value", "-+")]
82+
[TestCase(" value", "-+")]
83+
[TestCase(" value", "")]
84+
[TestCase(" value", null)]
85+
[TestCase("value", "+-")]
86+
[TestCase("value", null)]
87+
public void TrimStart_TrimChars(string value, string? trimChars)
88+
{
89+
Assert.That(
90+
value.AsView().TrimStart(trimChars?.ToCharArray()).ToString(),
91+
Is.EqualTo(value.TrimStart(trimChars?.ToCharArray())));
92+
93+
Assert.That(
94+
value.AsView().TrimStart(trimChars.AsSpan()).ToString(),
95+
Is.EqualTo(value.TrimStart(trimChars?.ToCharArray())));
96+
}
97+
6398
[TestCase("", 0, 0)]
6499
[TestCase(" ", 0, 4)]
65100
[TestCase(" ", 1, 3)]
@@ -76,6 +111,42 @@ public void TrimEnd(string value, int index, int length)
76111
Is.EqualTo(value.AsSpan(index, length).TrimEnd().ToString()));
77112
}
78113

114+
[TestCase("", '-')]
115+
[TestCase("---------", '-')]
116+
[TestCase("value--++", '-')]
117+
[TestCase("value--++", '-')]
118+
[TestCase("value--++", '+')]
119+
[TestCase("value ", '-')]
120+
[TestCase("value ", ' ')]
121+
[TestCase("value", '-')]
122+
public void TrimEnd_TrimChar(string value, char trimChar)
123+
{
124+
Assert.That(
125+
value.AsView().TrimEnd(trimChar).ToString(),
126+
Is.EqualTo(value.TrimEnd(trimChar)));
127+
}
128+
129+
[TestCase("", "-+")]
130+
[TestCase("++--++--+", "-+")]
131+
[TestCase("value++--", "-+")]
132+
[TestCase("value++--", "?=")]
133+
[TestCase("value ", "-+")]
134+
[TestCase("value ", "-+")]
135+
[TestCase("value ", "")]
136+
[TestCase("value ", null)]
137+
[TestCase("value", "+-")]
138+
[TestCase("value", null)]
139+
public void TrimEnd_TrimChars(string value, string? trimChars)
140+
{
141+
Assert.That(
142+
value.AsView().TrimEnd(trimChars?.ToCharArray()).ToString(),
143+
Is.EqualTo(value.TrimEnd(trimChars?.ToCharArray())));
144+
145+
Assert.That(
146+
value.AsView().TrimEnd(trimChars.AsSpan()).ToString(),
147+
Is.EqualTo(value.TrimEnd(trimChars?.ToCharArray())));
148+
}
149+
79150
[TestCase("", 0, 0)]
80151
[TestCase(" ", 0, 4)]
81152
[TestCase(" ", 1, 3)]
@@ -96,6 +167,42 @@ public void Trim(string value, int index, int length)
96167
Is.EqualTo(value.AsSpan(index, length).Trim().ToString()));
97168
}
98169

170+
[TestCase("", '-')]
171+
[TestCase("---------", '-')]
172+
[TestCase("++--value--++", '-')]
173+
[TestCase("++--value--++", '-')]
174+
[TestCase("++--value--++", '+')]
175+
[TestCase(" value ", '-')]
176+
[TestCase(" value ", ' ')]
177+
[TestCase("value", '-')]
178+
public void Trim_TrimChar(string value, char trimChar)
179+
{
180+
Assert.That(
181+
value.AsView().Trim(trimChar).ToString(),
182+
Is.EqualTo(value.Trim(trimChar)));
183+
}
184+
185+
[TestCase("", "-+")]
186+
[TestCase("++--++--+", "-+")]
187+
[TestCase("--++value++--", "-+")]
188+
[TestCase("--++value++--", "?=")]
189+
[TestCase(" value ", "-+")]
190+
[TestCase(" value ", "-+")]
191+
[TestCase(" value ", "")]
192+
[TestCase(" value ", null)]
193+
[TestCase("value", "+-")]
194+
[TestCase("value", null)]
195+
public void Trim_TrimChars(string value, string? trimChars)
196+
{
197+
Assert.That(
198+
value.AsView().Trim(trimChars?.ToCharArray()).ToString(),
199+
Is.EqualTo(value.Trim(trimChars?.ToCharArray())));
200+
201+
Assert.That(
202+
value.AsView().Trim(trimChars.AsSpan()).ToString(),
203+
Is.EqualTo(value.Trim(trimChars?.ToCharArray())));
204+
}
205+
99206
[TestCase("value", 0, 0)]
100207
[TestCase("value", 0, 5)]
101208
[TestCase("value", 1, 4)]

0 commit comments

Comments
 (0)