string utilities #20

Parent #79Owner #2Flags obsolete1, readSource QuestCore.db

Aliases: string utilities, string, utils

74 verbs · 11 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
space(noansi)this none thisrxd#2024
left(noansi)this none thisrxd#2013
right(noansi)this none thisrxd#2013
centre centerthis none thisrxd#2013
columnize columnisethis none thisrxd#2017
from_listthis none thisrxd#2014
english_listthis none thisrxd#2024
names_ofthis none thisrxd#208
from_secondsthis none thisrxd#2030
trimthis none thisrxd#206
trimlthis none thisrxd#206
trimrthis none thisrxd#205
strip_charsthis none thisrxd#206
strip_all_butthis none thisrxd#2011
uppercase lowercasethis none thisrxd#2013
capitalize capitalisethis none thisrxd#205
literal_objectthis none thisrxd#2027
matchthis none thisrxd#2038
match_str*ingthis none thisrxd#2040
match_objectthis none thisrxd#2020
match_playerthis none thisrxd#2034
match_player_or_objectthis none thisrxd#2024
find_prefixthis none thisrxd#2013
index_d*elimitedthis none thisrxd#203
is_integer is_numericthis none thisrxd#2018
ordinalthis none thisrxd#208
group_numberthis none thisrxd#2012
english_numberthis none thisrxd#2028
english_ordinalthis none thisrxd#2019
english_onesthis none thisrxd#203
english_tensthis none thisrxd#2010
subst*itutethis none thisrxd#2048
substitute_d*elimitednone none nonerxd#2044
_cap_propertythis none thisrxd#2029
pronoun_subthis none thisrxd#2078
pronoun_sub_securethis none thisrxd#209
pronoun_quotethis none thisrxd#2023
alt_pronoun_subnone none nonerxd#2076
explodethis none thisrxd#2014
wordsthis none thisrxd#2034
word_startthis none thisrxd#2028
to_valuethis none thisrxd#2014
prefix_to_valuethis none thisrxd#2023
_tolistthis none thisrxd#2035
_unquotethis none thisrxd#2015
_toscalarthis none thisrxd#2021
parse_commandthis none thisrxd#2040
from_valuethis none thisrxd#2036
print print_suspendedthis none thisrxd#2021
reversethis none thisrxd#2013
char_listthis none thisrxd#2011
regexp_quotethis none thisrxd#209
connection_hostname_bsdthis none thisrxd#203
connection_hostnamethis none thisrxd#202
from_value_suspendedthis none thisrxd#2040
end_expressionthis none thisrxd#2042
first_wordthis none thisrxd#2030
commonthis none thisrxd#2013
title_list*c list_title*cthis none thisrxd#2014
name_and_number nn name_and_number_list nn_listthis none thisrxd#2013
columnize_suspended columnise_suspendedthis none thisrxd#2018
a_or_anthis none thisrxd#2025
index_allthis none thisrxd#2016
match_stringlist match_string_listthis none thisrx#2038
from_ASCIIthis none thisrxd#205
to_ASCIIthis none thisrxd#204
abbreviated_valuethis none thisrxd#2014
_abbreviated_valuethis none thisrxd#2069
match_suspendedthis none thisrxd#2040
incr_alphathis none thisrxd#2011
is_floatthis none thisrxd#204
redirect_ansi left right center centre columnize columnise spacethis none thisrx#207
get_say_verb_prepthis none thisrxd#2011
get_say_verbthis none thisrxd#2064

Properties

PropertyDefinerFlagsOwnerValue
digits#20rc#2"0123456789"
ascii#20rc#2" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
alphabet#20rc#2"abcdefghijklmnopqrstuvwxyz"
use_article_a#20r#36{"unit", "unix", "one", "once", "utility"}
use_article_an#20r#36{}
tab#20rc#2"\t"
help_msg#79rc#2
list of 99{"For a complete description of a given verb, do `help $string_utils:verbname'", "", " Conversion routines:", "", ":from_list (list [,sep]) => \"foo1foo2foo3\"", ":english_list (str-list[,none-str[,and-str[, sep]]]) => \"foo1, foo2, and foo3\"", ":title_list*c (obj-list[,none-str[,and-str[, sep]]]) => \"foo1, foo2, and foo3\"", " or => \"Foo1, foo2, and foo3\"", ":from_value (value [,quoteflag [,maxlistdepth]]) => \"{foo1, foo2, foo3}\"", ":print (value) => value in string", ":abbreviated_value (value, options) => short value in string", "", ":to_value (string) => {success?, value or error message}", ":prefix_to_value(string) => {rest of string, value} or {0, error message}", "", ":english_number(42) => \"forty-two\"", ":english_ordinal(42) => \"forty-second\"", ":ordinal(42) => \"42nd\"", ":group_number(42135 [,sep]) => \"42,135\"", ":from_ASCII(65) => \"A\"", ":to_ASCII(\"A\") => 65", ":from_seconds(number) => string of rough time passed in large increments", "", ":name_and_number(obj [,sep]) => \"ObjectName (#obj)\"", ":name_and_number_list({obj1,obj2} [,sep])", " => \"ObjectName1 (#obj1) and ObjectName2 (#obj2)\"", ":nn is an alias for :name_and_number.", ":nn_list is an alias for :name_and_number_list.", "", " Type checking:", "", ":is_integer (string) => return true if string is composed entirely of digits", ":is_float (string) => return true if string holds just a floating point", "", " Parsing:", "", ":explode (string,char) -- string => list of words delimited by char", ":words (string) -- string => list of words (as with command line parser)", ":word_start (string) -- string => list of start-end pairs.", ":first_word (string) -- string => list {first word, rest of string} or {}", ":char_list (string) -- string => list of characters in string", "", ":parse_command (cmd_line [,player] => mimics action of builtin parser", "", " Matching:", "", ":find_prefix (prefix, string-list)=>list index of element starting with prefix", ":index_delimited(string,target[,case]) =>index of delimited string occurrence", ":index_all (string, target string) => list of all matched positions", ":common (first string, second string) => length of longest common prefix", ":match (string, [obj-list, prop-name]+) => matching object", ":match_player (string-list[,me-object]) => list of matching players", ":match_object (string, location) => default object match...", ":match_player_or_object (string, location) => object then player matching", ":literal_object (string) => match against #xxx, $foo", ":match_stringlist (string, targets) => match against static strings", ":match_string (string, wildcard target,options)=> match against a wildcard", ":get_say_verb(string) => 3rd person 'says' synonym to match emoticons in string.", ":get_say_verb_prep(string) => A preposition to match a 'says' verb synonym.", "", " Pretty printing:", "", ":space (n/string[,filler]) => n spaces", ":left (string,width[,filler]) => left justified string in field ", ":right (string,width[,filler]) => right justified string in field", ":center/re (string,width[,lfiller[,rfiller]]) => centered string in field", ":columnize/se (list,n[,width]) => list of strings in n columns", "", " Substitutions", "", ":substitute (string,subst_list [,case]) -- general substitutions.", ":substitute_delimited (string,subst_list [,case])", " -- like subst, but uses index_delim", ":pronoun_sub (string/list[,who[,thing[,location]]])", " -- pronoun substitutions.", ":pronoun_sub_secure (string[,who[,thing[,location]]],default)", " -- substitute and check for names.", ":pronoun_quote (string/list/subst_list) -- quoting for pronoun substitutions.", "", " Miscellaneous string munging:", "", ":trim (string) => string with outside whitespace removed.", ":triml (string) => string with leading whitespace removed.", ":trimr (string) => string with trailing whitespace removed.", ":strip_chars (string,chars) => string with all chars in `chars' removed.", ":strip_all_but(string,chars) => string with all chars not in `chars' removed.", ":capitalize/se(string) => string with first letter capitalized.", ":uppercase/lowercase(string) => string with all letters upper or lowercase.", ":names_of (list of OBJ) => string with names and object numbers of items.", ":a_or_an (word) => \"a\" or \"an\" as appropriate for that word.", ":reverse (string) => \"gnirts\"", ":incr_alpha (string) => \"increments\" the string alphabetically", "", " A useful property:", "", ".alphabet => \"abcdefghijklmnopqrstuvwxyz\"", "", "Suspended versions (with _suspended at end of name) for", " :print :from_value :columnize/se :match"}
key#1c#2<clear>
aliases#1rc#2{"string utilities", "string", "utils"}
description#1rc#2{"This is the string utilities utility package. See `help $string_utils' for more details."}
object_size#1r#36{78106, 1539462952}

Ancestry

Ancestors (nearest first): #79 Generic Utilities Package#1 Root Class

Children: none

Call graph

calls n20_1 #20:left(noansi) n20_71 #20:redirect_ansi n20_1->n20_71 n20_2 #20:right(noansi) n20_2->n20_71 n20_3 #20:centre n20_3->n20_71 n20_4 #20:columnize n20_4->n20_71 n55_0 #55:make n20_4->n55_0 n20_7 #20:names_of n20_11 #20:trimr n20_7->n20_11 n20_16 #20:literal_object n59_2 #59:toobj n20_16->n59_2 n20_20 #20:match_player n20_16->n20_20 n46_10 #46:match_recipient n20_16->n46_10 n52_0 #52:has_property n20_16->n52_0 n20_20->n20_16 n37_0 #37:find n20_20->n37_0 n20_19 #20:match_object n20_19->n20_16 n20_21 #20:match_player_or_object n20_21->n20_20 n6_18 #6:tell n20_21->n6_18 n20_23 #20:index_d*elimited n20_51 #20:regexp_quote n20_23->n20_51 n20_27 #20:english_number n20_30 #20:english_tens n20_27->n20_30 n20_29 #20:english_ones n20_27->n20_29 n20_30->n20_29 n20_28 #20:english_ordinal n20_28->n20_27 n20_28->n20_30 n20_31 #20:subst*itute n55_6 #55:find_insert n20_31->n55_6 n20_32 #20:substitute_d*elimited n20_32->n55_6 n20_33 #20:_cap_property n20_33->n52_0 n20_33->n20_33 n20_6 #20:english_list n20_33->n20_6 n20_34 #20:pronoun_sub n20_34->n20_33 n20_35 #20:pronoun_sub_secure n20_35->n20_34 n20_37 #20:alt_pronoun_sub n20_37->n20_33 n52_2 #52:has_verb n20_37->n52_2 n20_39 #20:words n20_10 #20:triml n20_39->n20_10 n20_41 #20:to_value n20_41->n20_71 n20_43 #20:_tolist n20_41->n20_43 n20_43->n20_10 n20_45 #20:_toscalar n20_43->n20_45 n20_42 #20:prefix_to_value n20_42->n20_10 n20_42->n20_45 n59_3 #59:toerr n20_45->n59_3 n20_46 #20:parse_command n20_46->n20_19 n20_46->n20_39 n59_19 #59:get_prep n20_46->n59_19 n20_5 #20:from_list n20_46->n20_5 n59_18 #59:full_prep n20_46->n59_18 n59_17 #59:short_prep n20_46->n59_17 n20_47 #20:from_value n20_47->n20_47 n59_4 #59:error_name n20_47->n59_4 n20_48 #20:print n20_48->n59_4 n20_48->n20_48 n20_49 #20:reverse n20_49->n20_49

