clozach
clozach

Reputation: 5136

Stubborn emoji won't combine: 👨‍❀‍💋‍👨

Even after @user3441734 solved most of my problems πŸ™‡, there are a few emoji that I can't seem to render properly when converting from a [String:String] to String.

Here's some Playground-ready code to illustrate the problem:

var u = ""
u = "1f468-1f468-1f467-1f467" // πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§
//u = "1f918-1f3ff" // 🀘🏿
//u = "1f468-2764-1f48b-1f468" // πŸ‘¨β€β€β€πŸ’‹β€πŸ‘¨ (broken)
//u = "1f3c7-1f3fb" // πŸ‡β€πŸ» (broken)

let unicodeArray = u.characters.split("-")
    .map(String.init)
    .map {String(UnicodeScalar(Int($0,radix: 16) ?? 0))}

if let last = unicodeArray.last {
    let separator: String
    switch (unicodeArray.first, last) {
        // Failed attempt to get tone applied to jockey
    case let (horse_racing, _) where horse_racing == "\u{1f3c7}":
        separator = "\u{200d}"
    case let (_, tone) where "\u{1f3fb}"..."\u{1f3ff}" ~= tone:
        separator = ""
    case let (_, regionalIndicatorSymbol) where "\u{1f1e6}"..."\u{1f1ff}" ~= regionalIndicatorSymbol:
        separator = ""
    default:
        separator = "\u{200d}"
    }
    print(unicodeArray.joinWithSeparator(separator))
}

Uncomment each assignment to u in turn to see the problem in action. The 3rd and 4th values should render like so:

Man-kiss-man

and

Short-and-white

Thoughts…

So, bug in Apple & Chrome's handling of certain emoji, or is there yet another idiosyncrasy of the standard that I've missed?

Upvotes: 1

Views: 717

Answers (1)

δΈ€δΊŒδΈ‰
δΈ€δΊŒδΈ‰

Reputation: 21289

There's no conspiracy, the bugs are in your code.

  • The first character can be produced with:

    U+1F468 U+200D U+2764 U+FE0F U+200D U+1F48B U+200D U+1F468

    Note the ZERO WIDTH JOINER (U+200D) between each character, and the VARIATION SELECTOR-16 selector (U+FE0F) on the HEAVY BLACK HEART (U+2764) to ensure the emoji presentation style is used.

    Refer to this table for a complete list of implemented multi-person groupings.

  • U+1F3C7 HORSE RACING is not an emoji modifier base, and so it does not support skin tone modifiers.

Upvotes: 3

Related Questions