Created
August 6, 2016 09:55
-
-
Save samhann/49da8cd4e4fc413c4a0051d9ec111640 to your computer and use it in GitHub Desktop.
Emojifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Emojifier | |
{ | |
var emojiMap : [ String : [String]] = [ | |
"smile|happy|laugh" : ["๐","๐","๐","๐","๐","๐","๐","๐"], | |
"wink|kidding" : ["๐"], | |
"tasty|yum|yummy|taste" : ["๐"], | |
"cool" : ["๐"], | |
"love" : ["๐","๐"], | |
"kiss" : ["๐","๐"], | |
"Hug" : ["๐ค"], | |
"Think" : ["๐ค"], | |
"nothing" : ["๐","๐"], | |
"Whatever" : ["๐"], | |
"Smirk" : ["๐"], | |
"Persevere" : ["๐ฃ"], | |
"shock" : ["๐ฎ","๐ณ"], | |
"muh band" : ["๐ค"], | |
"surprise" : ["๐ฏ"], | |
"tire" : ["๐ช"], | |
"Sleep" : ["๐ด"], | |
"Relief" : ["๐"], | |
"joking|kidding" : ["๐"], | |
"LOL" : ["๐"], | |
"Disappoint" : ["๐","๐","๐ฅ"], | |
"Sad" : ["๐"], | |
"Pensive" : ["๐"], | |
"Confused" : ["๐"], | |
"Upside-Down" : ["๐"], | |
"Money-Mouth" : ["๐ค"], | |
"Astonished " : ["๐ฒ"], | |
"Sick" : ["๐ค"], | |
"Confound " : ["๐"], | |
"Worry " : ["๐"], | |
"Cry" : ["๐ข","๐ญ"], | |
"Frown|sad" : ["๐ฆ","๐"], | |
"Anguish " : ["๐ง"], | |
"Fear " : ["๐จ"], | |
"Frustrate" : ["๐ฌ"], | |
"Scream" : ["๐ฑ"], | |
"Angry" : ["๐ก"], | |
"Skull" : ["๐"], | |
"Ghost" : ["๐ป"], | |
"Alien" : ["๐ฝ"], | |
"Robot " : ["๐ค"], | |
"Boy" : ["๐ฆ"], | |
"Girl" : ["๐ง"], | |
"Man|guy" : ["๐จ"], | |
"Woman|gal|girl" : ["๐ฉ"], | |
"Baby" : ["๐ถ"], | |
"Hair" : ["๐ฑ"], | |
"Officer|police|security" : ["๐ฎ"], | |
"Worker" : ["๐ท"], | |
"Helmet" : ["โ"], | |
"Princess" : ["๐ธ"], | |
"Guard" : ["๐"], | |
"Spy" : ["๐ต"], | |
"Santa" : ["๐ "], | |
"Bride" : ["๐ฐ"], | |
"Angel" : ["๐ผ"], | |
"Massage" : ["๐"], | |
"Pouting" : ["๐"], | |
"Pedestrian" : ["๐ถ"], | |
"Runner" : ["๐"], | |
"Family " : ["๐จโ๐ฉโ๐ง"], | |
"Left" : ["๐"], | |
"Right" : ["๐"], | |
"Up" : ["๐"], | |
"Down" : ["๐"], | |
"Hi" : ["๐","๐"], | |
"Stop" : ["โ"], | |
"OK" : ["๐"], | |
"Nope" : ["๐"], | |
"Clap|applause" : ["๐"], | |
"Eye" : ["๐"], | |
"Tongue" : ["๐ "], | |
"Mouth" : ["๐"], | |
"Mark" : ["๐"], | |
"Eyeglass" : ["๐"], | |
"Sunglass" : ["๐ถ"], | |
"Necktie" : ["๐"], | |
"T-Shirt" : ["๐"], | |
"Jean" : ["๐"], | |
"Dress" : ["๐"], | |
"Kimono" : ["๐"], | |
"Bikini" : ["๐"], | |
"Cloth|Clothes" : ["๐"], | |
"Purse" : ["๐"], | |
"Handbag" : ["๐"], | |
"Pouch" : ["๐"], | |
"Satchel" : ["๐"], | |
"Shoe" : ["๐"], | |
"Sandal" : ["๐ก"], | |
"Boot" : ["๐ข"], | |
"Crown" : ["๐"], | |
"Hat" : ["๐"], | |
"Cap" : ["๐"], | |
"Ring" : ["๐"], | |
"Umbrella" : ["๐"], | |
"Briefcase" : ["๐ผ"] | |
] | |
func emojify(string : String) -> String | |
{ | |
var final = string | |
let components = string.componentsSeparatedByString(" ") | |
for component in components { | |
if let emojiList = emojiMap[component.lowercaseString] { | |
final = final.stringByReplacingOccurrencesOfString(component, withString: emojiList.first ?? component, options: [.CaseInsensitiveSearch], range: final.startIndex..<final.endIndex) | |
} | |
} | |
return final | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment