From 5b430ca3cca0c0a334e1ddcffd1f93cb7667f4b6 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Sat, 16 Nov 2024 03:25:19 -0500 Subject: [PATCH] implements trimtext() --- code/__HELPERS/text.dm | 20 +------------------- code/modules/mapping/reader.dm | 9 +++------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index eb4059af7f50..f8f6e639c524 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -284,24 +284,6 @@ return copytext(text, 1, i + 1) return "" -//Returns a string with reserved characters and spaces after the first and last letters removed -//Like trim(), but very slightly faster. worth it for niche usecases -/proc/trim_reduced(text) - var/starting_coord = 1 - var/text_len = length(text) - for (var/i in 1 to text_len) - if (text2ascii(text, i) > 32) - starting_coord = i - break - - for (var/i = text_len, i >= starting_coord, i--) - if (text2ascii(text, i) > 32) - return copytext(text, starting_coord, i + 1) - - if(starting_coord > 1) - return copytext(text, starting_coord) - return "" - /** * Truncate a string to the given length * @@ -322,7 +304,7 @@ /proc/trim(text, max_length) if(max_length) text = copytext_char(text, 1, max_length) - return trim_reduced(text) + return trimtext(text) //Returns a string with the first element of the string capitalized. /proc/capitalize(t) diff --git a/code/modules/mapping/reader.dm b/code/modules/mapping/reader.dm index ceeedfa9f794..59fbee0377ce 100644 --- a/code/modules/mapping/reader.dm +++ b/code/modules/mapping/reader.dm @@ -115,9 +115,6 @@ var/turfsSkipped = 0 #endif -//text trimming (both directions) helper macro -#define TRIM_TEXT(text) (trim_reduced(text)) - /// Shortcut function to parse a map and apply it to the world. /// /// - `dmm_file`: A .dmm file to load (Required). @@ -722,7 +719,7 @@ GLOBAL_LIST_EMPTY(map_model_default) if(member_string[length(member_string)] == "}") variables_start = findtext(member_string, "{") - var/path_text = TRIM_TEXT(copytext(member_string, 1, variables_start)) + var/path_text = trimtext(copytext(member_string, 1, variables_start)) var/atom_def = text2path(path_text) //path definition, e.g /obj/foo/bar if(!ispath(atom_def, /atom)) // Skip the item if the path does not exist. Fix your crap, mappers! @@ -898,7 +895,7 @@ GLOBAL_LIST_EMPTY(map_model_default) // check if this is a simple variable (as in list(var1, var2)) or an associative one (as in list(var1="foo",var2=7)) var/equal_position = findtext(text,"=",old_position, position) - var/trim_left = TRIM_TEXT(copytext(text,old_position,(equal_position ? equal_position : position))) + var/trim_left = trimtext(copytext(text,old_position,(equal_position ? equal_position : position))) var/left_constant = parse_constant(trim_left) if(position) old_position = position + length(text[position]) @@ -908,7 +905,7 @@ GLOBAL_LIST_EMPTY(map_model_default) if(equal_position && !isnum(left_constant)) // Associative var, so do the association. // Note that numbers cannot be keys - the RHS is dropped if so. - var/trim_right = TRIM_TEXT(copytext(text, equal_position + length(text[equal_position]), position)) + var/trim_right = trimtext(copytext(text, equal_position + length(text[equal_position]), position)) var/right_constant = parse_constant(trim_right) .[left_constant] = right_constant else // simple var