Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hashtag

jsugai
September 15, 2017

 Hashtag

jsugai

September 15, 2017
Tweet

More Decks by jsugai

Other Decks in Programming

Transcript

  1. 1. int String#indexOf(String str, int fromIndex)Ͱ #ͷҐஔΛαʔν 2. int String#indexOf(String

    str, int fromIndex)Ͱ ' 'ͷҐஔΛαʔν 3. 2ͭͷ۠ؒΛ SpannableString ʹஔ͖׵͑ͯΫϦοΫ࣌ͷॲཧΛॻ͘ 4. 1~3 Λจࣈྻͷऴ୺·Ͱߦ͍ͬͯ͘ 5. CPU ύϫʔͰ! #ॲཧͷྲྀΕβ
  2. #Spec -1 •ʮ൒֯εϖʔε + # ʯͷ૊Έ߹Θ͔ͤΒελʔτͯ͠ (൒ ֯εϖʔεʣ·ͰΛ1୯ޠͱ͢Δ
 ʢશ֯εϖʔε͸ಛʹݴٴ͞Ε͍ͯͳ͍ͷͰΫϥΠΞϯ τଆͰͷ൑அʣ

    •ߦ಄͕ # Ͱ࢝·Δ৔߹͸൒֯εϖʔεͳ͠Ͱ΋Մ •ߦ຤ʹ౸ୡͨ͠৔߹͸? (࢓༷͕෼͔ΕΔ) • # ͔Βߦ຤·ͰΛ1୯ޠͱ͢Δ • ࣍ߦΛαʔνͯ͠ߦ຤/จ຤΋͘͠͸ऴ୺จࣈ͕ొ৔ ͢Δ·ͰંΓฦ͠ΛؚΊͯ1ͭͷHashtagͱͯ͠ѻ͏
  3. #Other • Instagram •ʮɺʯʮɻʯ΍ׅހ͸શ֯จࣈ΋ Hashtag ʹ͸࢖͑ͳ͍ •શ֯εϖʔε͸ NG •Emoji OK

    (ex: # •ݕࡧ࣌ͷશ֯ͱ൒֯ͷΞϧϑΝϕοτͷڍಈ͕Ṗ •͍͍ͩͨ൒֯Ͱॻ͍ͱ͖Ό͍͍ • Twitter •શ֯εϖʔε͸ NG •શ֯ɾ൒֯ΞϧϑΝϕοτͳͲ͸ݕࡧ࣌ʹ۠ผ͞Εͳ͍ •ʢ͔ͨ͠...ʣEmoji NG ίί஫ҙ
  4. #ࡶֶ •൒֯ͷϋογϡϚʔΫ # ͚͕ͩ Hashtag ͷઌ಄จࣈͱ͠ ͯ༗ޮɻΩʔϘʔυͰ Shift + 3

    Λԡ͢ͱೖྗͰ͖Δɻ •ྨࣅ඼ʹ͸͝஫ҙ!
 ʮ̅ʢγϟʔϓʣʯʮˌʢҪܻʣʯʮ#ʢҪܻʣʯ •Hashtag पΓΛݕࡧͯ͠Δͱߴ֬཰Ͱ #HashMap ΍ #HashTable ͕Ͱͯ͘Δ
  5. #࣮૷ • Pattern Ͱ Hashtag ͷύλʔϯΛੜ੒͢Δ
 > Pattern.compile("(#[a-zA-Z0-9_-]+)"); • #Hashtag

    Λද͍ࣔͨ͠ TextView Λ༻ҙ͢Δ • #Hashtag ΛؚΉจࣈྻΛ SpannableStringBuilder ʹηοτ
 > SpannableStringBuilder string = new SpannableStringBuilder(nTagString); • ޙ͸͍ͭ΋ͷྲྀΕͰ...
  6. Matcher m = hashTagsPattern.matcher(nTagString);
 
 while (m.find()) {
 
 start

    = m.start();
 end = m.end();
 
 spanText = nTagString.subSequence(start, end);
 final CharSequence mLastTextSpan = spanText;
 
 string.setSpan(new ClickableSpan() {
 @Override
 public void onClick(View widget) {
 
 // Click on each tag will get here
 }
 
 @Override
 public void updateDrawState(TextPaint ds) {
 // color for the hash tag
 }
 }, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 } return string; // Spannable String
 \͍ͭ΋ͷྲྀΕͰ͓ئ͍͠·͢/
  7. #໰୊఺ •ॲཧ͕࣌ؒ௕͍ɻ1000จࣈͱ͔౉ͨ͠Β0.5secͱ͔΋ɻ •ϝϯςφϯε͕ਓؒ཭Εͯ͘͠Δ • μʔΫαΠυʹམͪͨਓؒͷ Hashtag ͸ϠόΠ͕ରԠ͕Μ͹Δ
 ex: #༒࣫ࠇͷତఱ࢖༒ ,

    #ΞΨϯμϜ, #ݪਓ⺏ • ѹ౗త Unicode ͷ֦ுύϫʔ
 - Unicode9 ΍ 10 Ͱ֦ு͞Εͨ Emoji ͱ͔Ͳʔ͢Δ?!
 ※ Android N ͸ 9 ·ͰରԠͰ 10 ͷ Emoji ൑ఆ͕.. \͍ͭ΋ͷྲྀΕͰ͓ئ͍͠·͢/ \͍ͭ΋ͷྲྀΕͰ͓ئ͍͠·͢/ \͍ͭ΋ͷྲྀΕͰ͓ئ͍͠·͢/
  8. // Generated from unicode_regex/unicode_regex_groups.scala, more inclusive than Ruby's pLpM HASHTAG_LETTERS_AND_MARKS

    = "\\p{L}\\p{M}" +\u037f\u0528-\u052f\u08a0-\u08b2\u08e4- \u08ff\u0978\u0980\u0c00\u0c34\u0c81\u0d01\u0ede\u0edf\u10c7\u10cd\u10fd-\u10ff\u16f1- \u16f8\u17b4\u17b5\u191d\u191e\u1ab0-\u1abe\u1bab-\u1bad\u1bba-\u1bbf\u1cf3-\u1cf6\u1cf8\u1cf9\u1de7- \u1df5\u2cf2\u2cf3\u2d27\u2d2d\u2d66\u2d67\u9fcc\ua674-\ua67b\ua698-\ua69d\ua69f\ua792-\ua79f\ua7aa- \ua7ad\ua7b0\ua7b1\ua7f7-\ua7f9\ua9e0-\ua9ef\ua9fa-\ua9fe\uaa7c-\uaa7f\uaae0-\uaaef\uaaf2-\uaaf6\uab30- \uab5a\uab5c-\uab5f\uab64\uab65\uf870-\uf87f\uf882\uf884-\uf89f\uf8b8\uf8c1-\uf8d6\ufa2e\ufa2f\ufe27- \ufe2d\u{102e0}\u{1031f}\u{10350}-\u{1037a}\u{10500}-\u{10527}\u{10530}-\u{10563}\u{10600}-\u{10736}\u{10740}- \u{10755}\u{10760}-\u{10767}\u{10860}-\u{10876}\u{10880}-\u{1089e}\u{10980}-\u{109b7}\u{109be}\u{109bf}\u{10a80}-\u{10a9c} \u{10ac0}-\u{10ac7}\u{10ac9}-\u{10ae6}\u{10b80}-\u{10b91}\u{1107f}\u{110d0}-\u{110e8}\u{11100}-\u{11134}\u{11150}- \u{11173}\u{11176}\u{11180}-\u{111c4}\u{111da}\u{11200}-\u{11211}\u{11213}-\u{11237}\u{112b0}-\u{112ea}\u{11301}- \u{11303}\u{11305}-\u{1130c}\u{1130f}\u{11310}\u{11313}-\u{11328}\u{1132a}-\u{11330}\u{11332}\u{11333}\u{11335}- \u{11339}\u{1133c}-\u{11344}\u{11347}\u{11348}\u{1134b}-\u{1134d}\u{11357}\u{1135d}-\u{11363}\u{11366}-\u{1136c}\u{11370}- \u{11374}\u{11480}-\u{114c5}\u{114c7}\u{11580}-\u{115b5}\u{115b8}-\u{115c0}\u{11600}-\u{11640}\u{11644}\u{11680}- \u{116b7}\u{118a0}-\u{118df}\u{118ff}\u{11ac0}-\u{11af8}\u{1236f}-\u{12398}\u{16a40}-\u{16a5e}\u{16ad0}-\u{16aed}\u{16af0}- \u{16af4}\u{16b00}-\u{16b36}\u{16b40}-\u{16b43}\u{16b63}-\u{16b77}\u{16b7d}-\u{16b8f}\u{16f00}-\u{16f44}\u{16f50}-\u{16f7e} \u{16f8f}-\u{16f9f}\u{1bc00}-\u{1bc6a}\u{1bc70}-\u{1bc7c}\u{1bc80}-\u{1bc88}\u{1bc90}-\u{1bc99}\u{1bc9d}\u{1bc9e}\u{1e800}- \u{1e8c4}\u{1e8d0}-\u{1e8d6}\u{1ee00}-\u{1ee03}\u{1ee05}-\u{1ee1f}\u{1ee21}\u{1ee22}\u{1ee24}\u{1ee27}\u{1ee29}- \u{1ee32}\u{1ee34}-\u{1ee37}\u{1ee39}\u{1ee3b}\u{1ee42}\u{1ee47}\u{1ee49}\u{1ee4b}\u{1ee4d}-\u{1ee4f} \u{1ee51}\u{1ee52}\u{1ee54}\u{1ee57}\u{1ee59}\u{1ee5b}\u{1ee5d}\u{1ee5f}"\u{1ee61}\u{1ee62}\u{1ee64}\u{1ee67}-\u{1ee6a} \u{1ee6c}-\u{1ee72}\u{1ee74}-\u{1ee77}\u{1ee79}-\u{1ee7c}\u{1ee7e}\u{1ee80}-\u{1ee89}\u{1ee8b}-\u{1ee9b}\u{1eea1}- \u{1eea3}\u{1eea5}-\u{1eea9}\u{1eeab}-\u{1eebb}" ... http://www.rubydoc.info/gems/twitter-text/Twitter/Regex
  9. INVALID_CHARS = // CJK-JP character "\\u3003" + // U+3003 `ʏ`

    DITTO MARK ; // υΠπޠΒ͍͠ ... // CJK-Tibetan "\\u0f0b" + // U+0F0B `་` TIBETAN MARK INTERSYLLABIC TSHEG "\\u0f0c" + // U+0F0C `༌` TIBETAN MARK DELIMITER TSHEG BSTAR // ͱԿ͕ҧ͏ͷ? ... "\\u0f12" + // U+0F12 `༒` TIBETAN MARK rgya gram shad // Կ͔ͩΘ͔Βͳ͍͕ΧοίΠΠ଄ܗ
 ... // White Spaces // ൒֯εϖʔε܉ஂ .... "\\u2003" + // U+2003 EM space "\\u2004" + // U+2004 THREE PER EM space 
 "\\u2005" + // U+2005 FOUR PER EM space
 "\\u2006" + // U+2006 Six per space "\\u2007" + // U+2007 figure space
 "\\u200A" + // U+200A HAIR space
 "\\u202F" + // U+202F NARROW NO-BREAK SPACE
 "\\u205F" + // U+205F medium mathematical space .... http://www.rubydoc.info/gems/twitter-text/Twitter/Regex