### ----------------------------------------------------
### -- Text::Emoji
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: lib/Text/Emoji.rakumod
### ----------------------------------------------------
### -- Chunk 7 of 7
', "person-bald",
  '🧑‍🦳', "person-white-hair",
  '🧑‍🦼', "person-in-motorized-wheelchair",
  '🧑‍🦽', "person-in-manual-wheelchair",
  '🧒', "child",
  '🧓', "older-adult",
  '🧔', "bearded-person",
  '🧔‍♀️', "woman-beard",
  '🧔‍♂️', "man-beard",
  '🧕', "woman-with-headscarf",
  '🧖', "sauna-person",
  '🧖‍♀️', "sauna-woman",
  '🧖‍♂️', "sauna-man",
  '🧗', "climbing",
  '🧗‍♀️', "climbing-woman",
  '🧗‍♂️', "climbing-man",
  '🧘', "lotus-position",
  '🧘‍♀️', "lotus-position-woman",
  '🧘‍♂️', "lotus-position-man",
  '🧙', "mage",
  '🧙‍♀️', "mage-woman",
  '🧙‍♂️', "mage-man",
  '🧚', "fairy",
  '🧚‍♀️', "fairy-woman",
  '🧚‍♂️', "fairy-man",
  '🧛', "vampire",
  '🧛‍♀️', "vampire-woman",
  '🧛‍♂️', "vampire-man",
  '🧜', "merperson",
  '🧜‍♀️', "mermaid",
  '🧜‍♂️', "merman",
  '🧝', "elf",
  '🧝‍♀️', "elf-woman",
  '🧝‍♂️', "elf-man",
  '🧞', "genie",
  '🧞‍♀️', "genie-woman",
  '🧞‍♂️', "genie-man",
  '🧟', "zombie",
  '🧟‍♀️', "zombie-woman",
  '🧟‍♂️', "zombie-man",
  '🧠', "brain",
  '🧡', "orange-heart",
  '🧢', "billed-cap",
  '🧣', "scarf",
  '🧤', "gloves",
  '🧥', "coat",
  '🧦', "socks",
  '🧧', "red-envelope",
  '🧨', "firecracker",
  '🧩', "jigsaw",
  '🧪', "test-tube",
  '🧫', "petri-dish",
  '🧬', "dna",
  '🧭', "compass",
  '🧮', "abacus",
  '🧯', "fire-extinguisher",
  '🧰', "toolbox",
  '🧱', "bricks",
  '🧲', "magnet",
  '🧳', "luggage",
  '🧴', "lotion-bottle",
  '🧵', "thread",
  '🧶', "yarn",
  '🧷', "safety-pin",
  '🧸', "teddy-bear",
  '🧹', "broom",
  '🧺', "basket",
  '🧻', "roll-of-paper",
  '🧼', "soap",
  '🧽', "sponge",
  '🧾', "receipt",
  '🧿', "nazar-amulet",
  '🩰', "ballet-shoes",
  '🩱', "one-piece-swimsuit",
  '🩲', "swim-brief",
  '🩳', "shorts",
  '🩴', "thong-sandal",
  '🩵', "light-blue-heart",
  '🩶', "grey-heart",
  '🩷', "pink-heart",
  '🩸', "drop-of-blood",
  '🩹', "adhesive-bandage",
  '🩺', "stethoscope",
  '🩻', "x-ray",
  '🩼', "crutch",
  '🪀', "yo-yo",
  '🪁', "kite",
  '🪂', "parachute",
  '🪃', "boomerang",
  '🪄', "magic-wand",
  '🪅', "pinata",
  '🪆', "nesting-dolls",
  '🪇', "maracas",
  '🪈', "flute",
  '🪐', "ringed-planet",
  '🪑', "chair",
  '🪒', "razor",
  '🪓', "axe",
  '🪔', "diya-lamp",
  '🪕', "banjo",
  '🪖', "military-helmet",
  '🪗', "accordion",
  '🪘', "long-drum",
  '🪙', "coin",
  '🪚', "carpentry-saw",
  '🪛', "screwdriver",
  '🪜', "ladder",
  '🪝', "hook",
  '🪞', "mirror",
  '🪟', "window",
  '🪠', "plunger",
  '🪡', "sewing-needle",
  '🪢', "knot",
  '🪣', "bucket",
  '🪤', "mouse-trap",
  '🪥', "toothbrush",
  '🪦', "headstone",
  '🪧', "placard",
  '🪨', "rock",
  '🪩', "mirror-ball",
  '🪪', "identification-card",
  '🪫', "low-battery",
  '🪬', "hamsa",
  '🪭', "folding-hand-fan",
  '🪮', "hair-pick",
  '🪯', "khanda",
  '🪰', "fly",
  '🪱', "worm",
  '🪲', "beetle",
  '🪳', "cockroach",
  '🪴', "potted-plant",
  '🪵', "wood",
  '🪶', "feather",
  '🪷', "lotus",
  '🪸', "coral",
  '🪹', "empty-nest",
  '🪺', "nest-with-eggs",
  '🪻', "hyacinth",
  '🪼', "jellyfish",
  '🪽', "wing",
  '🪿', "goose",
  '🫀', "anatomical-heart",
  '🫁', "lungs",
  '🫂', "people-hugging",
  '🫃', "pregnant-man",
  '🫄', "pregnant-person",
  '🫅', "person-with-crown",
  '🫎', "moose",
  '🫏', "donkey",
  '🫐', "blueberries",
  '🫑', "bell-pepper",
  '🫒', "olive",
  '🫓', "flatbread",
  '🫔', "tamale",
  '🫕', "fondue",
  '🫖', "teapot",
  '🫗', "pouring-liquid",
  '🫘', "beans",
  '🫙', "jar",
  '🫚', "ginger-root",
  '🫛', "pea-pod",
  '🫠', "melting-face",
  '🫡', "saluting-face",
  '🫢', "face-with-open-eyes-and-hand-over-mouth",
  '🫣', "face-with-peeking-eye",
  '🫤', "face-with-diagonal-mouth",
  '🫥', "dotted-line-face",
  '🫦', "biting-lip",
  '🫧', "bubbles",
  '🫨', "shaking-face",
  '🫰', "hand-with-index-finger-and-thumb-crossed",
  '🫱', "rightwards-hand",
  '🫲', "leftwards-hand",
  '🫳', "palm-down-hand",
  '🫴', "palm-up-hand",
  '🫵', "index-pointing-at-the-viewer",
  '🫶', "heart-hands",
  '🫷', "leftwards-pushing-hand",
  '🫸', "rightwards-pushing-hand",