Showing 48 of 67 verbs; 19 not shown.

Source

space(noansi)

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"space(len,fill) returns a string of length abs(len) consisting of copies of fill.  If len is negative, fill is anchored on the right instead of the left.";
2{n, ?fill = " "} = args;
3if (typeof(n) == STR)
4n = length(n);
5endif
6if (n > 1000)
7"Prevent someone from crashing the moo with $string_utils:space($maxint)";
8return E_INVARG;
9endif
10if (" " != fill)
11fill = fill + fill;
12fill = fill + fill;
13fill = fill + fill;
14elseif ((n = abs(n)) < 70)
15return "                                                                      "[1..n];
16else
17fill = "                                                                      ";
18endif
19m = (n - 1) / length(fill);
20while (m)
21fill = fill + fill;
22m = m / 2;
23endwhile
24return (n > 0) ? fill[1..n] | fill[($ + 1) + n..$];

left(noansi)

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"$string_utils:left(string,width[,filler])";
2"";
3"Assures that <string> is at least <width> characters wide.  Returns <string> if it is at least that long, or else <string> followed by enough filler to make it that wide. If <width> is negative and the length of <string> is greater than the absolute value of <width>, then the <string> is cut off at <width>.";
4"";
5"The <filler> is optional and defaults to \" \"; it controls what is used to fill the resulting string when it is too short.  The <filler> is replicated as many times as is necessary to fill the space in question.";
6{text, len, ?fill = " "} = args;
7abslen = abs(len);
8out = tostr(text);
9if (length(out) < abslen)
10return out + this:space(length(out) - abslen, fill);
11else
12return (len > 0) ? out | out[1..abslen];
13endif

right(noansi)

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"$string_utils:right(string,width[,filler])";
2"";
3"Assures that <string> is at least <width> characters wide.  Returns <string> if it is at least that long, or else <string> preceded by enough filler to make it that wide. If <width> is negative and the length of <string> is greater than the absolute value of <width>, then <string> is cut off at <width> from the right.";
4"";
5"The <filler> is optional and defaults to \" \"; it controls what is used to fill the resulting string when it is too short.  The <filler> is replicated as many times as is necessary to fill the space in question.";
6{text, len, ?fill = " "} = args;
7abslen = abs(len);
8out = tostr(text);
9if ((lenout = length(out)) < abslen)
10return this:space(abslen - lenout, fill) + out;
11else
12return (len > 0) ? out | out[($ - abslen) + 1..$];
13endif

centre center

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:center(string,width[,lfiller[,rfiller]])";
2"";
3"Assures that <string> is at least <width> characters wide.  Returns <string> if it is at least that long, or else <string> preceded and followed by enough filler to make it that wide.  If <width> is negative and the length of <string> is greater than the absolute value of <width>, then the <string> is cut off at <width>.";
4"";
5"The <lfiller> is optional and defaults to \" \"; it controls what is used to fill the left part of the resulting string when it is too short.  The <rfiller> is optional and defaults to the value of <lfiller>; it controls what is used to fill the right part of the resulting string when it is too short.  In both cases, the filler is replicated as many times as is necessary to fill the space in question.";
6{text, len, ?lfill = " ", ?rfill = lfill} = args;
7out = tostr(text);
8abslen = abs(len);
9if (length(out) < abslen)
10return (this:space((abslen - length(out)) / 2, lfill) + out) + this:space(((abslen - length(out)) + 1) / -2, rfill);
11else
12return (len > 0) ? out | out[1..abslen];
13endif

columnize columnise

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"columnize (items, n [, width]) - Turn a one-column list of items into an n-column list. 'width' is the last character position that may be occupied; it defaults to a standard screen width. Example: To tell the player a list of numbers in three columns, do 'player:tell_lines ($string_utils:columnize ({1, 2, 3, 4, 5, 6, 7}, 3));'.";
2{items, n, ?width = 79} = args;
3height = ((length(items) + n) - 1) / n;
4items = {@items, @$list_utils:make((height * n) - length(items), "")};
5colwidths = {};
6for col in [1..n - 1]
7colwidths = listappend(colwidths, 1 - (((width + 1) * col) / n));
8endfor
9result = {};
10for row in [1..height]
11line = tostr(items[row]);
12for col in [1..n - 1]
13line = tostr(this:left(line, colwidths[col]), " ", items[row + (col * height)]);
14endfor
15result = listappend(result, line[1..min($, width)]);
16endfor
17return result;

from_list

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:from_list(list [, separator])";
2"Return a string being the concatenation of the string representations of the elements of LIST, each pair separated by the string SEPARATOR, which defaults to the empty string.";
3{thelist, ?separator = ""} = args;
4if (separator == "")
5return tostr(@thelist);
6elseif (thelist)
7result = tostr(thelist[1]);
8for elt in (listdelete(thelist, 1))
9result = tostr(result, separator, elt);
10endfor
11return result;
12else
13return "";
14endif

english_list

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Prints the argument (must be a list) as an english list, e.g. {1, 2, 3} is printed as \"1, 2, and 3\", and {1, 2} is printed as \"1 and 2\".";
2"Optional arguments are treated as follows:";
3"  Second argument is the string to use when the empty list is given.  The default is \"nothing\".";
4"  Third argument is the string to use in place of \" and \".  A typical application might be to use \" or \" instead.";
5"  Fourth argument is the string to use instead of a comma (and space).  Gary_Severn's deranged mind actually came up with an application for this.  You can ask him.";
6"  Fifth argument is a string to use after the penultimate element before the \" and \".  The default is to have a comma without a space.";
7{things, ?nothingstr = "nothing", ?andstr = " and ", ?commastr = ", ", ?finalcommastr = ","} = args;
8nthings = length(things);
9if (nthings == 0)
10return nothingstr;
11elseif (nthings == 1)
12return tostr(things[1]);
13elseif (nthings == 2)
14return tostr(things[1], andstr, things[2]);
15else
16ret = "";
17for k in [1..nthings - 1]
18if (k == (nthings - 1))
19commastr = finalcommastr;
20endif
21ret = tostr(ret, things[k], commastr);
22endfor
23return tostr(ret, andstr, things[nthings]);
24endif

names_of

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Return a string of the names and object numbers of the objects in a list.";
2line = "";
3for item in (args[1])
4if ((typeof(item) == OBJ) && valid(item))
5line = (((line + item.name) + "(") + tostr(item)) + ")   ";
6endif
7endfor
8return $string_utils:trimr(line);

from_seconds

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":from_seconds(number of seconds) => returns a string containing the rough increment of days, or hours if less than a day, or minutes if less than an hour, or lastly in seconds.";
2":from_seconds(86400) => \"a day\"";
3":from_seconds(7200)  => \"two hours\"";
4minute = 60;
5hour = 60 * minute;
6day = 24 * hour;
7secs = args[1];
8if (secs > day)
9count = secs / day;
10unit = "day";
11article = "a";
12elseif (secs > hour)
13count = secs / hour;
14unit = "hour";
15article = "an";
16elseif (secs > minute)
17count = secs / minute;
18unit = "minute";
19article = "a";
20else
21count = secs;
22unit = "second";
23article = "a";
24endif
25if (count == 1)
26time = tostr(article, " ", unit);
27else
28time = tostr(count, " ", unit, "s");
29endif
30return time;

trim

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":trim (string [, space]) -- remove leading and trailing spaces";
2"";
3"`space' should be a character (single-character string); it defaults to \" \".  Returns a copy of string with all leading and trailing copies of that character removed.  For example, $string_utils:trim(\"***foo***\", \"*\") => \"foo\".";
4{string, ?space = " "} = args;
5m = match(string, tostr("[^", space, "]%(.*[^", space, "]%)?%|$"));
6return string[m[1]..m[2]];

triml

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":triml(string [, space]) -- remove leading spaces";
2"";
3"`space' should be a character (single-character string); it defaults to \" \".  Returns a copy of string with all leading copies of that character removed.  For example, $string_utils:triml(\"***foo***\", \"*\") => \"foo***\".";
4{string, ?what = " "} = args;
5m = match(string, tostr("[^", what, "]%|$"));
6return string[m[1]..$];

trimr

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":trimr(string [, space]) -- remove trailing spaces";
2"";
3"`space' should be a character (single-character string); it defaults to \" \".  Returns a copy of string with all trailing copies of that character removed.  For example, $string_utils:trimr(\"***foo***\", \"*\") => \"***foo\".";
4{string, ?what = " "} = args;
5return string[1..rmatch(string, tostr("[^", what, "]%|^"))[2]];

strip_chars

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":strip_chars(string,chars) => string with chars removed";
2{subject, stripped} = args;
3for i in [1..length(stripped)]
4subject = strsub(subject, stripped[i], "");
5endfor
6return subject;

strip_all_but

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1":strip_all_but(string,keep) => string with chars not in `keep' removed.";
2"`keep' is used in match() so if it includes ], ^, or -,";
3"] should be first, ^ should be other from first, and - should be last.";
4string = args[1];
5wanted = ("[" + args[2]) + "]+";
6output = "";
7while (m = match(string, wanted))
8output = output + string[m[1]..m[2]];
9string = string[m[2] + 1..$];
10endwhile
11return output;

