Utility Object #20

Parent #1Owner #10Flags Source MurpgCore-0.4/MurpgCore-0.4.db

21 verbs · 14 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
parse_prop_refthis none thisrwxd#2031
cap*italizethis none thisrwxd#205
triml*eftthis none thisrwxd#205
list_to_str*ingthis none thisrwxd#2027
trimr*ightthis none thisrwxd#204
parse_verb_refthis none thisrwxd#2031
sortthis none thisrwxd#2027
matchthis none thisrwxd#2041
parse_dot_refthis none thisrwxd#2011
padl*eftthis none thisrwxd#2013
padr*ightthis none thisrwxd#2013
dhmsthis none thisrwxd#2010
_uptimethis none thisrwxd#204
ftimethis none thisrwxd#2036
dhms_strthis none thisrwxd#2013
longest*_lengththis none thisrwxd#2011
string_to_listthis none thisrwxd#2013
rem*ovethis none thisrwxd#2010
string_to_frag*mentthis none thisrwxd#2018
match_dollar_refthis none thisrwxd#2017
height_strthis none thisrwxd#204

Properties

PropertyDefinerFlagsOwnerValue
description#1rw#10<clear>
aliases#1rw#10<clear>
home#1rw#10<clear>
short_desc#1rw#10<clear>
core#1rw#101
handedness#1rw#10<clear>
base_enc#1rw#10<clear>
base_weight#1rw#10<clear>
capacity#1rw#10<clear>
max_fit#1rw#10<clear>
pprep#1rw#10<clear>
gprep#1rw#10<clear>
generic_name#1rw#10<clear>
age#1rw#10<clear>

Ancestry

Ancestors (nearest first): #1 Root Class

Children: none

Call graph

calls n20_6 #20:sort n20_6->n20_6 n20_7 #20:match n20_8 #20:parse_dot_ref n20_7->n20_8 n20_12 #20:_uptime n20_11 #20:dhms n20_12->n20_11 n20_14 #20:dhms_str n20_12->n20_14 n20_18 #20:string_to_frag*ment n20_16 #20:string_to_list n20_18->n20_16

Source

parse_prop_ref

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1" #20:parse_prop_ref this none this";
2prop_ref = args[1];
3dot = index(prop_ref, ".");
4if (!dot)
5if (prop_ref[1] != "$")
6return 0;
7else
8return {"#0", prop_ref[2..$]};
9endif
10else
11object = prop_ref[1..dot - 1];
12prop = prop_ref[dot + 1..$];
13if (!(object && prop))
14return 0;
15elseif (object[1] != "$")
16return {object, prop};
17else
18sysprop = object[2..$];
19if (!$has_prop(sysprop))
20return 0;
21else
22object = #0.(sysprop);
23if (typeof(object) != OBJ)
24return 0;
25else
26object = tostr(object);
27return {object, prop};
28endif
29endif
30endif
31endif

cap*italize

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1" #20:capitalize(STR) this none this ";
2if ((string = args[1]) && (i = index("abcdefghijklmnopqrstuvwxyz", string[1], 1)))
3string[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i];
4endif
5return string;

triml*eft

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:triml*eft this none this";
2"copied from LambdaMOO";
3{string, ?what = " "} = args;
4index = match(string, tostr("[^", what, "]%|$"));
5return string[index[1]..$];

list_to_str*ing

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:list_to_str*ing this none this";
2{thelist, ?separator = "", ?conj = ""} = args;
3if (thelist == {})
4return "";
5else
6if (length(thelist) == 1)
7return tostr(thelist[1]);
8else
9if (separator == "")
10return tostr(@thelist);
11else
12if (conj)
13if (length(thelist) == 2)
14result = (((tostr(thelist[1]) + " ") + conj) + " ") + tostr(thelist[2]);
15return result;
16else
17thelist[$] = (conj + " ") + tostr(thelist[$]);
18endif
19endif
20result = tostr(thelist[1]);
21for item in (listdelete(thelist, 1))
22result = tostr(result, separator, item);
23endfor
24return result;
25endif
26endif
27endif

trimr*ight

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:trimr*ight this none this";
2"Copied from LambdaMOO";
3{string, ?what = " "} = args;
4return string[1..rmatch(string, tostr("[^", what, "]%|^"))[2]];

