Short: new efun substitute_string() From: Dave Setty <garpoz@locallink.net> Date: Thu, 10 Dec 1998 02:03:04 -0500 Type: Feature State: Unclassified See also: f-020404 I've also got some various patches around that I'd like to see in there. Lars, if you're interested in any of this let me know... 1) subst(), which is similar to MudOS's replace_string() which in turn is a more refined version of the old implode(explode()) trick. Mine can take two arrays or a mapping of search/replace pairs though. --- Doomdark: If I'm not mistaken, this is similar to 'substitute_string()'-efun I made, which takes 2 string arrays to define the strings to replace. It can be found from 'bugs/doomdark/strutil.c'-file from the ldmud-3.2.5 if you are interested. The extra arguments (min and max length of the aliases to substitute) are just for optimizing the speed; also, the first array is expeceted to be sorted to allow binary search of the substitutions. Finally, the substitution is done by scanning the whole string just once, and by using a static replace buffer (no mallocs except for one used for mallocing room for the returned string, _if_ any substitutions were made). All in all, I tried to do a somewhat optimized version which could be used for alias subsitution in command strings; since this is called for every command players enter, it should be made as fast as possible. ---- Suggestion by Matthew Julius: varargs string strsubst(string, string|mapping|string*, string|string*) String replacement/substitution... Examples, strsubst("abc", "ab", "1") == "1c" strsubst("abc", ({ "a", "b" }), ({ "1", "2" })) == "12c" strsubst("abc", ([ "a": "1" ])) == "1bc" strsubst("abc", ({ "d" }), ({ "1" })) == "abc" The Timewarp mudlib has historically called this subst().