uppercase lowercase

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"lowercase(string) -- returns a lowercase version of the string.";
2"uppercase(string) -- returns the uppercase version of the string.";
3string = args[1];
4from = caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
5to = lower = "abcdefghijklmnopqrstuvwxyz";
6if (verb == "uppercase")
7from = lower;
8to = caps;
9endif
10for i in [1..26]
11string = strsub(string, from[i], to[i], 1);
12endfor
13return string;

capitalize capitalise

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"capitalizes its argument.";
2if ((string = args[1]) && (i = index("abcdefghijklmnopqrstuvwxyz", string[1], 1)))
3string[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i];
4endif
5return string;

literal_object

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Matches args[1] against literal objects: #xxxxx, $variables, *mailing-lists, and username.  Returns the object if successful, $failed_match else.";
2string = args[1];
3if (!string)
4return $nothing;
5elseif ((string[1] == "#") && (E_TYPE != (object = $code_utils:toobj(string))))
6return object;
7elseif (string[1] == "~")
8return this:match_player(string[2..$], #0);
9elseif ((string[1] == "*") && (length(string) > 1))
10return $mail_agent:match_recipient(string);
11elseif (string[1] == "$")
12string[1..1] = "";
13object = #0;
14while (pn = string[1..(dot = index(string, ".")) ? dot - 1 | $])
15if ((!$object_utils:has_property(object, pn)) || (typeof(object = object.(pn)) != OBJ))
16return $failed_match;
17endif
18string = string[length(pn) + 2..$];
19endwhile
20if ((object == #0) || (typeof(object) == ERR))
21return $failed_match;
22else
23return object;
24endif
25else
26return $failed_match;
27endif

match

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:match(string [, obj-list, prop-name]*)";
2"Each obj-list should be a list of objects or a single object, which is treated as if it were a list of that object.  Each prop-name should be string naming a property on every object in the corresponding obj-list.  The value of that property in each case should be either a string or a list of strings.";
3"The argument string is matched against all of the strings in the property values.";
4"If it exactly matches exactly one of them, the object containing that property is returned.  If it exactly matches more than one of them, $ambiguous_match is returned.";
5"If there are no exact matches, then partial matches are considered, ones in which the given string is a prefix of some property string.  Again, if exactly one match is found, the object with that property is returned, and if there is more than one match, $ambiguous_match is returned.";
6"Finally, if there are no exact or partial matches, then $failed_match is returned.";
7subject = args[1];
8if (subject == "")
9return $nothing;
10endif
11no_exact_match = no_partial_match = 1;
12for i in [1..length(args) / 2]
13prop_name = args[(2 * i) + 1];
14for object in ((typeof(olist = args[2 * i]) == LIST) ? olist | {olist})
15if (valid(object))
16if (typeof(str_list = `object.(prop_name) ! E_PERM, E_PROPNF => {}') != LIST)
17str_list = {str_list};
18endif
19if (subject in str_list)
20if (no_exact_match)
21no_exact_match = object;
22elseif (no_exact_match != object)
23return $ambiguous_match;
24endif
25else
26for string in (str_list)
27if (index(string, subject) != 1)
28elseif (no_partial_match)
29no_partial_match = object;
30elseif (no_partial_match != object)
31no_partial_match = $ambiguous_match;
32endif
33endfor
34endif
35endif
36endfor
37endfor
38return no_exact_match && (no_partial_match && $failed_match);

match_str*ing

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"* wildcard matching. Returns a list of what the *s actually matched. Won't cath every match, if there are several ways to parse it.";
2"Example: $string_utils:match_string(\"Jack waves to Jill\",\"* waves to *\") returns {\"Jack\", \"Jill\"}";
3"Optional arguments: numbers are interpreted as case-sensitivity, strings as alternative wildcards.";
4{what, targ, @rest} = args;
5wild = "*";
6case = ret = {};
7what = what + "&^%$";
8targ = targ + "&^%$";
9for y in (rest)
10if (typeof(y) == STR)
11wild = y;
12elseif (typeof(y) == INT)
13case = {y};
14endif
15endfor
16while (targ != "")
17if (z = index(targ, wild))
18part = targ[1..z - 1];
19else
20z = length(targ);
21part = targ;
22endif
23n = (part == "") ? 1 | index(what, part, @case);
24if (n)
25ret = listappend(ret, what[1..n - 1]);
26what = what[(z + n) - 1..$];
27targ = targ[z + 1..$];
28else
29return 0;
30endif
31endwhile
32if (ret == {})
33return what == "";
34elseif (ret == {""})
35return 1;
36elseif (ret[1] == "")
37return ret[2..$];
38else
39return 0;
40endif

match_object

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":match_object(string,location[,someone])";
2"Returns the object matching the given string for someone, on the assumption that s/he is in the given location.  `someone' defaults to player.";
3"This first tries :literal_object(string), \"me\"=>someone,\"here\"=>location, then player:match(string) and finally location:match(string) if location is valid.";
4"This is the default algorithm for use by room :match_object() and player :my_match_object() verbs.  Player verbs that are calling this directly should probably be calling :my_match_object instead.";
5{string, here, ?who = player} = args;
6if ($failed_match != (object = this:literal_object(string)))
7return object;
8elseif (string == "me")
9return who;
10elseif (string == "here")
11return here;
12elseif ((valid(pobject = who:match(string)) && (string in {@pobject.aliases, pobject.name})) || (!valid(here)))
13"...exact match in player or room is bogus...";
14return pobject;
15elseif ((valid(hobject = here:match(string)) && (string in {@hobject.aliases, hobject.name})) || (pobject == $failed_match))
16"...exact match in room or match in player failed completely...";
17return hobject;
18else
19return pobject;
20endif

match_player

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"match_player(name,name,...)      => {obj,obj,...}";
2"match_player(name[,meobj])       => obj";
3"match_player({name,...}[,meobj]) => {obj,...}";
4"objs returned are either players, $failed_match, $ambiguous_match, or $nothing in the case of an empty string.";
5"meobj (what to return for instances of `me') defaults to player; if given and isn't actually a player, `me' => $failed_match";
6retstr = 0;
7me = player;
8if ((length(args) < 2) || (typeof(me = args[2]) == OBJ))
9me = (valid(me) && is_player(me)) ? me | $failed_match;
10if (typeof(args[1]) == STR)
11strings = {args[1]};
12retstr = 1;
13"return a string, not a list";
14else
15strings = args[1];
16endif
17else
18strings = args;
19me = player;
20endif
21found = {};
22for astr in (strings)
23if (!astr)
24aobj = $nothing;
25elseif (astr == "me")
26aobj = me;
27elseif (valid(aobj = $string_utils:literal_object(astr)) && is_player(aobj))
28"astr is a valid literal object number of some player, so we are done.";
29else
30aobj = $player_db:find(astr);
31endif
32found = {@found, aobj};
33endfor
34return retstr ? found[1] | found;

match_player_or_object

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Accepts any number of strings, attempts to match those strings first against objects in the room, and if no objects by those names exist, matches against player names (and \"#xxxx\" style strings regardless of location).  Returns a list of valid objects so found.";
2"Unlike $string_utils:match_player, does not include in the list the failed and ambiguous matches; instead has built-in error messages for such objects.  This should probably be improved.  Volunteers?";
3if (!args)
4return;
5endif
6unknowns = {};
7objs = {};
8"We have to do something icky here.  Parallel walk the victims and args lists.  When it's a valid object, then it's a player.  If it's an invalid object, try to get an object match from the room.  If *that* fails, complain.";
9for i in [1..length(args)]
10if (valid(o = player.location:match_object(args[i])))
11objs = {@objs, o};
12else
13unknowns = {@unknowns, args[i]};
14endif
15endfor
16victims = $string_utils:match_player(unknowns);
17for i in [1..length(victims)]
18if (!valid(victims[i]))
19player:tell("Could not find ", unknowns[i], " as either an object or a player.");
20else
21objs = {@objs, victims[i]};
22endif
23endfor
24return objs;

find_prefix

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"find_prefix(prefix, string-list) => list index of something starting with prefix, or 0 or $ambiguous_match.";
2{subject, choices} = args;
3answer = 0;
4for i in [1..length(choices)]
5if (index(choices[i], subject) == 1)
6if (answer == 0)
7answer = i;
8else
9answer = $ambiguous_match;
10endif
11endif
12endfor
13return answer;

index_d*elimited

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"index_delimited(string,target[,case_matters]) is just like the corresponding call to the builtin index() but instead only matches on occurences of target delimited by word boundaries (i.e., not preceded or followed by an alphanumeric)";
2args[2] = ("%(%W%|^%)" + $string_utils:regexp_quote(args[2])) + "%(%W%|$%)";
3return (m = match(@args)) ? m[3][1][2] + 1 | 0;

is_integer is_numeric

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Usage:  is_numeric(string)";
2"        is_integer(string)";
3"Is string numeric (composed of one or more digits possibly preceded by a minus sign)? This won't catch floating points.";
4"Return true or false";
5return match(args[1], "^ *[-+]?[0-9]+ *$");
6digits = "1234567890";
7if (!(string = args[1]))
8return 0;
9endif
10if (string[1] == "-")
11string = string[2..length(string)];
12endif
13for i in [1..length(string)]
14if (!index(digits, string[i]))
15return 0;
16endif
17endfor
18return 1;

ordinal

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":short_ordinal(1) => \"1st\",:short_ordinal(2) => \"2nd\",etc...";
2string = tostr(n = args[1]);
3n = abs(n) % 100;
4if (((n / 10) != 1) && ((n % 10) in {1, 2, 3}))
5return string + {"st", "nd", "rd"}[n % 10];
6else
7return string + "th";
8endif

group_number

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:group_number(n [, sep_char])";
2"";
3"Converts N to a string, inserting commas (or copies of SEP_CHAR, if given) every three digits, counting from the right.  For example, $string_utils:group_number(1234567890) returns the string \"1,234,567,890\".";
4{n, ?comma = ","} = args;
5result = "";
6sign = (n < 0) ? "-" | "";
7n = tostr(abs(n));
8while (length(n) > 3)
9result = (comma + n[$ - 2..$]) + result;
10n = n[1..$ - 3];
11endwhile
12return (sign + n) + result;

english_number

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:english_number(n) -- convert the integer N into English";
2"";
3"Produces a string containing the English phrase naming the given integer.  For example, $string_utils:english_number(-1234) returns the string `negative one thousand two hundred thirty-four'.";
4numb = toint(args[1]);
5if (numb == 0)
6return "zero";
7endif
8labels = {"", " thousand", " million", " billion"};
9numstr = "";
10mod = abs(numb);
11for n in [1..4]
12div = mod % 1000;
13if (div)
14hun = div / 100;
15ten = div % 100;
16outstr = this:english_tens(ten) + labels[n];
17if (hun)
18outstr = ((this:english_ones(hun) + " hundred") + (ten ? " " | "")) + outstr;
19endif
20if (numstr)
21numstr = (outstr + " ") + numstr;
22else
23numstr = outstr;
24endif
25endif
26mod = mod / 1000;
27endfor
28return ((numb < 0) ? "negative " | "") + numstr;

english_ordinal

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"$string_utils:english_ordinal(n) -- convert the integer N into an english ordinal (1 => \"first\", etc...)";
2numb = toint(args[1]);
3if (numb == 0)
4return "zeroth";
5elseif (numb % 100)
6hundreds = (abs(numb) > 100) ? this:english_number((numb / 100) * 100) + " " | ((numb < 0) ? "negative " | "");
7numb = abs(numb) % 100;
8specials = {1, 2, 3, 5, 8, 9, 12, 20, 30, 40, 50, 60, 70, 80, 90};
9ordinals = {"first", "second", "third", "fifth", "eighth", "ninth", "twelfth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth", "seventieth", "eightieth", "ninetieth"};
10if (i = numb in specials)
11return hundreds + ordinals[i];
12elseif ((numb > 20) && (i = (numb % 10) in specials))
13return ((hundreds + this:english_tens((numb / 10) * 10)) + "-") + ordinals[i];
14else
15return (hundreds + this:english_number(numb)) + "th";
16endif
17else
18return this:english_number(numb) + "th";
19endif

english_ones

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1numb = args[1];
2ones = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
3return ones[numb + 1];

english_tens

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1numb = args[1];
2teens = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
3others = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
4if (numb < 10)
5return this:english_ones(numb);
6elseif (numb < 20)
7return teens[numb - 9];
8else
9return (others[(numb / 10) - 1] + ((numb % 10) ? "-" | "")) + this:english_ones(numb % 10);
10endif

subst*itute

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"subst(string,{{redex1,repl1},{redex2,repl2},{redex3,repl3}...}[,case])";
2"  => returns string with all instances of the strings redex<n> replaced respectively by the strings repl<n>.  If the optional argument `case' is given and nonzero, the search for instances of redex<n> is case sensitive.";
3"  Substitutions are done in parallel, i.e., instances of redex<n> that appear in any of the replacement strings are ignored.  In the event that two redexes overlap, whichever is leftmost in `string' takes precedence.  For two redexes beginning at the same position, the longer one takes precedence.";
4"";
5"subst(\"hoahooaho\",{{\"ho\",\"XhooX\"},{\"hoo\",\"mama\"}}) => \"XhooXamamaaXhooX\"";
6"subst(\"Cc: banana\",{{\"a\",\"b\"},{\"b\",\"c\"},{\"c\",\"a\"}},1) => \"Ca: cbnbnb\"";
7{ostr, subs, ?case = 0} = args;
8if (typeof(ostr) != STR)
9return ostr;
10endif
11len = length(ostr);
12" - - - find the first instance of each substitution - -";
13indices = {};
14substs = {};
15for s in (subs)
16if (i = index(ostr, s[1], case))
17fi = $list_utils:find_insert(indices, i = i - len) - 1;
18while (fi && ((indices[fi] == i) && (length(substs[fi][1]) < length(s[1]))))
19"...give preference to longer redexes...";
20fi = fi - 1;
21endwhile
22indices = listappend(indices, i, fi);
23substs = listappend(substs, s, fi);
24endif
25endfor
26"- - - - - perform substitutions - ";
27nstr = "";
28while (substs)
29ind = len + indices[1];
30sub = substs[1];
31indices = listdelete(indices, 1);
32substs = listdelete(substs, 1);
33if (ind > 0)
34nstr = (nstr + ostr[1..ind - 1]) + sub[2];
35ostr = ostr[ind + length(sub[1])..len];
36len = length(ostr);
37endif
38if (next = index(ostr, sub[1], case))
39fi = $list_utils:find_insert(indices, next = next - len) - 1;
40while (fi && ((indices[fi] == next) && (length(substs[fi][1]) < length(sub[1]))))
41"...give preference to longer redexes...";
42fi = fi - 1;
43endwhile
44indices = listappend(indices, next, fi);
45substs = listappend(substs, sub, fi);
46endif
47endwhile
48return nstr + ostr;

substitute_d*elimited

Spec none none noneFlags rxdOwner #2Definer #20

Referenced by

none

Source

1"subst(string,{{redex1,repl1},{redex2,repl2},{redex3,repl3}...}[,case])";
2"Just like :substitute() but it uses index_delimited() instead of index()";
3{ostr, subs, ?case = 0} = args;
4if (typeof(ostr) != STR)
5return ostr;
6endif
7len = length(ostr);
8" - - - find the first instance of each substitution - -";
9indices = {};
10substs = {};
11for s in (subs)
12if (i = this:index_delimited(ostr, s[1], case))
13fi = $list_utils:find_insert(indices, i = i - len) - 1;
14while (fi && ((indices[fi] == i) && (length(substs[fi][1]) < length(s[1]))))
15"...give preference to longer redexes...";
16fi = fi - 1;
17endwhile
18indices = listappend(indices, i, fi);
19substs = listappend(substs, s, fi);
20endif
21endfor
22"- - - - - perform substitutions - ";
23nstr = "";
24while (substs)
25ind = len + indices[1];
26sub = substs[1];
27indices = listdelete(indices, 1);
28substs = listdelete(substs, 1);
29if (ind > 0)
30nstr = (nstr + ostr[1..ind - 1]) + sub[2];
31ostr = ostr[ind + length(sub[1])..len];
32len = length(ostr);
33endif
34if (next = this:index_delimited(ostr, sub[1], case))
35fi = $list_utils:find_insert(indices, next = next - len) - 1;
36while (fi && ((indices[fi] == next) && (length(substs[fi][1]) < length(sub[1]))))
37"...give preference to longer redexes...";
38fi = fi - 1;
39endwhile
40indices = listappend(indices, next, fi);
41substs = listappend(substs, sub, fi);
42endif
43endwhile
44return nstr + ostr;

_cap_property

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

Source

1"cap_property(what,prop[,ucase]) returns what.(prop) but capitalized if either ucase is true or the prop name specified is capitalized.";
2"If prop is blank, returns what:title().";
3"If prop is bogus or otherwise irretrievable, returns the error.";
4"If capitalization is indicated, we return what.(prop+\"c\") if that exists, else we capitalize what.(prop) in the usual fashion.  There is a special exception for is_player(what)&&prop==\"name\" where we just return what.name if no .namec is provided --- ie., a player's .name is never capitalized in the usual fashion.";
5"If args[1] is a list, calls itself on each element of the list and returns $string_utils:english_list(those results).";
6{what, prop, ?ucase = 0} = args;
7set_task_perms(caller_perms());
8if (typeof(what) == LIST)
9result = {};
10for who in (what)
11result = {@result, this:_cap_property(who, prop, ucase)};
12endfor
13return $string_utils:english_list(result);
14endif
15ucase = (prop && (strcmp(prop, "a") < 0)) || ucase;
16if (!prop)
17return valid(what) ? ucase ? what:titlec() | what:title() | ((ucase ? "N" | "n") + "othing");
18elseif ((!ucase) || (typeof(s = `what.(prop + "c") ! ANY') == ERR))
19if (prop == "name")
20s = valid(what) ? what.name | "nothing";
21ucase = ucase && (!is_player(what));
22else
23s = `$object_utils:has_property(what, prop) ? what.(prop) | $player.(prop) ! ANY';
24endif
25if (ucase && (s && ((typeof(s) == STR) && (((z = index(this.alphabet, s[1], 1)) < 27) && (z > 0)))))
26s[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[z];
27endif
28endif
29return (typeof(s) == ERR) ? s | tostr(s);

pronoun_sub

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

Source

1"Pronoun (and other things) substitution. See 'help pronouns' for details.";
2"syntax:  $string_utils:pronoun_sub(text[,who[,thing[,location[,dobj[,iobj]]]]])";
3"%s,%o,%p,%q,%r    => <who>'s pronouns.  <who> defaults to player.";
4"%n,%d,%i,%t,%l,%% => <who>, dobj, iobj, <thing>, location and %";
5"<thing> defaults to caller; <location> defaults to who.location";
6"%S,%O,%P,%Q,%R, %N,%D,%I,%T,%L have corresponding capitalized substitutions.";
7" %[#n], %[#d], ...  =>  <who>, dobj, etc.'s object number";
8"%(foo) => <who>.foo and %(Foo) => <who>.foo capitalized. %[dfoo] => dobj.foo, etc..";
9"%<foo> -> whatever <who> does when normal people foo. This is determined by calling :verb_sub() on the <who>.";
10"%<d:foo> -> whatever <dobj> does when normal people foo.";
11{string, ?who = player, ?thing = caller, ?where = $nothing, ?dobject = dobj, ?iobject = iobj} = args;
12where = valid(where) ? where | (valid(who) ? who.location | where);
13set_task_perms($no_one);
14if (typeof(string) == LIST)
15plines = {};
16for line in (string)
17plines = {@plines, this:(verb)(line, who, thing, where)};
18endfor
19return plines;
20endif
21old = tostr(string);
22new = "";
23objspec = "nditl";
24objects = {who, dobject, iobject, thing, where};
25prnspec = "sopqrSOPQR";
26prprops = {"ps", "po", "pp", "pq", "pr", "Ps", "Po", "Pp", "Pq", "Pr"};
27oldlen = length(old);
28while ((prcnt = index(old, "%")) && (prcnt < oldlen))
29s = old[k = prcnt + 1];
30if ((s == "<") && (gt = index(old[k + 2..$], ">")))
31"handling %<verb> ";
32gt = (gt + k) + 1;
33vb = old[k + 1..gt - 1];
34vbs = who;
35if ((length(vb) > 2) && (vb[2] == ":"))
36" %<d:verb>";
37vbs = objects[index(objspec, vb[1]) || 1];
38vb = vb[3..$];
39endif
40vb = `vbs:verb_sub(vb) ! E_VERBNF => this:(verb)(vb, vbs)';
41new = (new + old[1..prcnt - 1]) + vb;
42k = gt;
43else
44cp_args = {};
45if (brace = index("([", s))
46if (!(w = index(old[k + 1..oldlen], ")]"[brace])))
47return new + old;
48else
49p = old[prcnt + 2..(k = k + w) - 1];
50if (brace == 1)
51"%(property)";
52cp_args = {who, p};
53elseif (p[1] == "#")
54"%[#n] => object number";
55s = (o = index(objspec, p[2])) ? tostr(objects[o]) | (("[" + p) + "]");
56elseif (!(o = index(objspec, p[1])))
57s = ("[" + p) + "]";
58else
59" %[dproperty] ";
60cp_args = {objects[o], p[2..w - 1], strcmp(p[1], "a") < 0};
61endif
62endif
63elseif (o = index(objspec, s))
64cp_args = {objects[o], "", strcmp(s, "a") < 0};
65elseif (w = index(prnspec, s, 1))
66cp_args = {who, prprops[w]};
67elseif (s == "#")
68s = tostr(who);
69elseif (s != "%")
70s = "%" + s;
71endif
72new = (new + old[1..prcnt - 1]) + ((!cp_args) ? s | ((typeof(sub = $string_utils:_cap_property(@cp_args)) != ERR) ? sub | (("%(" + tostr(sub)) + ")")));
73endif
74old = old[k + 1..oldlen];
75oldlen = oldlen - k;
76(ticks_left() < 4000) && suspend(0);
77endwhile
78return new + old;

pronoun_sub_secure

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:pronoun_sub_secure(string[,who[,thing[,location]]], default)";
2"Do pronoun_sub on string with the arguments given (see help";
3"string_utils:pronoun_sub for more information).  Return pronoun_subbed";
4"<default> if the subbed string does not contain <who>.name (<who>";
5"defaults to player).";
6who = (length(args) > 2) ? args[2] | player;
7default = args[$];
8result = this:pronoun_sub(@args[1..$ - 1]);
9return this:index_delimited(result, who.name) ? result | this:pronoun_sub(@{default, @args[2..$ - 1]});

pronoun_quote

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1" pronoun_quote(string) => quoted_string";
2" pronoun_quote(list of strings) => list of quoted_strings";
3" pronoun_quote(list of {key,string} pairs) => list of {key,quoted_string} pairs";
4"";
5"Here `quoted' means quoted in the sense of $string_utils:pronoun_sub, i.e., given a string X, the corresponding `quoted' string Y is such that pronoun_sub(Y) => X.  For example, pronoun_quote(\"--%Spam%--\") => \"--%%Spam%%--\".  This is for including literal text into a string that will eventually be pronoun_sub'ed, i.e., including it in such a way that the pronoun_sub will not expand anything in the included text.";
6"";
7"The 3rd form above (with {key,string} pairs) is for use with $string_utils:substitute().  If you have your own set of substitutions to be done in parallel with the pronoun substitutions, do";
8"";
9"  msg=$string_utils:substitute(msg,$string_utils:pronoun_quote(your_substs));";
10"  msg=$string_utils:pronoun_sub(msg);";
11if (typeof(what = args[1]) == STR)
12return strsub(what, "%", "%%");
13else
14ret = {};
15for w in (what)
16if (typeof(w) == LIST)
17ret = listappend(ret, listset(w, strsub(w[2], "%", "%%"), 2));
18else
19ret = listappend(ret, strsub(w, "%", "%%"));
20endif
21endfor
22return ret;
23endif

alt_pronoun_sub

Spec none none noneFlags rxdOwner #2Definer #20

Referenced by

none

Source

1"Pronoun (and other things) substitution. See 'help pronouns' for details.";
2"syntax:  $string_utils:pronoun_sub(text[,who[,thing[,location]]])";
3"%s,%o,%p,%q,%r    => <who>'s pronouns.  <who> defaults to player.";
4"%n,%d,%i,%t,%l,%% => <who>, dobj, iobj, this, <who>.location and %";
5"%S,%O,%P,%Q,%R, %N,%D,%I,%T,%L have corresponding capitalized substitutions.";
6" %[#n], %[#d], ...  =>  <who>, dobj, etc.'s object number";
7"%(foo) => <who>.foo and %(Foo) => <who>.foo capitalized. %[dfoo] => dobj.foo, etc..";
8"%<foo> -> whatever <who> does when normal people foo. This is determined by calling :verb_sub() on the <who>.";
9"%<d:foo> -> whatever <dobj> does when normal people foo.";
10set_task_perms($no_one);
11{string, ?who = player, ?thing = caller, ?where = $nothing} = args;
12where = valid(who) ? who.location | where;
13if (typeof(string) == LIST)
14plines = {};
15for line in (string)
16plines = {@plines, this:(verb)(line, who, thing, where)};
17endfor
18return plines;
19endif
20old = tostr(string);
21new = "";
22objspec = "nditl";
23objects = {who, dobj, iobj, thing, where};
24prnspec = "sopqrSOPQR";
25prprops = {"ps", "po", "pp", "pq", "pr", "Ps", "Po", "Pp", "Pq", "Pr"};
26oldlen = length(old);
27while ((prcnt = index(old, "%")) && (prcnt < oldlen))
28s = old[k = prcnt + 1];
29if ((s == "<") && (gt = index(old[k + 2..$], ">")))
30"handling %<verb> ";
31gt = (gt + k) + 1;
32vb = old[k + 1..gt - 1];
33vbs = who;
34if ((length(vb) > 2) && (vb[2] == ":"))
35" %<d:verb>";
36vbs = objects[index(objspec, vb[1]) || 1];
37vb = vb[3..$];
38endif
39vb = $object_utils:has_verb(vbs, "verb_sub") ? vbs:verb_sub(vb) | this:(verb)(vb, vbs);
40new = (new + old[1..prcnt - 1]) + vb;
41k = gt;
42else
43cp_args = {};
44if (brace = index("([", s))
45if (!(w = index(old[k + 1..oldlen], ")]"[brace])))
46return new + old;
47else
48p = old[prcnt + 2..(k = k + w) - 1];
49if (brace == 1)
50"%(property)";
51cp_args = {who, p};
52elseif (p[1] == "#")
53"%[#n] => object number";
54s = (o = index(objspec, p[2])) ? tostr(objects[o]) | (("[" + p) + "]");
55elseif (!(o = index(objspec, p[1])))
56s = ("[" + p) + "]";
57else
58" %[dproperty] ";
59cp_args = {objects[o], p[2..w - 1], strcmp(p[1], "a") < 0};
60endif
61endif
62elseif (o = index(objspec, s))
63cp_args = {objects[o], "", strcmp(s, "a") < 0};
64elseif (w = index(prnspec, s, 1))
65cp_args = {who, prprops[w]};
66elseif (s == "#")
67s = tostr(who);
68elseif (s != "%")
69s = "%" + s;
70endif
71new = (new + old[1..prcnt - 1]) + ((!cp_args) ? s | ((typeof(sub = $string_utils:_cap_property(@cp_args)) != ERR) ? sub | (("%(" + tostr(sub)) + ")")));
72endif
73old = old[k + 1..oldlen];
74oldlen = oldlen - k;
75endwhile
76return new + old;

explode

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:explode(subject [, break])";
2"Return a list of those substrings of subject separated by runs of break[1].";
3"break defaults to space.";
4{subject, ?breakit = {" "}} = args;
5breakit = breakit[1];
6subject = subject + breakit;
7parts = {};
8while (subject)
9if ((i = index(subject, breakit)) > 1)
10parts = {@parts, subject[1..i - 1]};
11endif
12subject = subject[i + 1..$];
13endwhile
14return parts;

words

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"This breaks up the argument string into words, the resulting list being obtained exactly the way the command line parser obtains `args' from `argstr'.";
2rest = args[1];
3"...trim leading blanks...";
4if (0)
5rest[1..match(rest, "^ *")[2]] = "";
6endif
7rest = $string_utils:triml(rest);
8if (!rest)
9return {};
10endif
11quote = 0;
12toklist = {};
13token = "";
14pattern = " +%|\\.?%|\"";
15while (m = match(rest, pattern))
16"... find the next occurence of a special character, either";
17"... a block of spaces, a quote or a backslash escape sequence...";
18char = rest[m[1]];
19token = token + rest[1..m[1] - 1];
20if (char == " ")
21toklist = {@toklist, token};
22token = "";
23elseif (char == "\"")
24"... beginning or end of quoted string...";
25"... within a quoted string spaces aren't special...";
26pattern = (quote = !quote) ? "\\.?%|\"" | " +%|\\.?%|\"";
27elseif (m[1] < m[2])
28"... char has to be a backslash...";
29"... include next char literally if there is one";
30token = token + rest[m[2]];
31endif
32rest[1..m[2]] = "";
33endwhile
34return (rest || (char != " ")) ? {@toklist, token + rest} | toklist;

word_start

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"This breaks up the argument string into words, returning a list of indices into argstr corresponding to the starting points of each of the arguments.";
2rest = args[1];
3"... find first nonspace...";
4wstart = match(rest, "[^ ]%|$")[1];
5wbefore = wstart - 1;
6rest[1..wbefore] = "";
7if (!rest)
8return {};
9endif
10quote = 0;
11wslist = {};
12pattern = " +%|\\.?%|\"";
13while (m = match(rest, pattern))
14"... find the next occurence of a special character, either";
15"... a block of spaces, a quote or a backslash escape sequence...";
16char = rest[m[1]];
17if (char == " ")
18wslist = {@wslist, {wstart, (wbefore + m[1]) - 1}};
19wstart = (wbefore + m[2]) + 1;
20elseif (char == "\"")
21"... beginning or end of quoted string...";
22"... within a quoted string spaces aren't special...";
23pattern = (quote = !quote) ? "\\.?%|\"" | " +%|\\.?%|\"";
24endif
25rest[1..m[2]] = "";
26wbefore = wbefore + m[2];
27endwhile
28return (rest || (char != " ")) ? {@wslist, {wstart, wbefore + length(rest)}} | wslist;

to_value

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":to_value(string) tries to parse string as a value (i.e., object, number, string, error, or list thereof).";
2"Returns {1,value} or {0,error_message} according as the attempt was successful or not.";
3result = this:_tolist(string = args[1] + "}");
4if (result[1] && (result[1] != $string_utils:space(result[1])))
5return {0, tostr("after char ", length(string) - result[1], ":  ", result[2])};
6elseif (typeof(result[1]) == INT)
7return {0, "missing } or \""};
8elseif (length(result[2]) > 1)
9return {0, "comma unexpected."};
10elseif (result[2])
11return {1, result[2][1]};
12else
13return {0, "missing expression"};
14endif

prefix_to_value

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":prefix_to_value(string) tries to parse string as a value (i.e., object, number, string, error, or list thereof).";
2"Returns {rest-of-string,value} or {0,error_message} according as the attempt was successful or not.";
3alen = length(args[1]);
4slen = length(string = this:triml(args[1]));
5if (!string)
6return {0, "empty string"};
7elseif (w = index("{\"", string[1]))
8result = this:({"_tolist", "_unquote"}[w])(string[2..slen]);
9if (typeof(result[1]) != INT)
10return result;
11elseif (result[1] == 0)
12return {0, "missing } or \""};
13else
14return {0, result[2], (alen - result[1]) + 1};
15endif
16else
17thing = string[1..tlen = index(string + " ", " ") - 1];
18if (typeof(s = this:_toscalar(thing)) != STR)
19return {string[tlen + 1..slen], s};
20else
21return {0, s, (alen - slen) + 1};
22endif
23endif

_tolist

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"_tolist(string) --- auxiliary for :to_value()";
2rest = this:triml(args[1]);
3vlist = {};
4if (!rest)
5return {0, {}};
6elseif (rest[1] == "}")
7return {rest[2..$], {}};
8endif
9while (1)
10rlen = length(rest);
11if (w = index("{\"", rest[1]))
12result = this:({"_tolist", "_unquote"}[w])(rest[2..rlen]);
13if (typeof(result[1]) == INT)
14return result;
15endif
16vlist = {@vlist, result[2]};
17rest = result[1];
18else
19thing = rest[1..tlen = min(index(rest + ",", ","), index(rest + "}", "}")) - 1];
20if (typeof(s = this:_toscalar(thing)) == STR)
21return {rlen, s};
22endif
23vlist = {@vlist, s};
24rest = rest[tlen + 1..rlen];
25endif
26if (!rest)
27return {0, vlist};
28elseif (rest[1] == "}")
29return {rest[2..$], vlist};
30elseif (rest[1] == ",")
31rest = this:triml(rest[2..$]);
32else
33return {length(rest), ", or } expected"};
34endif
35endwhile

_unquote

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"_unquote(string)   (auxiliary for :to_value())";
2"reads string as if it were preceded by a quote, reading up to the closing quote if any, then returns the corresponding unquoted string.";
3" => {0, string unquoted}  if there is no closing quote";
4" => {original string beyond closing quote, string unquoted}  otherwise";
5rest = args[1];
6result = "";
7while (m = match(rest, "\\.?%|\""))
8"Find the next special character";
9if (rest[pos = m[1]] == "\"")
10return {rest[pos + 1..$], result + rest[1..pos - 1]};
11endif
12result = (result + rest[1..pos - 1]) + rest[pos + 1..m[2]];
13rest = rest[m[2] + 1..$];
14endwhile
15return {0, result + rest};

_toscalar

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":_toscalar(string)  --- auxiliary for :tovalue";
2" => value if string represents a number, object or error";
3" => string error message otherwise";
4thing = args[1];
5if (!thing)
6return "missing value";
7elseif (match(thing, "^#?[-+]?[0-9]+ *$"))
8return (thing[1] == "#") ? toobj(thing) | toint(thing);
9elseif (match(thing, "^[-+]?%([0-9]+%.[0-9]*%|[0-9]*%.[0-9]+%)%(e[-+]?[0-9]+%)? *$"))
10"matches 2. .2 3.2 3.2e3 .2e-3 3.e3";
11return `tofloat(thing) ! E_INVARG => tostr("Bad floating point value: ", thing)';
12elseif (match(thing, "^[-+]?[0-9]+e[-+]?[0-9]+ *$"))
13"matches 345e4. No decimal, but has an e so still a float";
14return `tofloat(thing) ! E_INVARG => tostr("Bad floating point value: ", thing)';
15elseif (thing[1] == "E")
16return (e = $code_utils:toerr(thing)) ? tostr("unknown error code `", thing, "'") | e;
17elseif (thing[1] == "#")
18return tostr("bogus objectid `", thing, "'");
19else
20return tostr("`", thing[1], "' unexpected");
21endif

parse_command

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

none

Source

1":parse_command(cmd_line[,player])";
2" => {verb, {dobj, dobjstr}, {prep, prepstr}, {iobj, iobjstr}, {args, argstr},";
3"     dobjset, prepset, iobjset}";
4"This mimics the action of the builtin parser, returning what the values of the builtin variables `verb', `dobj', `dobjstr', `prepstr', `iobj', `iobjstr', `args', and `argstr' would be if `player' had typed `cmd_line'.  ";
5"`prep' is the shortened version of the preposition found.";
6"";
7"`dobjset' and `iobjset' are subsets of {\"any\",\"none\"} and are used to determine possible matching verbs, i.e., the matching verb must either be on `dobj' and have verb_args[1]==\"this\" or else it has verb_args[1] in `dobjset'; likewise for `iobjset' and verb_args[3]; similarly we must have verb_args[2] in `prepset'.";
8{c, ?who = player} = args;
9y = $string_utils:words(c);
10if (y == {})
11return {};
12endif
13vrb = y[1];
14y = y[2..$];
15as = (y == {}) ? "" | c[length(vrb) + 2..$];
16n = 1;
17while ((!(gp = $code_utils:get_prep(@y[n..$]))[1]) && (n < length(y)))
18n = n + 1;
19endwhile
20"....";
21really = player;
22player = who;
23loc = who.location;
24if (ps = gp[1])
25ds = $string_utils:from_list(y[1..n - 1], " ");
26is = $string_utils:from_list(listdelete(gp, 1), " ");
27io = valid(loc) ? loc:match_object(is) | $string_utils:match_object(is, loc);
28else
29ds = $string_utils:from_list(y, " ");
30is = "";
31io = $nothing;
32endif
33do = valid(loc) ? loc:match_object(ds) | $string_utils:match_object(ds, loc);
34player = really;
35"....";
36dset = {"any", @(ds == "") ? {"none"} | {}};
37"\"this\" must be handled manually.";
38pset = {"any", @ps ? {$code_utils:full_prep(ps)} | {"none"}};
39iset = {"any", @(is == "") ? {"none"} | {}};
40return {vrb, {do, ds}, {$code_utils:short_prep(ps), ps}, {io, is}, {y, as}, {dset, pset, iset}};

from_value

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

Source

1"$string_utils:from_value(value [, quote_strings = 0 [, list_depth = 1]])";
2"Print the given value into a string.";
3{value, ?quote_strings = 0, ?list_depth = 1} = args;
4if (typeof(value) == LIST)
5if (value)
6if (list_depth)
7result = "{" + this:from_value(value[1], quote_strings, list_depth - 1);
8for v in (listdelete(value, 1))
9result = tostr(result, ", ", this:from_value(v, quote_strings, list_depth - 1));
10endfor
11return result + "}";
12else
13return "{...}";
14endif
15else
16return "{}";
17endif
18elseif (quote_strings)
19if (typeof(value) == STR)
20result = "\"";
21while (q = index(value, "\"") || index(value, "\\"))
22if (value[q] == "\"")
23q = min(q, index(value + "\\", "\\"));
24endif
25result = ((result + value[1..q - 1]) + "\\") + value[q];
26value = value[q + 1..$];
27endwhile
28return (result + value) + "\"";
29elseif (typeof(value) == ERR)
30return $code_utils:error_name(value);
31else
32return tostr(value);
33endif
34else
35return tostr(value);
36endif

print print_suspended

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:print(value)";
2"Print the given value into a string. == from_value(value,1,-1)";
3return toliteral(args[1]);
4value = args[1];
5if (typeof(value) == LIST)
6if (value)
7result = "{" + this:print(value[1]);
8for val in (listdelete(value, 1))
9result = tostr(result, ", ", this:print(val));
10endfor
11return result + "}";
12else
13return "{}";
14endif
15elseif (typeof(value) == STR)
16return tostr("\"", strsub(strsub(value, "\\", "\\\\"), "\"", "\\\""), "\"");
17elseif (typeof(value) == ERR)
18return $code_utils:error_name(value);
19else
20return tostr(value);
21endif

reverse

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":reverse(string) => \"gnirts\"";
2"An example: :reverse(\"This is a test.\") => \".tset a si sihT\"";
3string = args[1];
4if ((len = length(string)) > 50)
5return this:reverse(string[($ / 2) + 1..$]) + this:reverse(string[1..$ / 2]);
6endif
7index = len;
8result = "";
9while (index > 0)
10result = result + string[index];
11index = index - 1;
12endwhile
13return result;

char_list

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":char_list(string) => string as a list of characters.";
2"   e.g., :char_list(\"abad\") => {\"a\",\"b\",\"a\",\"d\"}";
3if (30 < (len = length(string = args[1])))
4return {@this:char_list(string[1..$ / 2]), @this:char_list(string[($ / 2) + 1..$])};
5else
6l = {};
7for c in [1..len]
8l = {@l, string[c]};
9endfor
10return l;
11endif

regexp_quote

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":regexp_quote(string)";
2" => string with all of the regular expression special characters quoted with %";
3string = args[1];
4quoted = "";
5while (m = rmatch(string, "[][$^.*+?%].*"))
6quoted = ("%" + string[m[1]..m[2]]) + quoted;
7string = string[1..m[1] - 1];
8endwhile
9return string + quoted;

connection_hostname_bsd

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Takes the output from connection_name() and returns just the host string portion of it.  Assumes you are using bsd_network style connection names.";
2s = args[1];
3return (m = `match(args[1], "^.* %(from%|to%) %([^, ]+%)") ! ANY') ? substitute("%2", m) | "";

connection_hostname

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"This is the function that should actually be called to get the host name from a connection name.  The archwizard should change _bsd so as to be calling the verb appropriate for his/her network interface.";
2return this:connection_hostname_bsd(@args);

from_value_suspended

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

none

Source

1"$string_utils:from_value(value [, quote_strings = 0 [, list_depth = 1]])";
2"Print the given value into a string.";
3"This verb suspends as necessary for large values.";
4set_task_perms(caller_perms());
5{value, ?quote_strings = 0, ?list_depth = 1} = args;
6if (typeof(value) == LIST)
7if (value)
8if (list_depth)
9result = "{" + this:from_value(value[1], quote_strings, list_depth - 1);
10for v in (listdelete(value, 1))
11(ticks_left() < 4000) && suspend(0);
12result = tostr(result, ", ", this:from_value(v, quote_strings, list_depth - 1));
13endfor
14return result + "}";
15else
16return "{...}";
17endif
18else
19return "{}";
20endif
21elseif (quote_strings)
22if (typeof(value) == STR)
23result = "\"";
24while (q = index(value, "\"") || index(value, "\\"))
25(ticks_left() < 4000) && suspend(0);
26if (value[q] == "\"")
27q = min(q, index(value + "\\", "\\"));
28endif
29result = ((result + value[1..q - 1]) + "\\") + value[q];
30value = value[q + 1..$];
31endwhile
32return (result + value) + "\"";
33elseif (typeof(value) == ERR)
34return $code_utils:error_name(value);
35else
36return tostr(value);
37endif
38else
39return tostr(value);
40endif

end_expression

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1":end_expression(string[,stop_at])";
2"  assumes string starts with an expression; returns the index of the last char in expression or 0 if string appears not to be an expression.  Expression ends at any character from stop_at which occurs at top level.";
3{string, ?stop_at = " "} = args;
4gone = 0;
5paren_stack = "";
6inquote = 0;
7search = top_level_search = ("[][{}()\"" + strsub(stop_at, "]", "")) + "]";
8paren_search = "[][{}()\"]";
9while (m = match(string, search))
10char = string[m[1]];
11string[1..m[2]] = "";
12gone = gone + m[2];
13if (char == "\"")
14"...skip over quoted string...";
15char = "\\";
16while (char == "\\")
17if (!(m = match(string, "%(\\.?%|\"%)")))
18return 0;
19endif
20char = string[m[1]];
21string[1..m[2]] = "";
22gone = gone + m[2];
23endwhile
24elseif (index("([{", char))
25"... push parenthesis...";
26paren_stack[1..0] = char;
27search = paren_search;
28elseif (i = index(")]}", char))
29if (paren_stack && ("([{"[i] == paren_stack[1]))
30"... pop parenthesis...";
31paren_stack[1..1] = "";
32search = paren_stack ? paren_search | top_level_search;
33else
34"...parenthesis mismatch...";
35return 0;
36endif
37else
38"... stop character ...";
39return gone - 1;
40endif
41endwhile
42return (!paren_stack) && (gone + length(string));

first_word

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":first_word(string) => {first word, rest of string} or {}";
2rest = args[1];
3"...trim leading blanks...";
4rest[1..match(rest, "^ *")[2]] = "";
5if (!rest)
6return {};
7endif
8quote = 0;
9token = "";
10pattern = " +%|\\.?%|\"";
11while (m = match(rest, pattern))
12"... find the next occurence of a special character, either";
13"... a block of spaces, a quote or a backslash escape sequence...";
14char = rest[m[1]];
15token = token + rest[1..m[1] - 1];
16if (char == " ")
17rest[1..m[2]] = "";
18return {token, rest};
19elseif (char == "\"")
20"... beginning or end of quoted string...";
21"... within a quoted string spaces aren't special...";
22pattern = (quote = !quote) ? "\\.?%|\"" | " +%|\\.?%|\"";
23elseif (m[1] < m[2])
24"... char has to be a backslash...";
25"... include next char literally if there is one";
26token = token + rest[m[2]];
27endif
28rest[1..m[2]] = "";
29endwhile
30return {token + rest, ""};

common

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":common(first,second) => length of longest common prefix";
2{first, second} = args;
3r = min(length(first), length(second));
4l = 1;
5while (r >= l)
6h = (r + l) / 2;
7if (first[l..h] == second[l..h])
8l = h + 1;
9else
10r = h - 1;
11endif
12endwhile
13return r;

title_list*c list_title*c

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"wr_utils:title_list/title_listc(<obj-list>[, @<args>)";
2"Creates an english list out of the titles of the objects in <obj-list>.  Optional <args> are passed on to $string_utils:english_list.";
3"title_listc uses :titlec() for the first item.";
4titles = $list_utils:map_verb(args[1], "title");
5if (verb[length(verb)] == "c")
6if (titles)
7titles[1] = args[1][1]:titlec();
8elseif (length(args) > 1)
9args[2] = $string_utils:capitalize(args[2]);
10else
11args = listappend(args, "Nothing");
12endif
13endif
14return $string_utils:english_list(titles, @args[2..$]);

name_and_number nn name_and_number_list nn_list

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"name_and_number(object [,sepr]) => \"ObjectName (#object)\"";
2"Return name and number for OBJECT.  Second argument is optional separator (for those who want no space, use \"\").  If OBJECT is a list of objects, this maps the above function over the list and then passes it to $string_utils:english_list.";
3{objs, ?sepr = " "} = args;
4if (typeof(objs) != LIST)
5objs = {objs};
6endif
7name_list = {};
8for what in (objs)
9name = valid(what) ? what.name | {"<invalid>", "$nothing", "$ambiguous_match", "$failed_match"}[1 + (what in {#-1, #-2, #-3})];
10name = tostr(name, sepr, "(", what, ")");
11name_list = {@name_list, name};
12endfor
13return $string_utils:english_list(name_list);

columnize_suspended columnise_suspended

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"columnize_suspended (interval, items, n [, width]) - Turn a one-column list of items into an n-column list, suspending for `interval' seconds as necessary. 'width' is the last character position that may be occupied; it defaults to a standard screen width. Example: To tell the player a list of numbers in three columns, do 'player:tell_lines ($string_utils:columnize_suspended(0, {1, 2, 3, 4, 5, 6, 7}, 3));'.";
2{interval, items, n, ?width = 79} = args;
3height = ((length(items) + n) - 1) / n;
4items = {@items, @$list_utils:make((height * n) - length(items), "")};
5colwidths = {};
6for col in [1..n - 1]
7colwidths = listappend(colwidths, 1 - (((width + 1) * col) / n));
8endfor
9result = {};
10for row in [1..height]
11line = tostr(items[row]);
12for col in [1..n - 1]
13(ticks_left() < 4000) && suspend(interval);
14line = tostr(this:left(line, colwidths[col]), " ", items[row + (col * height)]);
15endfor
16result = listappend(result, line[1..min($, width)]);
17endfor
18return result;

a_or_an

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1":a_or_an(<noun>) => \"a\" or \"an\"";
2"To accomodate personal variation (e.g., \"an historical book\"), a player can override this by having a personal a_or_an verb.  If that verb returns 0 instead of a string, the standard algorithm is used.";
3noun = args[1];
4if ($object_utils:has_verb(player, "a_or_an") && ((custom_result = player:a_or_an(noun)) != 0))
5return custom_result;
6endif
7if (noun in this.use_article_a)
8return "a";
9endif
10if (noun in this.use_article_an)
11return "an";
12endif
13a_or_an = "a";
14if (noun != "")
15if (index("aeiou", noun[1]))
16a_or_an = "an";
17"unicycle, unimplemented, union, united, unimpressed, unique";
18if ((((noun[1] == "u") && (length(noun) > 2)) && (noun[2] == "n")) && ((index("aeiou", noun[3]) == 0) || (((noun[3] == "i") && (length(noun) > 3)) && (index("aeioubcghqwyz", noun[4]) || ((length(noun) > 4) && index("eiy", noun[5]))))))
19a_or_an = "a";
20endif
21endif
22endif
23return a_or_an;
24"Ported by Mickey with minor tweaks from a Moo far far away.";
25"Last modified Sun Aug  1 22:53:07 1993 EDT by BabyBriar (#2).";

index_all

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"index_all(string,target) -- returns list of positions of target in string.";
2"Usage: $string_utils:index_all(<string,pattern>)";
3"       $string_utils:index_all(\"aaabacadae\",\"a\")";
4{line, pattern} = args;
5if ((typeof(line) != STR) || (typeof(pattern) != STR))
6return E_TYPE;
7else
8where = {};
9place = -1;
10next = 0;
11while ((place = index(line[next + 1..$], pattern)) != 0)
12where = {@where, place + next};
13next = ((place + next) + length(pattern)) - 1;
14endwhile
15return where;
16endif

match_stringlist match_string_list

Spec this none thisFlags rxOwner #36Definer #20

Referenced by

Source

1"Copied from Puff (#1449):match_stringlist Tue Oct 19 08:18:13 1993 PDT";
2"$string_utils:match_stringlist(string, {list of strings})";
3"The list of strings should be just that, a list of strings.  The first string is matched against the list of strings.";
4"If it exactly matches exactly one of them, the index of the match is returned. If it exactly matches more than one of them, $ambiguous_match is returned.";
5"If there are no exact matches, then partial matches are considered, ones in which the given string is a prefix of one of the strings.";
6"Again, if exactly one match is found, the index of that string is returned, and if more than one match is found, $ambiguous match is returned.";
7"Finally, if there are no exact or partial matches, then $failed_match is returned.";
8{subject, stringlist} = args;
9if ((subject == "") || (length(stringlist) < 1))
10return $nothing;
11endif
12matches = {};
13"First check for exact matches.";
14for i in [1..length(stringlist)]
15if (subject == stringlist[i])
16matches = {@matches, i};
17endif
18endfor
19"Now return a match, or $ambiguous, or check for partial matches.";
20if (length(matches) == 1)
21return matches[1];
22elseif (length(matches) > 1)
23return $ambiguous_match;
24elseif (length(matches) == 0)
25"Checking for partial matches is almost identical to checking for exact matches, but we use index(list[i], target) instead of list[i] == target to see if they match.";
26for i in [1..length(stringlist)]
27if (index(stringlist[i], subject) == 1)
28matches = {@matches, i};
29endif
30endfor
31if (length(matches) == 1)
32return matches[1];
33elseif (length(matches) > 1)
34return $ambiguous_match;
35elseif (length(matches) == 0)
36return $failed_match;
37endif
38endif

from_ASCII

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"This converts a ASCII character code in the range [32..126] into the ASCII character with that code, represented as a one-character string.";
2"";
3"Example:   $string_utils:from_ASCII(65) => \"A\"";
4code = args[1];
5return this.ascii[code - 31];

to_ASCII

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"Convert a one-character string into the ASCII character code for that character.";
2"";
3"Example:  $string_utils:to_ASCII(\"A\") => 65";
4return (index(this.ascii, args[1], 1) || raise(E_INVARG)) + 31;

abbreviated_value

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Copied from Mickey (#52413):abbreviated_value Fri Sep  9 08:52:41 1994 PDT";
2":abbreviated_value(value,max_reslen,max_lstlev,max_lstlen,max_strlen,max_toklen)";
3"";
4"Gets the printed representation of value, subject to these parameters:";
5" max_reslen = Maximum desired result string length.";
6" max_lstlev = Maximum list level to show.";
7" max_lstlen = Maximum list length to show.";
8" max_lstlen = Maximum string length to show.";
9" max_lstlen = Maximum token length (e.g., numbers and errors) to show.";
10"";
11"A best attempt is made to get the exact target size, but in some cases the result is not exact.";
12{value, ?max_reslen = $maxint, ?max_lstlev = $maxint, ?max_lstlen = $maxint, ?max_strlen = $maxint, ?max_toklen = $maxint} = args;
13return this:_abbreviated_value(value, max_reslen, max_lstlev, max_lstlen, max_strlen, max_toklen);
14"Originally written by Mickey.";

_abbreviated_value

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"Copied from Mickey (#52413):_abbreviated_value Fri Sep  9 08:52:44 1994 PDT";
2"Internal to :abbreviated_value.  Do not call this directly.";
3{value, max_reslen, max_lstlev, max_lstlen, max_strlen, max_toklen} = args;
4if ((type = typeof(value)) == LIST)
5if (!value)
6return "{}";
7elseif (max_lstlev == 0)
8return "{...}";
9else
10n = length(value);
11result = "{";
12r = max_reslen - 2;
13i = 1;
14eltstr = "";
15while (((i <= n) && (i <= max_lstlen)) && (r > (x = (i == 1) ? 0 | 2)))
16eltlen = length(eltstr = this:(verb)(value[i], r, max_lstlev - 1, max_lstlen, max_strlen, max_toklen));
17lastpos = 1;
18if (r >= (eltlen + x))
19comma = (i == 1) ? "" | ", ";
20result = tostr(result, comma);
21if (r > 4)
22lastpos = length(result);
23endif
24result = tostr(result, eltstr);
25r = (r - eltlen) - x;
26elseif (i == 1)
27return "{...}";
28elseif (r > 4)
29return tostr(result, ", ...}");
30else
31return tostr(result[1..lastpos], "...}");
32endif
33i = i + 1;
34endwhile
35if (i <= n)
36if (i == 1)
37return "{...}";
38elseif (r > 4)
39return tostr(result, ", ...}");
40else
41return tostr(result[1..lastpos], "...}");
42endif
43else
44return tostr(result, "}");
45endif
46endif
47elseif (type == STR)
48result = "\"";
49while ((q = index(value, "\"")) ? q = min(q, index(value, "\\")) | (q = index(value, "\\")))
50result = ((result + value[1..q - 1]) + "\\") + value[q];
51value = value[q + 1..$];
52endwhile
53result = result + value;
54if ((length(result) + 1) > (z = max(min(max_reslen, max(max_strlen, max_strlen + 2)), 6)))
55z = z - 5;
56k = 0;
57while ((k < z) && (result[z - k] == "\\"))
58k = k + 1;
59endwhile
60return tostr(result[1..z - (k % 2)], "\"+...");
61else
62return tostr(result, "\"");
63endif
64else
65v = (type == ERR) ? $code_utils:error_name(value) | tostr(value);
66len = max(4, min(max_reslen, max_toklen));
67return (length(v) > len) ? v[1..len - 3] + "..." | v;
68endif
69"Originally written by Mickey.";

match_suspended

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"$string_utils:match_suspended(string [, obj-list, prop-name]*)";
2"Each obj-list should be a list of objects or a single object, which is treated as if it were a list of that object.  Each prop-name should be string naming a property on every object in the corresponding obj-list.  The value of that property in each case should be either a string or a list of strings.";
3"The argument string is matched against all of the strings in the property values.";
4"If it exactly matches exactly one of them, the object containing that property is returned.  If it exactly matches more than one of them, $ambiguous_match is returned.";
5"If there are no exact matches, then partial matches are considered, ones in which the given string is a prefix of some property string.  Again, if exactly one match is found, the object with that property is returned, and if there is more than one match, $ambiguous_match is returned.";
6"Finally, if there are no exact or partial matches, then $failed_match is returned.";
7"This verb will suspend as needed, and should be used if obj-list is very large.";
8subject = args[1];
9if (subject == "")
10return $nothing;
11endif
12no_exact_match = no_partial_match = 1;
13for i in [1..length(args) / 2]
14prop_name = args[(2 * i) + 1];
15for object in ((typeof(olist = args[2 * i]) == LIST) ? olist | {olist})
16if (valid(object))
17if (typeof(str_list = `object.(prop_name) ! E_PERM, E_PROPNF => {}') != LIST)
18str_list = {str_list};
19endif
20if (subject in str_list)
21if (no_exact_match)
22no_exact_match = object;
23elseif (no_exact_match != object)
24return $ambiguous_match;
25endif
26else
27for string in (str_list)
28if (index(string, subject) != 1)
29elseif (no_partial_match)
30no_partial_match = object;
31elseif (no_partial_match != object)
32no_partial_match = $ambiguous_match;
33endif
34endfor
35endif
36endif
37$command_utils:suspend_if_needed(5);
38endfor
39endfor
40return no_exact_match && (no_partial_match && $failed_match);

incr_alpha

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

Source

1"args[1] is a string.  'increments' the string by one. E.g., aaa => aab, aaz => aba.  empty string => a, zzz => aaaa.";
2s = args[1];
3index = length(s);
4if (!s)
5return "a";
6elseif (s[$] == "z")
7return this:incr_alpha(s[1..index - 1]) + "a";
8else
9t = index(this.alphabet, s[index]);
10return s[1..index - 1] + this.alphabet[t + 1];
11endif

is_float

Spec this none thisFlags rxdOwner #36Definer #20

Referenced by

none

Source

1"Usage:  is_float(string)";
2"Is string composed of one or more digits possibly preceded by a minus sign either followed by a decimal or by an exponent?";
3"Return true or false";
4return match(args[1], "^ *[-+]?%(%([0-9]+%.[0-9]*%|[0-9]*%.[0-9]+%)%(e[-+]?[0-9]+%)?%)%|%([0-9]+e[-+]?[0-9]+%) *$");

redirect_ansi left right center centre columnize columnise space

Spec this none thisFlags rxOwner #36Definer #20

Referenced by

Source

1"...redirects verbs to $ansi_utils...";
2if (verb == "redirect_ansi")
3elseif (valid(au = $ansi_utils))
4return au:(verb)(@args);
5else
6return this:(verb + "(noansi)")(@args);
7endif

get_say_verb_prep

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

Source

1"USAGE: get_say_verb_prep(STRING) => preposition plus";
2"       leading and trailing spaces for 'say' substitutes.";
3"       ie. get_say_verb_prep('complains')";
4"           returns ' to '";
5sayverb = args[1];
6if (sayverb == "asks")
7return " ";
8elseif (sayverb in {"exclaims", "adds", "ponders", "complains", "yawns", "yells", "says"})
9return " to ";
10endif
11return " at ";

get_say_verb

Spec this none thisFlags rxdOwner #2Definer #20

Referenced by

Source

1"USAGE: get_say_verb(STRING) => 3rd person verb for 'say'";
2"       (ie. return 'asks')";
3"       Parses for ! and ? and ... first, then emoticons.";
4"...<words> adds            <words>... ponders";
5" ! exclaims     ? asks     :) smiles    :} chuckles";
6":D laughs      :> grins    :( frowns    :[ complains";
7":P plbbbbbts   :/ shrugs   :o yawns     :0 yells";
8":| sighs";
9";) winks       ;> smirks   ;/ winces    ;( grimaces";
10"OTHERWISE, 'says' is returned.";
11words = args[1];
12if ((!words) || (!$string_utils:words(words)))
13return "pauses";
14endif
15if (length(words) > 2)
16if (tostr(words[1..3]) == "...")
17return "adds";
18elseif (tostr(words[$ - 2..$]) == "...")
19return "ponders";
20endif
21endif
22cutstring = this:trim(this:strip_chars(words, "^-."));
23cutstring = this:subst(cutstring, {{"=", ":"}, {"B", ":"}, {"8", ":"}, {"]", ")"}, {"b", "P"}, {"O", "0"}, {"@", "0"}}, 1);
24smiley = this:explode(cutstring)[$];
25if (smiley[$] == "!")
26return "exclaims";
27elseif (smiley[$] == "?")
28return "asks";
29elseif (length(smiley) > 3)
30return "says";
31elseif (smiley[1] == ";")
32if (smiley[$] == ">")
33return "smirks";
34elseif (smiley[$] == "/")
35return "winces";
36elseif (smiley[$] == "(")
37return "grimaces";
38endif
39return "winks";
40elseif (smiley == ":)")
41return "smiles";
42elseif (smiley == ":}")
43return "chuckles";
44elseif (smiley == ":D")
45return "laughs";
46elseif (smiley == ":>")
47return "grins";
48elseif (smiley == ":(")
49return "frowns";
50elseif (smiley == ":[")
51return "complains";
52elseif (smiley == ":P")
53return "plbbbbbts";
54elseif (smiley == ":/")
55return "shrugs";
56elseif (smiley == ":o")
57return "yawns";
58elseif (smiley == ":0")
59return "yells";
60elseif (smiley == ":|")
61return "sighs";
62else
63return "says";
64endif