Skip to content

Commit

Permalink
linvi#430 Fixed a small issue and now the tests are now correctly run…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
linvi committed Oct 4, 2017
1 parent bb3cf2c commit 3389a1c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Testinvi/Tweetinvi.Core/UnicodeHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void UnicodeSubstring()
var substr = UnicodeHelper.UnicodeSubstring(str, 141);

// Assert
Assert.AreEqual(substr, " https://t.co/oUeMIkyb5G");
Assert.AreEqual(substr, "https://t.co/oUeMIkyb5G");
}
}
}
2 changes: 1 addition & 1 deletion Testinvi/Tweetinvi.Logic/ExtendedTweetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void UnicodeExtendedTweetSuffix()
{
ITweet tweet = InitTweet(EXTENDED_TWEET_WITH_UNICODE, TweetMode.Extended);

Assert.AreEqual(tweet.Suffix, " https://t.co/oUeMIkyb5G");
Assert.AreEqual(tweet.Suffix, "https://t.co/oUeMIkyb5G");
}


Expand Down
30 changes: 29 additions & 1 deletion Tweetinvi.Core/Core/Helpers/UnicodeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Globalization;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Text;

namespace Tweetinvi.Core.Core.Helpers
Expand All @@ -14,12 +16,38 @@ public static string UnicodeSubstring(string str, int startIndex)

var sbuilder = new StringBuilder();

Func<string, int, bool> shouldCountTwice = (string str2, int i2) =>
{
if (char.IsSurrogatePair(str2, i2))
{
var grapheme = $"{str2[i2]}{str2[i2 + 1]}";

Console.WriteLine($"{grapheme} = {(int)str[i2]}/{(int)str[i2 + 1]}");

UnicodeCategory characterChategory = CharUnicodeInfo.GetUnicodeCategory(grapheme, 0);

return characterChategory == UnicodeCategory.ModifierSymbol;
}

return false;
};

var i = 0;
for (; i < startIndex; ++i)
{
if (char.IsSurrogatePair(str, i))
{
++i;
++startIndex;

var grapheme = $"{str[i]}{str[i + 1]}";

UnicodeCategory characterChategory = CharUnicodeInfo.GetUnicodeCategory(grapheme, 0);

if (characterChategory == UnicodeCategory.ModifierSymbol)
{
++startIndex;
}
}
}

Expand Down

0 comments on commit 3389a1c

Please sign in to comment.