Files
kiwistation/code/modules/emoji/emoji_parse.dm
T
MrPerson f7eb2c905b Unicode awareness Part 2 -- copytext() (#48512)
* Unicode support Part 2 -- copytext()

This is the transition of all copytext() calls to be unicode aware and also some nearby calls in the same functions. Most things are just replacing copytext() with copytext_char() as a terrible character limiter but a few others were slightly more involved.

I replaced a ton of
````
var/something = sanitize(input())
something = copytext(something, 1, MAX_MESSAGE_LEN)
````

with a single stripped_input() call. stripped_input() already calls html_encode(), trim(), and some other sanitization so there shouldn't be any major issues there.

This is still VERY rough btw; DNA is a mess, the status displays are complete ass, there's a copytext() in code\datums\shuttles.dm that I'm not sure what to do with, and I didn't touch anything in the tools folder. I haven't tested this much at all yet, I only got it to compile earlier this morning. There's also likely to be weird bugs until I get around to fixing length(), findtext(), and the rest of the string procs.

* Makes the code functional

* Assume color hex strings are always # followed by ascii.
Properly encodes and decodes the stuff in mob_helpers.dm which fixes some issues there.

* Removes ninjaspeak since it's unused
2020-01-18 13:07:22 +13:00

54 lines
1.5 KiB
Plaintext

/proc/emoji_parse(text) //turns :ai: into an emoji in text.
. = text
if(!CONFIG_GET(flag/emojis))
return
var/static/list/emojis = icon_states(icon('icons/emoji.dmi'))
var/parsed = ""
var/pos = 1
var/search = 0
var/emoji = ""
while(1)
search = findtext(text, ":", pos)
parsed += copytext(text, pos, search)
if(search)
pos = search
search = findtext(text, ":", pos + length(text[pos]))
if(search)
emoji = lowertext(copytext(text, pos + length(text[pos]), search))
var/datum/asset/spritesheet/sheet = get_asset_datum(/datum/asset/spritesheet/goonchat)
var/tag = sheet.icon_tag("emoji-[emoji]")
if(tag)
parsed += tag
pos = search + length(text[pos])
else
parsed += copytext(text, pos, search)
pos = search
emoji = ""
continue
else
parsed += copytext(text, pos, search)
break
return parsed
/proc/emoji_sanitize(text) //cuts any text that would not be parsed as an emoji
. = text
if(!CONFIG_GET(flag/emojis))
return
var/static/list/emojis = icon_states(icon('icons/emoji.dmi'))
var/final = "" //only tags are added to this
var/pos = 1
var/search = 0
while(1)
search = findtext(text, ":", pos)
if(search)
pos = search
search = findtext(text, ":", pos + length(text[pos]))
if(search)
var/word = lowertext(copytext(text, pos + length(text[pos]), search))
if(word in emojis)
final += lowertext(copytext(text, pos, search + length(text[search])))
pos = search + length(text[search])
continue
break
return final