Skip to content

Commit

Permalink
Return no TextPart if the length is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
azyobuzin committed Apr 2, 2017
1 parent 37ddf33 commit 6a50b30
Show file tree
Hide file tree
Showing 6 changed files with 493 additions and 251 deletions.
12 changes: 10 additions & 2 deletions src/CoreTweetSupplement/CoreTweetSupplement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ private static string ToString(IList<DoubleUtf16Char> source, int start, int cou
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities)
{
if (text == null)
throw new ArgumentNullException(nameof(text));

var chars = GetCodePoints(text);
return EnumerateTextParts(chars, entities, 0, chars.Count);
}
Expand All @@ -153,6 +156,9 @@ public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities ent
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities, int startIndex, int endIndex)
{
if (text == null)
throw new ArgumentNullException(nameof(text));

var chars = GetCodePoints(text);

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

private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> chars, Entities entities, int startIndex, int endIndex)
{
if (startIndex == endIndex) yield break;

if (entities == null)
{
var text = ToString(chars, startIndex, endIndex - startIndex);
Expand All @@ -185,7 +193,7 @@ private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> c
}

var list = new LinkedList<TextPart>(
(entities.HashTags ?? Enumerable.Empty<SymbolEntity>())
(entities.HashTags ?? Enumerable.Empty<HashtagEntity>())
.Select(e => new TextPart()
{
Type = TextPartType.Hashtag,
Expand All @@ -196,7 +204,7 @@ private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> c
Entity = e
})
.Concat(
(entities.Symbols ?? Enumerable.Empty<SymbolEntity>())
(entities.Symbols ?? Enumerable.Empty<CashtagEntity>())
.Select(e => new TextPart()
{
Type = TextPartType.Cashtag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RootNamespace>CoreTweetSupplementTest</RootNamespace>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="testdata\**\*" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CoreTweetSupplement\CoreTweetSupplement.csproj" />
</ItemGroup>
Expand All @@ -15,6 +21,7 @@
</ItemGroup>

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

Expand Down
Loading

0 comments on commit 6a50b30

Please sign in to comment.