開発に使用するリポジトリ
Revisión | 56c9541eb4e443073be3df0963f7aaaaedb65044 (tree) |
---|---|
Tiempo | 2018-10-14 00:48:00 |
Autor | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
絵文字に関する文字数カウントの新仕様に対応
@@ -629,6 +629,26 @@ namespace OpenTween | ||
629 | 629 | } |
630 | 630 | |
631 | 631 | [Fact] |
632 | + public void GetTextLengthRemain_EmojiTest() | |
633 | + { | |
634 | + using (var twitter = new Twitter()) | |
635 | + { | |
636 | + // 絵文字の文字数カウントの仕様変更に対するテストケース | |
637 | + // https://twittercommunity.com/t/114607 | |
638 | + | |
639 | + Assert.Equal(279, twitter.GetTextLengthRemain("©")); // 基本多言語面の絵文字 | |
640 | + Assert.Equal(277, twitter.GetTextLengthRemain("©\uFE0E")); // 異字体セレクタ付き (text style) | |
641 | + Assert.Equal(279, twitter.GetTextLengthRemain("©\uFE0F")); // 異字体セレクタ付き (emoji style) | |
642 | + Assert.Equal(278, twitter.GetTextLengthRemain("🍣")); // 拡張面の絵文字 | |
643 | + Assert.Equal(279, twitter.GetTextLengthRemain("#⃣")); // 合字で表現される絵文字 | |
644 | + Assert.Equal(278, twitter.GetTextLengthRemain("👦\U0001F3FF")); // Emoji modifier 付きの絵文字 | |
645 | + Assert.Equal(278, twitter.GetTextLengthRemain("\U0001F3FF")); // Emoji modifier 単体 | |
646 | + Assert.Equal(278, twitter.GetTextLengthRemain("👨\u200D🎨")); // ZWJ で結合された絵文字 | |
647 | + Assert.Equal(278, twitter.GetTextLengthRemain("🏃\u200D♀\uFE0F")); // ZWJ と異字体セレクタを含む絵文字 | |
648 | + } | |
649 | + } | |
650 | + | |
651 | + [Fact] | |
632 | 652 | public void GetTextLengthRemain_BrokenSurrogateTest() |
633 | 653 | { |
634 | 654 | using (var twitter = new Twitter()) |
@@ -38,6 +38,9 @@ namespace OpenTween.Api.DataModel | ||
38 | 38 | [DataMember(Name = "defaultWeight")] |
39 | 39 | public int DefaultWeight { get; set; } |
40 | 40 | |
41 | + [DataMember(Name = "emojiParsingEnabled")] | |
42 | + public bool EmojiParsingEnabled { get; set; } | |
43 | + | |
41 | 44 | [DataMember(Name = "transformedURLLength")] |
42 | 45 | public int TransformedURLLength { get; set; } |
43 | 46 |
@@ -65,13 +68,14 @@ namespace OpenTween.Api.DataModel | ||
65 | 68 | |
66 | 69 | public static TwitterTextConfiguration DefaultConfiguration() |
67 | 70 | { |
68 | - // 参照: https://github.com/twitter/twitter-text/blob/v2.0.5/config/v2.json | |
71 | + // 参照: https://github.com/twitter/twitter-text/blob/v3.0.0/config/v3.json | |
69 | 72 | return new TwitterTextConfiguration |
70 | 73 | { |
71 | - Version = 2, | |
74 | + Version = 3, | |
72 | 75 | MaxWeightedTweetLength = 280, |
73 | 76 | Scale = 100, |
74 | 77 | DefaultWeight = 200, |
78 | + EmojiParsingEnabled = true, | |
75 | 79 | TransformedURLLength = 23, |
76 | 80 | Ranges = new[] |
77 | 81 | { |
@@ -1,6 +1,8 @@ | ||
1 | 1 | 更新履歴 |
2 | 2 | |
3 | 3 | ==== Ver 2.1.3-dev(2018/xx/xx) |
4 | + * NEW: 絵文字に関する文字数カウントの新仕様に対応しました | |
5 | + - この変更により「👩👧👦」「👨🎨」など複数の文字で構成される絵文字を入力した場合の文字数制限が緩和されます | |
4 | 6 | * FIX: ユーザー情報ダイアログでbioに絵文字を含む場合にハッシュタグやメンションのリンク範囲がずれる不具合を修正 |
5 | 7 | |
6 | 8 | ==== Ver 2.1.2(2018/09/30) |
@@ -1812,7 +1812,21 @@ namespace OpenTween | ||
1812 | 1812 | var config = this.TextConfiguration; |
1813 | 1813 | var totalWeight = 0; |
1814 | 1814 | |
1815 | + int GetWeightFromCodepoint(int codepoint) | |
1816 | + { | |
1817 | + foreach (var weightRange in config.Ranges) | |
1818 | + { | |
1819 | + if (codepoint >= weightRange.Start && codepoint <= weightRange.End) | |
1820 | + return weightRange.Weight; | |
1821 | + } | |
1822 | + | |
1823 | + return config.DefaultWeight; | |
1824 | + } | |
1825 | + | |
1815 | 1826 | var urls = TweetExtractor.ExtractUrlEntities(postText).ToArray(); |
1827 | + var emojis = config.EmojiParsingEnabled | |
1828 | + ? TweetExtractor.ExtractEmojiEntities(postText).ToArray() | |
1829 | + : Array.Empty<TwitterEntityEmoji>(); | |
1816 | 1830 | |
1817 | 1831 | var codepoints = postText.ToCodepoints().ToArray(); |
1818 | 1832 | var index = 0; |
@@ -1826,19 +1840,17 @@ namespace OpenTween | ||
1826 | 1840 | continue; |
1827 | 1841 | } |
1828 | 1842 | |
1829 | - var codepoint = codepoints[index]; | |
1830 | - var weight = config.DefaultWeight; | |
1831 | - | |
1832 | - foreach (var weightRange in config.Ranges) | |
1843 | + var emojiEntity = emojis.FirstOrDefault(x => x.Indices[0] == index); | |
1844 | + if (emojiEntity != null) | |
1833 | 1845 | { |
1834 | - if (codepoint >= weightRange.Start && codepoint <= weightRange.End) | |
1835 | - { | |
1836 | - weight = weightRange.Weight; | |
1837 | - break; | |
1838 | - } | |
1846 | + totalWeight += GetWeightFromCodepoint(codepoints[index]); | |
1847 | + index = emojiEntity.Indices[1]; | |
1848 | + continue; | |
1839 | 1849 | } |
1840 | 1850 | |
1841 | - totalWeight += weight; | |
1851 | + var codepoint = codepoints[index]; | |
1852 | + totalWeight += GetWeightFromCodepoint(codepoint); | |
1853 | + | |
1842 | 1854 | index++; |
1843 | 1855 | } |
1844 | 1856 |