;
#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE
#- end of generated part of Text::Emoji

#- to-emoji --------------------------------------------------------------------
my proto sub to-emoji(|) is export {*}
my multi sub to-emoji(Str:D $text) is default {
    $text.contains(":")
      ?? $text.trans: / ":" <[\w+-]>+ ":" / => {
             %lookup{$/.substr(1, *-1).lc} || $/.Str
         }
      !! $text
}
my multi sub to-emoji(Str:D $text, %additional) {
    $text.contains(":")
      ?? $text.trans: / ":" <[\w+-]>+ ":" / => {
             my $key = $/.substr(1, *-1).lc;
             if %additional{$key} -> $value {
                 %lookup{$value} || $value
             }
             else {
                 %lookup{$key} || $/.Str
             }
         }
      !! $text
}
my multi sub to-emoji(Str:D $text, *%_) { to-emoji($text, %_) }

#- to-text ---------------------------------------------------------------------
my proto sub to-text(|) is export {*}
my multi sub to-text(Str:D $text) is default {
    my int $from;
    my int $to;
    my str @parts;

    for $text.comb -> $grapheme {
        if %reverse{$grapheme} -> $alternatives {
            @parts.push: $text.substr($from, $to - $from);
            @parts.push: ":$alternatives.head():";
            $from = ++$to;
        }
        else {
            ++$to;
        }
    }

    # graphemes found
    if @parts {
        @parts.push: $text.substr($from, $to - $from);
        @parts.join
    }

    # no work done
    else {
        $text
    }
}
my multi sub to-text(Str:D $text, %extra) {
    my %additional is Map = %extra.map: {
        (%lookup{.value} || .value) => .key
    }
    my int $from;
    my int $to;
    my str @parts;

    for $text.comb -> $grapheme {
        if %additional{$grapheme} || %reverse{$grapheme} -> $alternatives {
            @parts.push: $text.substr($from, $to - $from);
            @parts.push: ":$alternatives.head():";
            $from = ++$to;
        }
        else {
            ++$to;
        }
    }

    # graphemes found
    if @parts {
        @parts.push: $text.substr($from, $to - $from);
        @parts.join
    }

    # no work done
    else {
        $text
    }
}
my multi sub to-text(Str:D $text, *%_) { to-text($text, %_) }

#- raw-emoji-data --------------------------------------------------------------
my %raw;
my sub raw-emoji-data() is export {
    if %raw {
        %raw
    }
    else {
        %raw := my %map is Map = Rakudo::Internals::JSON.from-json(
          %?RESOURCES<emojis.json>.slurp
        ).map: { .<emoji>:delete => .Map }
    }
}

# vim: expandtab shiftwidth=4


