ã¯ããã«
ãã®èšäºã¯ãNTTã³ã ãŠã§ã¢ Advent Calendar 2021 8æ¥ç®ã®èšäºã§ãã
æåã³ãŒãã¯éå¢ã§ãããããªéå¢ã®äžéšã§ããçµµæåã«ã€ããŠèª¿ã¹ãŸããã
ãã®èšäºã«æžãããŠããããš
- Unicode ã®çµµæåãç¹ã«ååïŒãªã¬ãã£ïŒãšããŠè¡šçŸãããçµµæåã®ä»çµã¿
- ãªã¬ãã£ãšäŒŒããããªèŠãç®ãšæåæ°ã®ç°ãªãæåã³ãŒãã®ä»æ§ïŒãµãã²ãŒããã¢ãçµåæååïŒ
- çµµæåãå«ãã æåã¯ã©ãããªããŒã·ã§ã³ããã°ããã®ã
åé¡
以äžã®ãããªæååã¯ãäœæåãšããŠã«ãŠã³ãããã°ããã§ããããïŒïŒæåã³ãŒãã¯UTF-8ãšããŸãïŒ
ãŸããããªããŒã·ã§ã³ããäžã§ã¯ã©ã®ãããªç¹ã«æ³šæãã¹ãã§ããããïŒ
ã«ãŒãªãã¢ã®çœäººç·æ§ðšð»âðŠ±
â»ç°å¢ã«ãã£ãŠã¯çµµæåãæ£ãã衚瀺ãããªããããããŸãããç»åã«ãããšä»¥äžã®ããã«ãªã£ãŠããŸãïŒWindows 10 / Firefox ã䜿çšïŒã
å®éã«ã«ãŠã³ãããŠã¿ã
æ¥åã«ãããŠã¯ã1æåã®å®çŸ©ãããŸã確èªããæ¹ãè¯ããšæããŸãããããã§ã¯ã²ãšãŸãã«ãŠã³ãããŠã¿ãŸãããã
èŠãç®ã§ã«ãŠã³ã
èŠããŸãŸãæ°ãããš11æåã§ãã
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
---|---|---|---|---|---|---|---|---|---|---|
ã« | ㌠| 㪠| ã | 㢠| ã® | çœ | 人 | ç· | æ§ | ðšð»âðŠ± |
ããã°ã©ã ã§ã«ãŠã³ã
åçš®ããã°ã©ãã³ã°èšèªã§æåæ°ãã«ãŠã³ãããããã°ã©ã ãäœã£ãŠèª¿ã¹ãŠã¿ãŸããã
ããã°ã©ãã³ã°èšèª | ã«ãŠã³ãã«äœ¿ã£ãé¢æ° | çµæ |
---|---|---|
Python 3 | len() | 14 |
Java 12 | String.length() | 17 |
PHP 7 | mb_strlen() | 14 |
Swift 4 | String.count | 11 |
Swift 4 | String.unicodeScalars.count | 14 |
Swift 4 | String.characters.count | 11 |
çµæã¯ãã©ãã©ã«ãªããŸããã次ã«çµµæå ðšð»âðŠ±
ã®éšåãæ¶ããŠã«ãŠã³ãããªãããŠã¿ãŸãããã
ããã°ã©ãã³ã°èšèª | ã«ãŠã³ãã«äœ¿ã£ãé¢æ° | çµæ |
---|---|---|
Python 3 | len() | 10 |
Java 12 | String.length() | 10 |
PHP 7 | mb_strlen() | 10 |
Swift 4 | String.count | 10 |
Swift 4 | String.unicodeScalars.count | 10 |
Swift 4 | String.characters.count | 10 |
10æåã§äžèŽããããšãããçµµæåãã«ãŠã³ãã®å·®ãçãã§ããããšãåãããŸããããªããã®ãããªå·®ãçãŸããã®ã§ããããïŒ
ååïŒãªã¬ãã£ïŒã¯è€æ°ã®æåãèŠãç®äž1æåã«ããŠãã
UTF-8ãããŸãæ±ããããã°ã©ãã³ã°èšèªã§ããã°ãçµµæåã¯1ã€1æåãšã«ãŠã³ãããŠãããŸããããããäžã«ã¯ãèŠãç®äžã¯1æåã ããæåã³ãŒããšããŠã¯è€æ°æåã§ããããšããæåããããŸãããã®1ã€ãååïŒãªã¬ãã£ïŒã§ãã
ä»åã® ðšð»âðŠ±
ãšããçµµæåããååã䜿ãããŠããŸãã1æåãã€ã«å解ãããšä»¥äžã®ããã«ãªããŸãã
æåé | çµµæåå 容 | çµµæåã°ãªã | Emojipedia ãªã³ã¯ |
---|---|---|---|
1 | ç·æ§ | ðš |
Man Emoji |
2 | ZWJ | (衚瀺äžå¯) |
âZero Width Joiner (ZWJ) Emoji |
3 | æããè | ð» |
Pale Skin Tone Emoji |
4 | ZWJ | (衚瀺äžå¯) |
âZero Width Joiner (ZWJ) Emoji |
5 | ã«ãŒãªã㢠| ðŠ± |
Emoji Component Curly Hair Emoji |
äžèšã®ããã«ååã¯ãZero Width JoinerïŒZWJïŒããšããå¶åŸ¡æåã§çµµæåå士ãçµå1ããŠããŸããæ°åŒã®ããã«æžããšä»¥äžã®ããã«ãªããŸãã
ðšã+ ZWJ +ãð»ã+ ZWJ +ãðŠ±ã=ãðšð»âðŠ±
ãã®ZWJã䜿ã£ãŠè¡šçŸå¯èœãªçµµæåã¯ãEmoji ZWJ (Zero Width Joiner) Sequencesã«äžèŠ§ããããŸãã
ZWJã«ããååã®çµµæåã¯Unicodeã«ãã£ãŠå®çŸ©ãããŠããŸãããã®å®çŸ©ã®ããã°ååã«ãã£ãŠå¹ åºãçµµæåãè¡šçŸå¯èœãšããŠãããå°æ¥ååã«ãã£ãŠããã«å€ãã®çµµæåãè¡šçŸã§ããå¯èœæ§ããããŸããäŸãã°ãèã®è²ãæ§å¥ã髪圢ã ãã§ãªãã以äžã®ãããªçµµæåïŒCouple with Heart: Woman, Woman EmojiïŒãååšããŸããçæ¹ãç·æ§ã«å€ããããèã®è²ãå€ããããã§ããŸãã
äŸ1ïŒð© + ZWJ + â€ïž + ZWJ + ð© = ð©ââ€ïžâð©
äŸ2ïŒð© + ZWJ + â€ïž + ZWJ + ðš + ZWJ + ð¿ = ð©ââ€ïžâðšð¿
ããã§ããã°ã©ã ã§ã®ã«ãŠã³ãçµæãããäžåºŠç¢ºèªããŠã¿ãŸããçµæã11æåãšãªã£ãŠãããã®ã¯èŠãç®éãã«ã«ãŠã³ãããŠãããšèšããŸããäžæ¹ãZWJã1æåãšã«ãŠã³ããããªãã°ãåè¿°ã®éã ðšð»âðŠ±
ã¯5æåãšãæ°ããããšãã§ããŸããã€ãŸã ã«ãŒãªãã¢ã®çœäººç·æ§ðšð»âðŠ±
ã15æåãšããŠã«ãŠã³ãããããšãäºæ³ã§ããŸãããããå®éã«ã¯15æåã®çµæã¯ãªãã14æåãŸãã¯17æåãšäºæ³ãšç°ãªããŸããäœæ
ã§ããããïŒ
ZWJã䜿ããªãçµµæåã®çµå
å®ã¯ZWJãªãã§ãçµµæåãçµåãããå ŽåããããŸããïŒåŸè¿°ã®çµåæåã«äŒŒãŠããŸããïŒããã話ããããããããŠããŸãã
äŸãã°ãèã®è²ã¯ZWJãæãŸããšãä»ã®çµµæåãšçµåããããšããããŸããUnicodeã§ã¯ãModifier SequencesããšåŒã°ããŠããŸãã
äŸïŒð + ðœ = ððœ (ZWJãæãŸããšãèã®è²ãå€ãã)
ã€ãŸããçµµæå ðšð»âðŠ±
ã¯ä»¥äžã®2ãã¿ãŒã³ãããšããããšã§ãã
(1) ðšã+ ZWJ +ãð»ã+ ZWJ +ãðŠ±ã=ãðšð»âðŠ± # 5 æåã®åå
(2) ðšã +ãð»ã+ ZWJ +ãðŠ±ã=ãðšð»âðŠ± # 4 æåã®åå
åè¿°ã®åé¡ã«äœ¿ãããŠãã ðšð»âðŠ±
ã¯å®ã¯ (2) ã®4æåãããªãååã§ãããã€ãŸã14æåãšã«ãŠã³ãããããã°ã©ã ã¯æ£ããååãå解ããŠ1æåãã€å€æãããšèšããã§ãããã2
ååãšãã䌌ãä»æ§ã®æå
ãµãã²ãŒããã¢
åæã®Unicodeã¯1æå2ãã€ãã§è¡šçŸããããšããŠããŸããããããã«2ãã€ãã§ã¯è¶³ããªããªã£ãããæ¡åŒµãããŸããããããå ã Unicodeã¯2ãã€ãã§è¡šçŸã§ãããšããåæã§äœãããUTF-16ã§äžéœåãèµ·ãããŸããããã§UnicodeãšUTF-16ã¯æªäœ¿çšã®ã³ãŒãç¯å²ã®æåã2æåå䜿ãããšã§1æå4ãã€ãã§è¡šçŸããä»æ§ããµãã²ãŒããã¢ãäœããŸããã
ãµãã²ãŒããã¢ã®ãšã³ã³ãŒãã£ã³ã°ã¯å°ã è€éãªã®ã§å²æããŸãããèŠãç®ãUnicodeå®çŸ©ã1æåã§ãããããUTF-16ã§ãµãã²ãŒããã¢ããšã³ã³ãŒããããšãæåã³ãŒãä»æ§äžã¯2æåãšãèšããè¡šçŸã«ãªã£ãŠããŸãããããŠUTF-16ã§ã¯çµµæåããµãã²ãŒããã¢ã§è¡šãããŸãã
ãªãä»åã®åé¡ãšããŠããã®ã¯UTF-8ã§ã¯ããµãã²ãŒããã¢ã¯ååšããŸããïŒUTF-8ã¯1æå4ãã€ãã§ãè¡šçŸå¯èœã®ããïŒã
çµåæåå
Unicodeã«ã¯Combining CharacterïŒçµåæåïŒãšããä»æ§ããããŸããããã¯æ¥æ¬èªã§ã¯æ¿ç¹ã»åæ¿ç¹ãåœãŠã¯ãŸããŸããäŸãã°ä»¥äžã®ãããªãã®ã§ãã
ã + (æ¿ç¹ã®çµåæå) = ãã
ãã®ããã«çµåãããæååãçµåæååã¯èŠãç®äžã¯1æåã§ãããæåã³ãŒããšããŠã¯2æåã«ãªããŸããååãšäŒŒãŠããŸãããZWJãå¿ èŠãšããŸããããŸããçµåæååç¬ã§äœ¿ãããšã¯æ³å®ãããŠããŸããã
ããã«Unicodeã§ã¯çµåæååã®ããããšçµåæååã§ã¯ãªããããã®äž¡æ¹ãååšããŸããã€ãŸããèŠãç®äžã¯äžç·ã§ãçµåæååãã©ããã§æåã³ãŒãäžã¯1æåã2æåãå€ããã®ã§ãããããæååã®ã«ãŠã³ãããããããããŠããŸãã
ããã°ã©ã ã§æååãã«ãŠã³ãããæå³
ããã°ã©ã ã§ã¯æåæ°ã®ããªããŒã·ã§ã³ããããšãéåžžã«ãããããŸããããªããŒã·ã§ã³ãããäž»ãªçç±ã¯ãDBã®ã«ã©ã å®çŸ©ãªã©ã·ã¹ãã äžã®äžéå€ãè¶ ããªãããã«ããããã§ãã
äŸãã°MySQLã®VARCHARåã¯ããã®ã«ã©ã ã®æåã³ãŒããutf8mb4ã§ããå Žå3ãUTF-8ãšããŠã®1æåãé·ãã®åäœãšããŠæ±ããŸããã€ãŸã VARCHAR(50)
ãªãUTF-8ã§50æåãäžéã®ã«ã©ã ãšãªããŸãããã€ãåäœã§ã¯ãããŸãããUTF-8ã§ã®1æåãåäœãšããã®ã§ãååãçµåæåã¯åå¥ã®æåã«å解ããåŸã®æåæ°ãèŠãŸãã4
ãããã€ãæ°ã®äžéå€ããããªããæåã³ãŒãè¡šçŸã§ã®ãã€ãæ°ãæ°ããã°ããã§ãããã®å Žåã¯ããã°ã©ãã³ã°èšèªå éšã®æåè¡šçŸãçµã¿èŸŒã¿é¢æ°ã®ä»æ§ã«æ°ãä»ããŠã«ãŠã³ãããå¿ èŠããããŸãã
ãããã®å ŽåãGUIã§ã®æååã®èŠãç®ãšãæåã«ãŠã³ãæ°ãç°ãªããã¿ãŒã³ãåºãŠããŸãããŠãŒã¶ãæ··ä¹±ããªãããã«UIãã¡ãã»ãŒãžã®å·¥å€«ã§ãªããšãããããšããã§ãã
æªãäŸãšããŠãçµµæåã®å ¥åãçŠæ¢ãããšããæ¹æ³ãèããããŸããä»åã¯çµµæåã«ãã©ãŒã«ã¹ããŸãããããµãã²ãŒããã¢ãçµåæåãªã©ä»ã«ãåä»ãªæåè¡šçŸã沢山ãããŸããå®æãªèãã§å ¥åãããããªãæåãçŠæ¢ã«ããã ãã§ã¯äºæ³ããªãæåãå ¥ã£ãŠããããšããããŸããåçš®æåã³ãŒãã®ä»æ§ãDBãªã©ã·ã¹ãã ãæ§æãæ£ããææ¡ããŠããªããŒã·ã§ã³ãè¡ããŸãããã
ãŸãšã
- åå
- è€æ°ã®æåïŒçµµæåïŒãZWJã§çµåããŠ1æåã«èŠããŠãã
- ZWJå«ããååãæ§æããæå1ã€ã²ãšã€ã1æåãšã«ãŠã³ããããšèŠãç®äžã®æåæ°ãšç°ãªãã
- èã®è²ã¯ZWJã䜿ããçµåãããããðšð»âðŠ±ã¯4æåã5æåã©ã¡ãã§ãè¡šçŸã§ããŠããŸããäœæåãç¥ãã«ã¯æåã³ãŒãåäœã§æ°ããŠã¿ããããªãã
- ãµãã²ãŒããã¢
- UTF-8ã§ã¯äœ¿ãããªãã
- UTF-16ã䜿ãå Žåããµãã²ãŒããã¢ã¯èŠãç®äž1æåã ãã2æååã®ãã€ãæ°ãšãªãã
- UTF-16ã§çµµæåã¯ãµãã²ãŒããã¢ãšããŠè¡šãããã
- çµåæåå
- åã®æåã«ãã£ã€ãæåã
- æåãšããŠã¯1æååã
- æ¿é³ã»åæ¿é³ã®çµåæåãååšããããæ··ä¹±ã®ããšã«ãªãã ããªã®ã§äœ¿ããªãæ¹ãç¡é£ã ãæ®éã«ããŠãã°äœ¿ãããªãã
ãããJavaã17æåãªã®ã¯äœã§ïŒïŒ
解説ãé·ããªã£ãã®ã§å²æããŸããããJavaã¯å éšçã«æåãUTF-16ãšããŠæ±ããŸãããµãã²ãŒããã¢1æåã¯2ãšã«ãŠã³ãããŸããã€ãŸããðšð»âðŠ±ã¯ä»¥äžã®ããã«åèš7æåãšããŠã«ãŠã³ããããŸããã10+7=17æåã§ãã
# | çµµæå | æååé¡ | String.length() |
---|---|---|---|
1 | ðš |
ãµãã²ãŒãã㢠| 2 |
2 | ð» |
ãµãã²ãŒãã㢠| 2 |
3 | ZWJ | å¶åŸ¡æå | 1 |
4 | ðŠ± |
ãµãã²ãŒãã㢠| 2 |
åè
- Unicode - Wikipedia
-
Emoji ZWJ Sequences: Three Letters, Many Possibilities
- ZWJã«ããçµµæåçµåã®è§£èª¬
-
ãŒãå¹
æ¥åå - Wikipedia
- ããããZWJã¯ã¢ã©ãã¢æåãªã©ã®çµçãªã©ã®ããã«ååšããå¶åŸ¡æåãããããžãŒã
-
Unicode Emoji v14.0
- Unicodeã®Emojiä»æ§ãæžãããŠããã
-
åææžã¿æå - Wikipedia
- çµåæåã®å¥åã
-
Unicodeã®ç¹æ®ãªæå âçµåæååâ â ãã®ãã®
- Mac OS Xã§ã¯æ¿ç¹ã»åæ¿ç¹ã«çµåæåã䜿ãããŠããããšããã£ãã
-
UTF-8ã®æåã³ãŒãè¡š - åå¿åž³ - ãªã¬ã³ãžå·¥æ¿
- 4ãã€ãæåã«çµµæåãå ¥ã£ãŠããã
- Swift3ã§çµµæåãå«ãã æååã®é·ããååŸããæ¹æ³ - Qiita
- String (Java SE 12 & JDK 12 )
-
Emojipedia ã§åæåã1æåãã€ã³ããŒã§ããŸãã1æåãã€é©åœãªããã¹ããšãªã¢ã«ã³ããããŠãããšãæå ã®ç°å¢ã§ãååãçµã¿ç«ãŠãããšãã§ããŸãã â©
-
ä»åã¯æåã³ãŒãä»æ§ç解ã®ããçµæããããã°ã©ã ã®åäœãæšæž¬ããŠããŸãããå®é䜿ãéã¯åã¡ãœããã»é¢æ°ã®ä»æ§ãããã¥ã¢ã«ãªã©ã§æ£ããææ¡ããŠäœ¿ããŸãããã â©
-
ã«ã©ã ã®æåã³ãŒããutf8mb3ïŒUTF-8ã®3ãã€ãã§è¡šçŸã§ããæåããæ±ããªãïŒã§ããå Žåã¯çµµæåïŒUTF-8ã§4ãã€ãè¡šçŸã®æåïŒã¯æ±ããŸãããããã©ã«ããutf8mb4ãªã®ã§ãããŸãæ°ã«ããå¿ èŠã¯ãããŸãããã â©
-
äœè«ã§ãããMySQL 5.6ãªã©ã®æšæºèšå®ã§ã¯ãã«ã©ã ã§ã¯ãªãã€ã³ããã¯ã¹ã«767ãã€ãã®å¶éããããæã£ãé·ãã®æååãå ¥ããããªããšããäºããããŸããã€ã³ããã¯ã¹ã®ãã©ãŒãããã
Barracuda
ã«å€æŽããããšã§ãã®äžéã¯åé¿ããããšãå¯èœã§ããMySQL 5.7 以éã§ã¯æšæºã§Barracuda
ãšãªã£ãŠããŸããåè: MySQLã®ã€ã³ããã¯ã¹ãµã€ãºã«767byteãŸã§ããã€ãããªãåé¡ãšå¯Ÿç - ãããã° â©