Skip to content

Commit 6a50b30

Browse files
committed
Return no TextPart if the length is zero
1 parent 37ddf33 commit 6a50b30

File tree

6 files changed

+493
-251
lines changed

6 files changed

+493
-251
lines changed

src/CoreTweetSupplement/CoreTweetSupplement.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ private static string ToString(IList<DoubleUtf16Char> source, int start, int cou
139139
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
140140
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities)
141141
{
142+
if (text == null)
143+
throw new ArgumentNullException(nameof(text));
144+
142145
var chars = GetCodePoints(text);
143146
return EnumerateTextParts(chars, entities, 0, chars.Count);
144147
}
@@ -153,6 +156,9 @@ public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities ent
153156
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
154157
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities, int startIndex, int endIndex)
155158
{
159+
if (text == null)
160+
throw new ArgumentNullException(nameof(text));
161+
156162
var chars = GetCodePoints(text);
157163

158164
if (startIndex < 0 || startIndex >= chars.Count)
@@ -166,6 +172,8 @@ public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities ent
166172

167173
private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> chars, Entities entities, int startIndex, int endIndex)
168174
{
175+
if (startIndex == endIndex) yield break;
176+
169177
if (entities == null)
170178
{
171179
var text = ToString(chars, startIndex, endIndex - startIndex);
@@ -185,7 +193,7 @@ private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> c
185193
}
186194

187195
var list = new LinkedList<TextPart>(
188-
(entities.HashTags ?? Enumerable.Empty<SymbolEntity>())
196+
(entities.HashTags ?? Enumerable.Empty<HashtagEntity>())
189197
.Select(e => new TextPart()
190198
{
191199
Type = TextPartType.Hashtag,
@@ -196,7 +204,7 @@ private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> c
196204
Entity = e
197205
})
198206
.Concat(
199-
(entities.Symbols ?? Enumerable.Empty<SymbolEntity>())
207+
(entities.Symbols ?? Enumerable.Empty<CashtagEntity>())
200208
.Select(e => new TextPart()
201209
{
202210
Type = TextPartType.Cashtag,

test/CoreTweetSupplement.Tests/CoreTweetSupplement.Tests.csproj

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

33
<PropertyGroup>
44
<TargetFramework>netcoreapp1.1</TargetFramework>
5+
<RootNamespace>CoreTweetSupplementTest</RootNamespace>
6+
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
57
</PropertyGroup>
68

9+
<ItemGroup>
10+
<EmbeddedResource Include="testdata\**\*" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
11+
</ItemGroup>
12+
713
<ItemGroup>
814
<ProjectReference Include="..\..\src\CoreTweetSupplement\CoreTweetSupplement.csproj" />
915
</ItemGroup>
@@ -15,6 +21,7 @@
1521
</ItemGroup>
1622

1723
<ItemGroup>
24+
<!-- Added by Test Explorer -->
1825
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
1926
</ItemGroup>
2027

0 commit comments

Comments
 (0)