mirror of
https://github.com/fulpstation/fulpstation.git
synced 2025-12-09 16:09:15 +00:00
* 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
89 lines
2.1 KiB
Plaintext
89 lines
2.1 KiB
Plaintext
//general stuff
|
|
/proc/sanitize_integer(number, min=0, max=1, default=0)
|
|
if(isnum(number))
|
|
number = round(number)
|
|
if(min <= number && number <= max)
|
|
return number
|
|
return default
|
|
|
|
/proc/sanitize_text(text, default="")
|
|
if(istext(text))
|
|
return text
|
|
return default
|
|
|
|
/proc/sanitize_islist(value, default)
|
|
if(islist(value) && length(value))
|
|
return value
|
|
if(default)
|
|
return default
|
|
|
|
/proc/sanitize_inlist(value, list/List, default)
|
|
if(value in List)
|
|
return value
|
|
if(default)
|
|
return default
|
|
if(List && List.len)
|
|
return pick(List)
|
|
|
|
|
|
|
|
//more specialised stuff
|
|
/proc/sanitize_gender(gender,neuter=0,plural=1, default="male")
|
|
switch(gender)
|
|
if(MALE, FEMALE)
|
|
return gender
|
|
if(NEUTER)
|
|
if(neuter)
|
|
return gender
|
|
else
|
|
return default
|
|
if(PLURAL)
|
|
if(plural)
|
|
return gender
|
|
else
|
|
return default
|
|
return default
|
|
|
|
/proc/sanitize_hexcolor(color, desired_format=3, include_crunch=0, default)
|
|
var/crunch = include_crunch ? "#" : ""
|
|
if(!istext(color))
|
|
color = ""
|
|
|
|
var/start = 1 + (text2ascii(color, 1) == 35)
|
|
var/len = length(color)
|
|
var/char = ""
|
|
// RRGGBB -> RGB but awful
|
|
var/convert_to_shorthand = desired_format == 3 && length_char(color) > 3
|
|
|
|
. = ""
|
|
var/i = start
|
|
while(i <= len)
|
|
char = color[i]
|
|
switch(text2ascii(char))
|
|
if(48 to 57) //numbers 0 to 9
|
|
. += char
|
|
if(97 to 102) //letters a to f
|
|
. += char
|
|
if(65 to 70) //letters A to F
|
|
. += lowertext(char)
|
|
else
|
|
break
|
|
i += length(char)
|
|
if(convert_to_shorthand && i <= len) //skip next one
|
|
i += length(color[i])
|
|
|
|
if(length_char(.) != desired_format)
|
|
if(default)
|
|
return default
|
|
return crunch + repeat_string(desired_format, "0")
|
|
|
|
return crunch + .
|
|
|
|
/proc/sanitize_ooccolor(color)
|
|
if(length(color) != length_char(color))
|
|
CRASH("Invalid characters in color '[color]'")
|
|
var/list/HSL = rgb2hsl(hex2num(copytext(color, 2, 4)), hex2num(copytext(color, 4, 6)), hex2num(copytext(color, 6, 8)))
|
|
HSL[3] = min(HSL[3],0.4)
|
|
var/list/RGB = hsl2rgb(arglist(HSL))
|
|
return "#[num2hex(RGB[1],2)][num2hex(RGB[2],2)][num2hex(RGB[3],2)]"
|