diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index a493aa9d08..af77addeab 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -195,32 +195,10 @@ proc/checkhtml(var/t) * Text modification */ /proc/replacetext(text, find, replacement) - var/find_len = length(find) - if(find_len < 1) return text - . = "" - var/last_found = 1 - while(1) - var/found = findtext(text, find, last_found, 0) - . += copytext(text, last_found, found) - if(found) - . += replacement - last_found = found + find_len - continue - return . + return list2text(text2list(text, find), replacement) /proc/replacetextEx(text, find, replacement) - var/find_len = length(find) - if(find_len < 1) return text - . = "" - var/last_found = 1 - while(1) - var/found = findtextEx(text, find, last_found, 0) - . += copytext(text, last_found, found) - if(found) - . += replacement - last_found = found + find_len - continue - return . + return list2text(text2listEx(text, find), replacement) //Adds 'u' number of zeros ahead of the text 't' /proc/add_zero(t, u) @@ -287,27 +265,6 @@ proc/checkhtml(var/t) return message return copytext(message, 1, length + 1) -/* - * Misc - */ - -/proc/stringsplit(txt, character) - var/cur_text = txt - var/last_found = 1 - var/found_char = findtext(cur_text,character) - var/list/list = list() - if(found_char) - var/fs = copytext(cur_text,last_found,found_char) - list += fs - last_found = found_char+length(character) - found_char = findtext(cur_text,character,last_found) - while(found_char) - var/found_string = copytext(cur_text,last_found,found_char) - last_found = found_char+length(character) - list += found_string - found_char = findtext(cur_text,character,last_found) - list += copytext(cur_text,last_found,length(cur_text)+1) - return list /proc/stringmerge(var/text,var/compare,replace = "*") //This proc fills in all spaces with the "replace" var (* by default) with whatever @@ -346,4 +303,4 @@ proc/checkhtml(var/t) var/new_text = "" for(var/i = length(text); i > 0; i--) new_text += copytext(text, i, i+1) - return new_text \ No newline at end of file + return new_text diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index 261e8c6d75..4e6287a5d2 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -83,22 +83,94 @@ return hex -//Attaches each element of a list to a single string seperated by 'seperator'. -/proc/dd_list2text(var/list/the_list, separator) - var/total = the_list.len - if(!total) - return - var/count = 2 - var/newText = "[the_list[1]]" - while(count <= total) - if(separator) - newText += separator - newText += "[the_list[count]]" - count++ - return newText +// Concatenates a list of strings into a single string. A seperator may optionally be provided. +/proc/list2text(list/ls, sep) + if(ls.len <= 1) // Early-out code for empty or singleton lists. + return ls.len ? ls[1] : "" + + var/l = ls.len // Made local for sanic speed. + var/i = 0 // Incremented every time a list index is accessed. + + if(sep <> null) + // Macros expand to long argument lists like so: sep, ls[++i], sep, ls[++i], sep, ls[++i], etc... + #define S1 sep, ls[++i] + #define S4 S1, S1, S1, S1 + #define S16 S4, S4, S4, S4 + #define S64 S16, S16, S16, S16 + + . = "[ls[++i]]" // Make sure the initial element is converted to text. + + // Having the small concatenations come before the large ones boosted speed by an average of at least 5%. + if(l-1 & 0x01) // 'i' will always be 1 here. + . = text("[][][]", ., S1) // Append 1 element if the remaining elements are not a multiple of 2. + if(l-i & 0x02) + . = text("[][][][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4. + if(l-i & 0x04) + . = text("[][][][][][][][][]", ., S4) // And so on.... + if(l-i & 0x08) + . = text("[][][][][][][][][][][][][][][][][]", ., S4, S4) + if(l-i & 0x10) + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16) + if(l-i & 0x20) + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16) + if(l-i & 0x40) + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64) + while(l > i) // Chomp through the rest of the list, 128 elements at a time. + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64) + + #undef S64 + #undef S16 + #undef S4 + #undef S1 + + else + // Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc... + #define S1 ls[++i] + #define S4 S1, S1, S1, S1 + #define S16 S4, S4, S4, S4 + #define S64 S16, S16, S16, S16 + + . = "[ls[++i]]" // Make sure the initial element is converted to text. + + if(l-1 & 0x01) // 'i' will always be 1 here. + . += S1 // Append 1 element if the remaining elements are not a multiple of 2. + if(l-i & 0x02) + . = text("[][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4. + if(l-i & 0x04) + . = text("[][][][][]", ., S4) // And so on... + if(l-i & 0x08) + . = text("[][][][][][][][][]", ., S4, S4) + if(l-i & 0x10) + . = text("[][][][][][][][][][][][][][][][][]", ., S16) + if(l-i & 0x20) + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16) + if(l-i & 0x40) + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64) + while(l > i) // Chomp through the rest of the list, 128 elements at a time. + . = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\ + [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64) + + #undef S64 + #undef S16 + #undef S4 + #undef S1 -//slower then dd_list2text, but correctly processes associative lists. +//slower then list2text, but correctly processes associative lists. proc/tg_list2text(list/list, glue=",") if(!istype(list) || !list.len) return @@ -108,56 +180,31 @@ proc/tg_list2text(list/list, glue=",") return output -//Converts a text string into a list by splitting the string at each seperator found in text (discarding the seperator) -//Returns an empty list if the text cannot be split, or the split text in a list. -//Not giving a "" seperator will cause the text to be broken into a list of single letters. -/proc/text2list(text, seperator="\n") +//Converts a string into a list by splitting the string at each delimiter found. (discarding the seperator) +/proc/text2list(text, delimiter="\n") + var/delim_len = length(delimiter) + if(delim_len < 1) return list(text) . = list() + var/last_found = 1 + var/found + do + found = findtext(text, delimiter, last_found, 0) + . += copytext(text, last_found, found) + last_found = found + delim_len + while(found) - var/text_len = length(text) //length of the input text - var/seperator_len = length(seperator) //length of the seperator text - - if(text_len >= seperator_len) - var/i - var/last_i = 1 - - for(i=1,i<=(text_len+1-seperator_len),i++) - if( cmptext(copytext(text,i,i+seperator_len), seperator) ) - if(i != last_i) - . += copytext(text,last_i,i) - last_i = i + seperator_len - - if(last_i <= text_len) - . += copytext(text, last_i, 0) - else - . += text - return . - -//Converts a text string into a list by splitting the string at each seperator found in text (discarding the seperator) -//Returns an empty list if the text cannot be split, or the split text in a list. -//Not giving a "" seperator will cause the text to be broken into a list of single letters. //Case Sensitive! -/proc/text2listEx(text, seperator="\n") +/proc/text2listEx(text, delimiter="\n") + var/delim_len = length(delimiter) + if(delim_len < 1) return list(text) . = list() - - var/text_len = length(text) //length of the input text - var/seperator_len = length(seperator) //length of the seperator text - - if(text_len >= seperator_len) - var/i - var/last_i = 1 - - for(i=1,i<=(text_len+1-seperator_len),i++) - if( cmptextEx(copytext(text,i,i+seperator_len), seperator) ) - if(i != last_i) - . += copytext(text,last_i,i) - last_i = i + seperator_len - - if(last_i <= text_len) - . += copytext(text, last_i, 0) - else - . += text - return . + var/last_found = 1 + var/found + do + found = findtextEx(text, delimiter, last_found, 0) + . += copytext(text, last_found, found) + last_found = found + delim_len + while(found) //Splits the text of a file at seperator and returns them in a list. /proc/file2list(filename, seperator="\n") diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 5f11d9f623..a86061aac6 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -184,7 +184,7 @@ if(type == "config") switch (name) if ("resource_urls") - config.resource_urls = stringsplit(value, " ") + config.resource_urls = text2list(value, " ") if ("admin_legacy_system") config.admin_legacy_system = 1 diff --git a/code/datums/diseases/advance/advance.dm b/code/datums/diseases/advance/advance.dm index 95adc92dcc..376df93678 100644 --- a/code/datums/diseases/advance/advance.dm +++ b/code/datums/diseases/advance/advance.dm @@ -297,7 +297,7 @@ var/list/advance_cures = list( for(var/datum/symptom/S in symptoms) L += S.id L = sortList(L) // Sort the list so it doesn't matter which order the symptoms are in. - var/result = dd_list2text(L, ":") + var/result = list2text(L, ":") id = result return result diff --git a/code/game/machinery/computer/buildandrepair.dm b/code/game/machinery/computer/buildandrepair.dm index 7dca0ae01f..61784e98c3 100644 --- a/code/game/machinery/computer/buildandrepair.dm +++ b/code/game/machinery/computer/buildandrepair.dm @@ -262,7 +262,7 @@ if(locked) user << "\red Circuit controls are locked." return - var/existing_networks = dd_list2text(network,",") + var/existing_networks = list2text(network,",") var/input = strip_html(input(usr, "Which networks would you like to connect this camera console circuit to? Seperate networks with a comma. No Spaces!\nFor example: SS13,Security,Secret ", "Multitool-Circuitboard interface", existing_networks)) if(!input) usr << "No input found please hang up and try your call again." diff --git a/code/game/objects/items/blueprints.dm b/code/game/objects/items/blueprints.dm index 4e7ae4d648..5c5b1b6fd8 100644 --- a/code/game/objects/items/blueprints.dm +++ b/code/game/objects/items/blueprints.dm @@ -1,6 +1,6 @@ /obj/item/blueprints name = "station blueprints" - desc = "Blueprints of the station. There's stamp \"Classified\" and several coffee stains on it." + desc = "Blueprints of the station. There is a \"Classified\" stamp and several coffee stains on it." icon = 'icons/obj/items.dmi' icon_state = "blueprints" attack_verb = list("attacked", "bapped", "hit") @@ -21,7 +21,7 @@ /obj/item/blueprints/attack_self(mob/M as mob) if (!istype(M,/mob/living/carbon/human)) - M << "This is stack of useless pieces of harsh paper." //monkeys cannot into projecting + M << "This stack of blue paper means nothing to you." //monkeys cannot into projecting return interact() return @@ -53,18 +53,18 @@ switch (get_area_type()) if (AREA_SPACE) text += {" -
According this blueprints you are in open space now.
+According the blueprints, you are now in outer space. Hold your breath.
"} if (AREA_STATION) text += {" -According this blueprints you are in [A.name] now.
+According the blueprints, you are now in \"[A.name]\".
You may move an amendment to the drawing.
"} if (AREA_SPECIAL) text += {" -This place isn't noted on these blueprints.
+This place isn't noted on the blueprint.
"} else return @@ -105,20 +105,20 @@ move an amendment to the drawing. if(!istype(res,/list)) switch(res) if(ROOM_ERR_SPACE) - usr << "\red New area must be complete airtight!" + usr << "\red The new area must be completely airtight!" return if(ROOM_ERR_TOOLARGE) - usr << "\red New area too large!" + usr << "\red The new area too large!" return else usr << "\red Error! Please notify administration!" return var/list/turf/turfs = res - var/str = trim(stripped_input(usr,"New area title","Blueprints editing", "", MAX_NAME_LEN)) + var/str = trim(stripped_input(usr,"New area name:","Blueprint Editing", "", MAX_NAME_LEN)) if(!str || !length(str)) //cancel return if(length(str) > 50) - usr << "\red Text too long." + usr << "\red Name too long." return var/area/A = new A.name = str @@ -153,8 +153,8 @@ move an amendment to the drawing. /obj/item/blueprints/proc/edit_area() var/area/A = get_area() //world << "DEBUG: edit_area" - var/prevname = A.name - var/str = trim(stripped_input(usr,"New area title","Blueprints editing", prevname, MAX_NAME_LEN)) + var/prevname = "[A.name]" + var/str = trim(stripped_input(usr,"New area name:","Blueprint Editing", prevname, MAX_NAME_LEN)) if(!str || !length(str) || str==prevname) //cancel return if(length(str) > 50) diff --git a/code/game/objects/items/devices/uplinks.dm b/code/game/objects/items/devices/uplinks.dm index 8f6fd0f632..b02fc79891 100644 --- a/code/game/objects/items/devices/uplinks.dm +++ b/code/game/objects/items/devices/uplinks.dm @@ -35,7 +35,7 @@ A list of items and costs is stored under the datum of every game mode, alongsid /obj/item/device/uplink/proc/generate_nanoui_items() var/items_nano[0] for(var/D in ItemList) - var/list/O = stringsplit(D, ":") + var/list/O = text2list(D, ":") if(O.len != 3) //If it is not an actual item, make a break in the menu. if(O.len == 1) //If there is one item, it's probably a title items_nano[++items_nano.len] = list("Category" = "[O[1]]", "items" = list()) @@ -53,7 +53,7 @@ A list of items and costs is stored under the datum of every game mode, alongsid else var/itemname = O[3] items_nano[items_nano.len]["items"] += list(list("Name" = itemname, "Cost" = cost, "obj_path" = path_text)) - + return items_nano @@ -62,7 +62,7 @@ A list of items and costs is stored under the datum of every game mode, alongsid //Halfassed fix for href exploit ~Z for(var/D in ItemList) - var/list/O = stringsplit(D, ":") + var/list/O = text2list(D, ":") if(O.len>0) valid_items += O[1] @@ -83,7 +83,7 @@ A list of items and costs is stored under the datum of every game mode, alongsid var/category_items = 1 //To prevent stupid :P for(var/D in ItemList) - var/list/O = stringsplit(D, ":") + var/list/O = text2list(D, ":") if(O.len != 3) //If it is not an actual item, make a break in the menu. if(O.len == 1) //If there is one item, it's probably a title dat += "[O[1]]