parse_verb_ref

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:parse_verb_ref this none this";
2verb_ref = args[1];
3colon = index(verb_ref, ":");
4if (!colon)
5if (verb_ref[1] != "$")
6return 0;
7else
8return {"#0", verb_ref[2..$]};
9endif
10else
11object = verb_ref[1..colon - 1];
12verbname = verb_ref[colon + 1..$];
13if (!(object && verbname))
14return 0;
15elseif (object[1] != "$")
16return {object, verbname};
17else
18prop_name = object[2..$];
19if (!$has_prop(prop_name))
20return 0;
21else
22object = #0.(prop_name);
23if (typeof(object) != OBJ)
24return 0;
25else
26object = tostr(object);
27return {object, verbname};
28endif
29endif
30endif
31endif

sort

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"quick sort algorithm";
2sortlist = args[1];
3if (length(sortlist) <= 1)
4return sortlist;
5elseif (length(sortlist) == 2)
6return (sortlist[1] < sortlist[2]) ? {sortlist[1], sortlist[2]} | {sortlist[2], sortlist[1]};
7else
8"partition into left and right";
9left = {};
10right = {};
11pivotlist = {};
12pivotindex = random(length(sortlist));
13pivotitem = sortlist[pivotindex];
14for each in (sortlist)
15if (each < pivotitem)
16left = {@left, each};
17elseif (each > pivotitem)
18right = {@right, each};
19else
20pivotlist = {@pivotlist, each};
21endif
22endfor
23"sort each side";
24sortedleft = $utils:sort(left);
25sortedright = $utils:sort(right);
26return {@sortedleft, @pivotlist, @sortedright};
27endif

match

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"#20:match(str, objlist, ?exact, ?nameonly) - returns a list of objs from args[2] that";
2"are named or aliased to args[1].  args[3] if true forces a full match. args[4] will";
3"if true match only to object's name";
4"if no match, returns empty list.";
5{token, objlist, ?exact = 0, ?nameonly = 0} = args;
6count = 0;
7count_and_item = $utils:parse_dot_ref(token);
8if (count_and_item)
9{count, item} = count_and_item;
10endif
11if (count > 0)
12token = item;
13endif
14matchlist = {};
15for each in (objlist)
16if (!(each in matchlist))
17doesmatch = 0;
18if (nameonly)
19names = {each.name};
20else
21names = {each.name, @each.aliases};
22endif
23for name in (names)
24if (exact)
25doesmatch = doesmatch || (token == name);
26else
27doesmatch = doesmatch || (index(name, token) == 1);
28endif
29endfor
30if (doesmatch)
31matchlist = {@matchlist, each};
32endif
33endif
34endfor
35if (count == 0)
36return matchlist;
37elseif (count <= length(matchlist))
38return {matchlist[count]};
39else
40return {};
41endif

parse_dot_ref

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:parse_dot_ref(str) returns {int count, str}";
2"used for dot matching... 2.sword, etc.";
3{prop_ref} = args;
4dot = index(prop_ref, ".");
5if (dot > 1)
6NUM = prop_ref[1..dot - 1];
7token = prop_ref[dot + 1..$];
8return {tonum(NUM), token};
9else
10return 0;
11endif

padl*eft

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:padleft(str token, int length, str char)";
2{token, len, ?char = " "} = args;
3token = tostr(token);
4needed = len - length(token);
5times = 1 + (needed / length(char));
6for x in [1..times]
7token = char + token;
8endfor
9newlen = length(token);
10if (newlen != len)
11token = token[(newlen - len) + 1..newlen];
12endif
13return token;

padr*ight

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:padright(str token, int length, str char)";
2{token, len, ?char = " "} = args;
3token = tostr(token);
4needed = len - length(token);
5times = 1 + (needed / length(char));
6for x in [1..times]
7token = token + char;
8endfor
9newlen = length(token);
10if (newlen != len)
11token = token[1..len];
12endif
13return token;

dhms

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:dhms(seconds)";
2"returns {days, hours, minutes, seconds}";
3{seconds} = args;
4days = seconds / 86400;
5seconds = seconds % 86400;
6hours = seconds / 3600;
7seconds = seconds % 3600;
8minutes = seconds / 60;
9seconds = seconds % 60;
10return {days, hours, minutes, seconds};

_uptime

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:_uptime() this none this";
2times = $utils:dhms(time() - $start_time);
3uptime_str = $utils:dhms_str(times);
4return uptime_str;

ftime

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:ftime this none this";
2"format any string in ctime format";
3ctime = args[1];
4_day = ctime[1..3];
5_mo = ctime[5..7];
6_hour = ctime[12..13];
7daynum = ctime[9..10];
8min = ctime[15..16];
9daysav = ctime[26..28];
10day = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}[_day in {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}];
11mo = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}[_mo in {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}];
12"switch to standard time format";
13if (tonum(_hour) > 11)
14hour = tonum(_hour) - 12;
15ampm = "pm";
16else
17hour = tonum(_hour);
18ampm = "am";
19endif
20hour = tostr(hour);
21if (hour == "0")
22hour = "12";
23endif
24"set ordinal notation";
25x = daynum in {" 1", "21", "31", " 2", "22", " 3", "23"};
26if (x)
27ord = {"st", "st", "st", "nd", "nd", "rd", "rd"}[x];
28else
29ord = "th";
30endif
31"eliminate extra spaces";
32if (daynum[1] == " ")
33daynum = daynum[2];
34endif
35new_string = (((((((((((day + ", ") + mo) + " ") + daynum) + ord) + ", ") + hour) + ":") + min) + ampm) + " ") + daysav;
36return new_string;

dhms_str

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:dhms_str() this none this";
2times = args[1];
3days = times[1];
4daystr = (days == 1) ? " day, " | " days, ";
5day_var = (days == 0) ? "" | (tostr(days) + daystr);
6hours = times[2];
7hourstr = (hours == 1) ? " hour, " | " hours, ";
8hour_var = ((days == 0) && (hours == 0)) ? "" | (tostr(hours) + hourstr);
9mins = times[3];
10minstr = (mins == 1) ? " minute." | " minutes.";
11min_var = tostr(mins) + minstr;
12final_str = (day_var + hour_var) + min_var;
13return final_str;

longest*_length

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:longest*_length this none this";
2"If more than one is longest, returns length of first.";
3thelist = args[1];
4longest = 0;
5for x in (thelist)
6xlen = length(x);
7if (xlen > longest)
8longest = xlen;
9endif
10endfor
11return longest;

string_to_list

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:string_to_list this none this";
2string = args[1];
3newlist = {};
4if (length(string))
5while (ref = index(string, " "))
6newlist = {@newlist, string[1..ref - 1]};
7string = string[ref + 1..$];
8endwhile
9newlist = {@newlist, string};
10endif
11"Clear out any doubled spaces that ended up in the list.";
12newlist = $utils:remove(newlist, "", 1);
13return newlist;

rem*ove

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:remove this none this";
2{thelist, what, ?all = 0} = args;
3if (all)
4while (what in thelist)
5thelist = setremove(thelist, what);
6endwhile
7else
8thelist = setremove(thelist, what);
9endif
10return thelist;

string_to_frag*ment

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

none

Source

1"$utils:string_to_frag*ment this none this";
2words = $utils:string_to_list(args[1]);
3len = length(words);
4first = random(len);
5rest = len - first;
6if (!rest)
7frag = words[first];
8else
9newlist = {};
10more = random(rest + 1) - 1;
11count = first;
12while (count <= (first + more))
13newlist = {@newlist, words[count]};
14count = count + 1;
15endwhile
16frag = $utils:list_to_string(newlist, " ");
17endif
18return frag;

match_dollar_ref

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:match_dollar_ref this none this";
2"matches a $ref to the object it evals to";
3dollar_ref = args[1];
4if (dollar_ref[1] != "$")
5return 0;
6else
7try
8xobj = #0.(dollar_ref[2..$]);
9if (typeof(xobj) == OBJ)
10return xobj;
11else
12return 0;
13endif
14except (ANY)
15return 0;
16endtry
17endif

height_str

Spec this none thisFlags rwxdOwner #10Definer #20

Referenced by

Source

1"$utils:height_str this none this";
2{height} = args;
3height_str = ((tostr(height / 12) + "' ") + tostr(height % 12)) + "\"";
4return height_str;