string utilities #20

Parent #72Owner #361Flags obsolete1, readSource hellcore/hellcore.db

Aliases: string, utils

134 verbs · 21 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
spacethis none thisrxd#2030
leftthis none thisrxd#2016
rightthis none thisrxd#2013
centre centerthis none thisrxd#2013
columnize columnisethis none thisrxd#2018
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#2017
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_number gnthis none thisrxd#2026
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#2030
pronoun_sub psthis none thisrxd#20121
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#2020
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 thisrx#2014
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#2012
is_floatthis none thisrxd#204
inside_quotesthis none thisrx#2013
strip_all_but_seqthis none thisrxd#2010
ps_backupthis none thisrxd#2078
mel_matchthis none thisrxd#2055
match_backup_spunkythis none thisrxd#2040
match_aliasesthis none thisrxd#2056
escapethis none thisrxd#207
match_aliases_ambiguousthis none thisrxd#2033
pluralthis none thisrxd#2075
aggregate_numberthis none thisrxd#2012
msgthis none thisrxd#204
nn_cthis none thisrxd#2015
message_dbthis none thisrxd#2025
english_weightthis none thisrxd#206
english_weight_shortthis none thisrxd#206
plural_deprecatedthis none thisrxd#2017
strip_articlethis none thisrxd#205
random_wordthis none thisrxd#2026
nn_tbthis none thisrxd#204
strip_binarythis none thisrxd#2012
last_word_startthis none thisrxd#2021
gibberishthis none thisrxd#2011
mergethis none thisrxd#2013
make_tablethis none thisrxd#2040
word_wrapthis none thisrxd#2050
_splitwordsthis none thisrxd#2021
colorize colourize cthis none thisrxd#2031
highlight_wordsthis none thisrxd#2019
fast_wordsthis none thisrxd#2019
re_sub*stitutethis none thisrxd#2020
smart_abbrevthis none thisrxd#2035
metaphonethis none thisrxd#20153
properties_likethis none thisrxd#2026
index_anythis none thisrxd#2010
_smart_abbrev_1this none thisrxd#201
_smart_abbrev_2this none thisrxd#2057
_smart_abbrev_3this none thisrxd#201
_smart_abbrev_4this none thisrxd#201
english_list_boldthis none thisrxd#2033
repeatthis none thisrxd#209
uncapitalizethis none thisrxd#2018
encrypt decryptthis none thisrxd#207
_tohashthis none thisrxd#2070
crapsumthis none thisrxd#2017
new_encrypt new_decryptthis none thisrxd#2029
format_bytesizethis none thisrxd#2023
cryptothis none thisrxd#2024
columnize_horiz*ontalthis none thisrxd#2028
reverse_nn rev_nnthis none thisrxd#202
spr*intf pr*intfthis none thisrxd#20109
capitalize_wordsthis none thisrxd#2020
superview svthis none thisrxd#2031
widenthis none thisrxd#208
bonus_numthis none thisrxd#2012
trim_binarythis none thisrxd#2019
short_numthis none thisrxd#2011
random_stringthis none thisrxd#206
silencethis none thisrxd#2016
scramblethis none thisrxd#2016
silence_wordsthis none thisrxd#2037
to_hexthis none thisrxd#2010
to_hex2this none thisrxd#209
match_aliases_genericsthis none thisrxd#2034

Properties

PropertyDefinerFlagsOwnerValue
digits#20rc#361"0123456789"
ascii#20rc#361" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
alphabet#20rc#361"abcdefghijklmnopqrstuvwxyz"
use_article_a#20r#29{"unit", "unix", "one", "once", "utility", "UNIX", "UNIX book"}
use_article_an#20r#29{}
tab#20rc#361"\t"
color_subs#20rc#361
list of 15{{"red", "/r", "~1b[31m"}, {"green", "/g", "~1b[32m"}, {"blue", "/b", "~1b[34m"}, {"yellow", "/y", "~1b[33m"}, {"magenta", "/m", "~1b[35m"}, {"cyan", "/c", "~1b[36m"}, {"white", "/w", "~1b[0m~1b[37m"}, {"brightred", "/R", "~1b[1m~1b[31m"}, {"brightgreen", "/G", "~1b[1m~1b[32m"}, {"brightblue", "/B", "~1b[1m~1b[34m"}, {"brightyellow", "/Y", "~1b[1m~1b[33m"}, {"brightmagenta", "/M", "~1b[1m~1b[35m"}, {"brightcyan", "/C", "~1b[1m~1b[36m"}, {"black", "/K", "~1b[1m~1b[30m"}, {"brightwhite", "/W", "~1b[1m~1b[37m"}}
proplikecache#20rc#361
list of 337{#530, 518, {"KMBT", "combat"}, {"HSTR", "history"}, {"STNK", "setting"}, {"MN", "money"}, {"T0", "death"}, {"RLS", "rules"}, {"MNRS", "manners"}, {"SKLS", "skills"}, {"MRTR", "murder"}, {"MFMNT", "movement"}, {"ETKT", "etiquette"}, {"OPXNS", "options"}, {"ALTS", "alts"}, {"KRNTNK", "grinding"}, {"KRFNK", "griefing"}, {"BKS", "bugs"}, {"STRS", "stress"}, {"RMRS", "rumors"}, {"PRNNS", "pronouns"}, {"ETTNK", "e-dating"}, {"RSK", "rescue"}, {"FNT", "feint"}, {"PBLK", "public"}, {"KLM", "climb"}, {"KKNS", "cocoons"}, {"ARMR", "armor"}, {"PRYR", "prayer"}, {"SKS", "sex"}, {"FT", "food"}, {"KRFT", "craft"}, {"WPNRPR", "weapon-repair"}, {"SKRT", "security"}, {"TRNNK", "training"}, {"XL", "chill"}, {"HL0", "health"}, {"FXNK", "fishing"}, {"WPNS", "weapons"}, {"TRFL", "travel"}, {"PRSR", "parser"}, {"ALS", "allows"}, {"FRNS", "friends"}, {"AJ", "age"}, {"MPS", "maps"}, {"KRM", "crime"}, {"RP", "rape"}, {"RPR", "repair"}, {"FK", "fuck"}, {"MTXNS", "mutations"}, {"RNT", "rent"}, {"JL", "jail"}, {"KRB", "grab"}, {"RSTRN", "restrain"}, {"SRX", "search"}, {"SKFNJ", "scavenge"}, {"FKPT", "fcpd"}, {"IP", "ip"}, {"PSWRT", "password"}, {"IMPRFMNT", "improvement"}, {"SP", "xp"}, {"EKSPRNS", "experience"}, {"KLN", "clone"}, {"KLNNK", "cloning"}, {"EMTS", "emotes"}, {"PS", "pose"}, {"KMNKXN", "communication"}, {"TL", "tell"}, {"PJ", "page"}, {"TLKNK", "talking"}, {"KKN", "cocoon"}, {"JM", "gym"}, {"PRFS", "prefs"}, {"HNJR", "hunger"}, {"PPL", "paypal"}, {"FRNS", "frenzy"}, {"MTT", "mutate"}, {"STTS", "status"}, {"HLP", "help"}, {"ITMS", "items"}, {"PRKTS", "practice"}, {"IMPLNTS", "implants"}, {"S", "say"}, {"APRTMNTS", "apartments"}, {"HM", "home"}, {"NTS", "nets"}, {"XTNT", "chatnet"}, {"STNT", "zotnet"}, {"TM", "time"}, {"RT", "radio"}, {"FTXS", "fetishes"}, {"LNJ", "lunge"}, {"FS", "phase"}, {"0RST", "thirst"}, {"WTR", "water"}, {"FKTSTL", "fightstyle"}, {"AKRSF", "aggressive"}, {"BRSRK", "berserk"}, {"PSFST", "pacifist"}, {"KXS", "cautious"}, {"STNS", "stance"}, {"NRML", "normal"}, {"UPTT", "update"}, {"SKS", "sx"}, {"KPS", "cops"}, {"NT", "@nude"}, {"PRT", "party"}, {"JRNLS", "journals"}, {"KSTS", "quests"}, {"AXFMNTS", "achievements"}, {"FKTNK", "fighting"}, {"TRNK", "drink"}, {"HW0NHNT", "hewithonhand"}, {"HP", "hp"}, {"KBHTL", "cube_hotel"}, {"EKSPLSFS", "explosives"}, {"TRNKNK", "drinking"}, {"STTS", "stats"}, {"KRPS", "corps"}, {"KRP", "corp"}, {"KNTRKTS", "contracts"}, {"FTBK", "feedback"}, {"SK", "sc"}, {"SKR", "score"}, {"APT", "apt"}, {"HRN", "horny"}, {"NB", "newbie"}, {"XRJN", "chargen"}, {"KL", "kill"}, {"ATK", "attack"}, {"KMBTPXNS", "combatoptions"}, {"PWRTK", "powerattack"}, {"TJ", "dodge"}, {"PR", "parry"}, {"KMNS", "commands"}, {"PRSN", "prison"}, {"FKT", "fight"}, {"JR", "gear"}, {"FL", "follow"}, {"RRLNK", "rerolling"}, {"KRTTS", "credits"}, {"FKSNK", "fixing"}, {"XNLS", "channels"}, {"TMPRTR", "temperature"}, {"HT", "heat"}, {"KLT", "cold"}, {"TRKS", "drugs"}, {"KRFTNK", "crafting"}, {"PNS", "penis"}, {"LK", "look"}, {"PRFRNSS", "preferences"}, {"STRS", "stars"}, {"KL0NK", "clothing"}, {"WR", "wear"}, {"SLT", "slut"}, {"HMBRJRS", "hamburgers"}, {"AM", "aim"}, {"ML", "mail"}, {"TLT", "delete"}, {"KNK", "king"}, {"BS", "biz"}, {"FNTL", "fondle"}, {"MSTRBT", "masturbate"}, {"WNK", "wank"}, {"SNS", "science"}, {"ETPS", "edps"}, {"KTNK", "quitting"}, {"IMPRFS", "improvise"}, {"JSS", "Jesus"}, {"TJ", "dj"}, {"TJNT", "djnet"}, {"TJB0", "djbooth"}, {"MSK", "music"}, {"KKNK", "cooking"}, {"TNT", "donate"}, {"TNTNK", "donating"}, {"TNXN", "donation"}, {"KMNKXNS", "communications"}, {"EKSMN", "examine"}, {"LKT", "logout"}, {"FR", "fire"}, {"RT", "ready"}, {"RJKT", "ragequit"}, {"WMN", "women"}, {"STP", "stop"}, {"WMN", "woman"}, {"STNKS", "settings"}, {"KMPN", "company"}, {"BSNS", "business"}, {"ILNS", "illness"}, {"SKNS", "sickness"}, {"TSSS", "diseases"}, {"TNK", "@doing"}, {"KMPTR", "computer"}, {"BRN", "brown"}, {"M", "me"}, {"TSKRB", "@describe"}, {"ATMNS", "admins"}, {"SMKL", "smuggle"}, {"BLPRNT", "blueprint"}, {"MSM", "museum"}, {"FRPL", "foreplay"}, {"LMP", "lmap"}, {"LKS", "locks"}, {"BNRS", "boners"}, {"NPKS", "npcs"}, {"KNFRSXN", "conversation"}, {"STR", "store"}, {"BYNK", "buying"}, {"MK", "make"}, {"HSNK", "housing"}, {"HLT", "hold"}, {"LRNNK", "learning"}, {"PPSKNK", "poopsocking"}, {"PRKNNS", "pregnancy"}, {"KT", "@quit"}, {"TSNK", "dozing"}, {"WLT", "wield"}, {"SST", "suicide"}, {"RTXN", "radiation"}, {"ORFN", "orphan"}, {"KMP", "gmap"}, {"KL0S", "clothes"}, {"NS", "news"}, {"TRS", "DRS"}, {"ABRXN", "abortion"}, {"SPLRS", "spoilers"}, {"JBS", "jobs"}, {"SKL", "<skill>"}, {"TPK", "<topic>"}, {"JKT", "joyquit"}, {"BNTS", "bounties"}, {"BNT", "bounty"}, {"PLNT", "playnet"}, {"KSNS", "coccoons"}, {"PSWRT", "@password"}, {"MLTPL", "multiplay"}, {"MLTPL", "multi-play"}, {"PRKNNT", "pregnant"}, {"KRM", "karma"}, {"ITS", "ideas"}, {"RLPLYNK", "roleplaying"}, {"ML", "mail2"}, {"MNNK", "mining"}, {"MKP", "mcp"}, {"HLFLFLP", "help help help"}, {"TKS", "tags"}, {"TK", "tag"}, {"RMTK", "rmtag"}, {"TLTK", "deltag"}, {"PRFS", "@prefs"}, {"KNKSKNS", "gangsigns"}, {"RNTM", "@random"}, {"STLNK", "stealing"}, {"KRPRXNS", "corporations"}, {"NTSNT", "nudesnet"}, {"INFXNS", "invasions"}, {"INFXN", "invasion"}, {"SKRPTNK", "scripting"}, {"TRKRS", "triggers"}, {"TMRS", "timers"}, {"SKRPTS", "scripts"}, {"IFFLNNTKNTJTP", "I've_fallen_and_I_can't_get_up"}, {"TNTSKTMNSTHLPYXT", "dontaskadminstohelpyoucheat"}, {"B", "B)"}, {"RBR", "robbery"}, {"SKM", "scam"}, {"JLMR", "gilmore"}, {"SKMNK", "scamming"}, {"BTMNS", "badmins"}, {"NKN0RP", "necanthrope"}, {"RSPS", "recipes"}, {"TNK", "doing"}, {"PSWRTS", "passwords"}, {"ENM", "enema"}, {"KRPXT", "corpchat"}, {"MSRF", "mservo"}, {"FKTSTLS", "fight_styles"}, {"FKTNKSTL", "fightingstyle"}, {"STL", "style"}, {"FKTNKSTL", "fighting_style"}, {"STLS", "styles"}, {"FKTSTLS", "fightstyles"}, {"FKTNKSTLS", "fightingstyles"}, {"AMNK", "aiming"}, {"LKPKNK", "lockpicking"}, {"PK", "pick"}, {"TXRS", "teachers"}, {"ORL", "oral"}, {"BLJBS", "blowjobs"}, {"SMLS", "smells"}, {"WSLST", "wizlist"}, {"WSRTS", "wizards"}, {"WNTT", "wanted"}, {"TTNK", "dating"}, {"IMK", "im_gay"}, {"JF", "give"}, {"KNFKRXN", "configuration"}, {"RJ", "rage"}, {"HNTS", "hints"}, {"URNXN", "urination"}, {"PS", "piss"}, {"PNK", "peeing"}, {"PJNK", "paging"}, {"BRJ", "barge"}, {"IMPRF", "improv"}, {"LSTS", "lists"}, {"PWP", "pwipe"}, {"XRKTRJNRXN", "character_generation"}, {"PBK", "pubic"}, {"PLS", "police"}, {"ARSTT", "arrested"}, {"TLT", "tilde"}, {"", "~"}, {"HLP", "he;lp"}, {"", "@"}, {"STFTHTFR", "stuffed_whatever"}, {"RP", "rp"}, {"TKN", "dagon"}, {"SNTKS", "syntax"}, {"HKLNK", "haggling"}, {"HKL", "haggle"}, {"BRKT", "barcode"}, {"BRKT", "bar_code"}, {"RPTR", "rupture"}, {"BLNT", "blind"}, {"RRL", "reroll"}, {"TPK", "topic"}, {"EMT", "emote"}, {"PFP", "pvp"}, {"OLTLTS", "old_alts"}, {"OTL", "outlaw"}, {"OTLS", "outlaws"}, {"XLNJS", "challenges"}, {"XLNJ", "challenge"}, {"HRTKR", "hardcore"}, {"ASNXN", "ascension"}}
lettersnumbers#20rc#361"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
line_noise#20rc#361"#$%^&*_/><|{}[]`()-+.="
help_msg#72rc#361
list of 122{"*** NOTE: for more help on any verb, do 'help $su: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}", "", " Object information:", ":nn(obj [,sep]) => \"ObjectName (#obj)\"", ":nn(obj-list, [,sep]) => \"One (#o1), Two (#o2) and Three (#o3)\"", ":nn_c(obj, [, sep]) => same as above, but with pointless colors", ":nn_tb(obj) => \"ObjectName #obj\", returns 0 if !valid", "", " English language:", ":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", "", ":plural(\"matrix\") => \"matrices\" (plurals for nouns)", ":aggregate_number(17) => \"lots of\" (vague numbers)", ":english_weight(2000) => \"2 kilograms\" (grams -> english)", ":english_weight_short(2000) => \"2kg\" (grams -> short form)", ":strip_article(\"an apple\") => \"apple\" (remove 'the', 'a', 'an')", ":random_word() => \"buttons\" (random from whole db)", ":gibberish(string) => random words, about as many as string", ":merge(paragraph1, paragraph2, join-string)", " => new paragraph (list of strings)", ":smart_abbrev(string or list [,eachbelow [,totalbelow]])", " => string or list, shortened to meet requirements", "", " Message handling:", ":msg(list or string) => single string picked at random", ":message_db(obj-list, prop) => { {objs1, msg1}, {objs2, msg2} ... }", "", " 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", ":fast_words (string [,char]) => word-list -- like :explode", "", " 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", ":match_aliases (string, obj-list) => match against names and aliases.", ":metaphone (string) => metaphone code for a word (try it)", "", " Pretty printing:", ":s/pr[intf] ([OBJ,]STR, *, *, ...) => formatted string (see documentation)", ":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", ":widen (string[,n]) => string with 1 (or n) spaces between chars", "", ":make_table (header-colors, headers, row-colors, rows, row-widths)", " => a pretty-printed table using the given colors, widths", ":word_wrap (list of strings, linelength [,color])", " => list of strings, none longer than linelength", ":colorize (string [, ok-colors])", " => uses special escape codes to color text, like \"/r\" for red.", ":highlight (string, highlight-words)", " => string with each of highlight-words bolded", "", " Substitutions", ":substitute (string,subst_list [,case]) -- general substitutions.", ":substitute_delimited (string,subst_list [,case])", " -- like subst, but uses index_delim", ":re_sub (string, subst_list, [,case]) -- like subst, with regexes.", ":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", ":escape (string) => escapes tildes in a string properly.", ":strip_binary (string) => string without any binary characters", "", " A useful property:", "alphabet => \"abcdefghijklmnopqrstuvwxyz\"", "", "Suspended versions (with _suspended at end of name) for", " :print :from_value :columnize/se :match"}
aliases#1rc#361{"string", "utils"}
description#1rc#361{"This is the string utilities utility package. See `help $string_utils' for more details."}
object_size#1r#29{151193, 1298433815}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rc#361<clear>
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n20_1 #20:left n122_8 #122:strip n20_1->n122_8 n20_0 #20:space n20_1->n20_0 n20_2 #20:right n20_2->n122_8 n20_2->n20_0 n20_3 #20:centre n20_3->n122_8 n20_3->n20_0 n20_4 #20:columnize n20_4->n20_1 n20_4->n122_8 n47_0 #47:make n20_4->n47_0 n20_7 #20:names_of n20_11 #20:trimr n20_7->n20_11 n20_16 #20:literal_object n51_2 #51:toobj n20_16->n51_2 n20_20 #20:match_player n20_16->n20_20 n38_10 #38:match_recipient n20_16->n38_10 n45_0 #45:has_property n20_16->n45_0 n20_20->n20_16 n30_0 #30:find n20_20->n30_0 n20_19 #20:match_object n20_19->n20_16 n20_21 #20:match_player_or_object n20_21->n20_20 n107_43 #107:tell n20_21->n107_43 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 n47_6 #47:find_insert n20_31->n47_6 n20_32 #20:substitute_d*elimited n20_32->n47_6 n20_33 #20:_cap_property n20_33->n45_0 n20_33->n20_33 n20_6 #20:english_list n20_33->n20_6 n20_34 #20:pronoun_sub n20_34->n20_33 n20_15 #20:capitalize n20_34->n20_15 n20_35 #20:pronoun_sub_secure n20_35->n20_34 n20_37 #20:alt_pronoun_sub n20_37->n20_33 n45_2 #45:has_verb n20_37->n45_2 n20_39 #20:words n20_10 #20:triml n20_39->n20_10 n20_41 #20:to_value n20_41->n20_0 n20_113 #20:_tohash n20_41->n20_113 n20_43 #20:_tolist n20_41->n20_43 n20_113->n20_10 n20_45 #20:_toscalar n20_113->n20_45 n20_43->n20_10 n20_43->n20_45 n20_42 #20:prefix_to_value n20_42->n20_10 n20_42->n20_45 n51_3 #51:toerr n20_45->n51_3 n20_46 #20:parse_command n20_46->n20_19 n20_46->n20_39 n51_19 #51:get_prep n20_46->n51_19 n20_5 #20:from_list n20_46->n20_5 n51_18 #51:full_prep n20_46->n51_18 n51_17 #51:short_prep n20_46->n51_17 n20_47 #20:from_value n20_47->n20_47

Showing 48 of 114 verbs; 66 not shown.

Source

space

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

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. fill must be 10 or fewer characters long.";
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)
11if (length(fill) > 10)
12raise(E_INVARG);
13endif
14fill = fill + fill;
15fill = fill + fill;
16fill = fill + fill;
17elseif ((n = abs(n)) < 70)
18return "                                                                      "[1..n];
19else
20fill = "                                                                      ";
21endif
22m = (n - 1) / length(fill);
23while (m)
24if (length(fill) > 500)
25raise(E_QUOTA);
26endif
27fill = fill + fill;
28m = m / 2;
29endwhile
30return (n > 0) ? fill[1..n] | fill[($ + 1) + n..$];

left

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1"Copied from string utilities (#20):_left by Hacker (#36) Fri Oct 29 15:46:29 2010 CDT";
2"Copied from string utilities (#20):left by Hacker (#36) Fri Oct 29 15:46:04 2010 CDT";
3"$string_utils:left(string,width[,filler])";
4"";
5"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>.";
6"";
7"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.";
8{text, len, ?fill = " "} = args;
9abslen = abs(len);
10out = tostr(text);
11ansilen = length(out) - length($ansi:strip(out));
12if ((ln = length($ansi:strip(out))) < abslen)
13return out + this:space(ln - abslen, fill);
14else
15return (len > 0) ? out | out[1..abslen + ansilen];
16endif

right

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

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($ansi:strip(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 #29Definer #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 ((ln = length($ansi:strip(out))) < abslen)
10return (this:space((abslen - ln) / 2, lfill) + out) + this:space(((abslen - ln) + 1) / -2, rfill);
11else
12return (len > 0) ? out | out[1..abslen];
13endif

columnize columnise

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1"columnize (items, n [, width[, hard]]) - 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, ?hard = 0} = 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
15diff = length(line) - length($ansi:strip(line));
16result = listappend(result, line[1..min(length(line), width + diff)]);
17endfor
18return result;

from_list

Spec this none thisFlags rxdOwner #29Definer #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 #29Definer #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 #29Definer #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() ! E_VERBNF => item.name') + "(") + tostr(item)) + ")   ";
6endif
7endfor
8return $string_utils:trimr(line);

from_seconds

Spec this none thisFlags rxdOwner #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #20

Referenced by

Source

1"capitalizes its argument.";
2if (string = args[1])
3ansi = 0;
4for i in [1..length(string)]
5if (string[i] == "~")
6ansi = 1;
7elseif (ansi && (string[i] == "m"))
8ansi = 0;
9elseif (!ansi)
10if (testi = index("abcdefghijklmnopqrstuvwxyz", string[i], 0))
11string[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[testi];
12return string;
13endif
14endif
15endfor
16endif
17return string;

literal_object

Spec this none thisFlags rxdOwner #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #20

Referenced by

none

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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 gn

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1"$string_utils:group_number(INT n [, sep_char])";
2"$string_utils:group_number(FLOAT n, [INT precision [, scientific [, sep_char]]])";
3"";
4"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\".";
5"For floats, the arguements precision (defaulting to 4 in this verb) and scientific are the same as given in floatstr().";
6if (typeof(args[1]) == INT)
7{n, ?comma = ","} = args;
8result = "";
9sign = (n < 0) ? "-" | "";
10n = tostr(abs(n));
11elseif (typeof(args[1]) == FLOAT)
12{n, ?prec = 4, ?scien = 0, ?comma = ","} = args;
13sign = (n < 0.0) ? "-" | "";
14n = floatstr(abs(n), prec, scien);
15i = index(n, ".");
16result = n[i..$];
17n = n[1..i - 1];
18else
19return E_INVARG;
20endif
21while ((len = length(n)) > 3)
22result = (comma + n[len - 2..len]) + result;
23n = n[1..len - 3];
24endwhile
25return (sign + n) + result;
26"Code contributed by SunRay";

english_number

Spec this none thisFlags rxdOwner #29Definer #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 #29Definer #20

Referenced by

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 #29Definer #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 #29Definer #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 #29Definer #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 #361Definer #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 #361Definer #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
25(s && (typeof(s) == LIST)) && (s = s[random($)]);
26if (ucase && (s && ((typeof(s) == STR) && (((z = index(this.alphabet, s[1], 1)) < 27) && (z > 0)))))
27s[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[z];
28endif
29endif
30return (typeof(s) == ERR) ? s | tostr(s);

pronoun_sub ps

Spec this none thisFlags rxdOwner #361Definer #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"In addition, you can have the direct or indirect article prepended to object substitutions, so that 'book' becomes 'a book' or 'the book':";
12"%dn, %dd, %di, %dt, %dl => object:dname() ('the' object)";
13"%in, %id, %ii, %it, %il => object:iname() ('a' object)";
14"SOME WORDS OF WISDOM TO NEW PROGRAMMERS: Please pass arguments explicitly to this verb unless you know exactly what you are doing. Most of the time, the default trailing subs (%d and %i) are given as #-1 which is invalid and will cause tracebacks. Many irritating but minor errors can be avoided by paying attention to proper usage of $su:ps. If you do not understand anything here, please ask someone who does before wantonly putting $su:ps in your code.";
15{string, ?who = player, ?thing = caller, ?where = $nothing, ?dobject = dobj, ?iobject = iobj} = args;
16where = valid(where) ? where | (valid(who) ? who.location | where);
17if (!string)
18if (typeof(string) == LIST)
19raise(E_INVARG, "empty list given to $su:ps");
20endif
21return "";
22endif
23if (typeof(string) == LIST)
24string = string[random($)];
25endif
26old = tostr(string);
27new = "";
28objspec = "nditl";
29objects = {who, dobject, iobject, thing, where};
30prnspec = "sopqrSOPQR";
31prprops = {"ps", "po", "pp", "pq", "pr", "Ps", "Po", "Pp", "Pq", "Pr"};
32oldlen = length(old);
33while ((prcnt = index(old, "%")) && (prcnt < oldlen))
34objects[1] = who;
35s = old[k = prcnt + 1];
36if ((s == "<") && (gt = index(old[k + 2..$], ">")))
37"handling %<verb> ";
38gt = (gt + k) + 1;
39vb = old[k + 1..gt - 1];
40vbs = who;
41if ((length(vb) > 2) && (vb[2] == ":"))
42" %<d:verb>";
43vbs = objects[index(objspec, vb[1]) || 1];
44vb = vb[3..$];
45endif
46vb = (valid(vbs) && has_callable_verb(vbs, "verb_sub")) ? vbs:verb_sub(vb) | this:(verb)(vb, vbs);
47new = (new + old[1..prcnt - 1]) + vb;
48k = gt;
49else
50include_direct = 0;
51include_indirect = 0;
52if (((old[k] == "d") && (k < oldlen)) && index(objspec, old[k + 1]))
53include_direct = 1;
54old = old[1..k - 1] + old[k + 1..oldlen];
55oldlen = oldlen - 1;
56s = old[k];
57elseif (((old[k] == "i") && (k < oldlen)) && index(objspec, old[k + 1]))
58include_indirect = 1;
59old = old[1..k - 1] + old[k + 1..oldlen];
60oldlen = oldlen - 1;
61s = old[k];
62endif
63if (((op = index(objspec, old[k])) && (k < oldlen)) && index(prnspec, old[k + 1]))
64objects[1] = objects[op];
65old = old[1..k - 1] + old[k + 1..oldlen];
66oldlen = oldlen - 1;
67s = old[k];
68endif
69cp_args = {};
70if (brace = index("([", s))
71if (!(w = index(old[k + 1..oldlen], ")]"[brace])))
72return new + old;
73else
74p = old[prcnt + 2..(k = k + w) - 1];
75if (brace == 1)
76"%(property)";
77cp_args = {who, p};
78elseif (p[1] == "#")
79"%[#n] => object number";
80s = (o = index(objspec, p[2])) ? tostr(objects[o]) | (("[" + p) + "]");
81elseif (!(o = index(objspec, p[1])))
82s = ("[" + p) + "]";
83else
84" %[dproperty] ";
85cp_args = {objects[o], p[2..w - 1], strcmp(p[1], "a") < 0};
86endif
87endif
88elseif (o = index(objspec, s))
89if (include_direct)
90s = (strcmp(s, "a") < 0) ? objects[o]:dnamec() | objects[o]:dname();
91elseif (include_indirect)
92s = (strcmp(s, "a") < 0) ? objects[o]:inamec() | objects[o]:iname();
93else
94oname = objects[o]:name();
95if (is_a(objects[o], $player))
96s = oname;
97else
98s = (strcmp(s, "a") < 0) ? $su:capitalize(oname) | oname;
99endif
100endif
101elseif (w = index(prnspec, s, 1))
102cp_args = {objects[1], prprops[w]};
103elseif (s == "#")
104s = tostr(who);
105elseif (s != "%")
106s = "%" + s;
107endif
108if (!cp_args)
109new = (new + old[1..prcnt - 1]) + s;
110else
111if (typeof(sub = $string_utils:_cap_property(@cp_args)) != ERR)
112new = (new + old[1..prcnt - 1]) + sub;
113else
114new = (((new + old[1..prcnt - 1]) + "%(") + tostr(sub)) + ")";
115endif
116endif
117endif
118old = old[k + 1..oldlen];
119oldlen = oldlen - k;
120endwhile
121return new + old;

pronoun_sub_secure

Spec this none thisFlags rxdOwner #29Definer #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 #29Definer #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 #361Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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.";
3if (length(string = args[1]) > 1)
4result = this:_tohash(string[2..$]);
5if (typeof(result[2]) == HASH)
6return {1, result[2]};
7endif
8endif
9result = this:_tolist(string + "}");
10if (result[1] && (result[1] != $string_utils:space(result[1])))
11return {0, tostr("after char ", length(string) - result[1], ":  ", result[2])};
12elseif (typeof(result[1]) == INT)
13return {0, "missing } or \""};
14elseif (length(result[2]) > 1)
15return {0, "comma unexpected."};
16elseif (result[2])
17return {1, result[2][1]};
18else
19return {0, "missing expression"};
20endif

prefix_to_value

Spec this none thisFlags rxdOwner #29Definer #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", "_tohash", "_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 #29Definer #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", "_tohash", "_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 #29Definer #20

Referenced by

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 #29Definer #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 #361Definer #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 #361Definer #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 #29Definer #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, "\\", "\\\\"), "\"", "\\\""), $ansi.reset, "\"");
17elseif (typeof(value) == ERR)
18return $code_utils:error_name(value);
19else
20return tostr(value);
21endif

reverse

Spec this none thisFlags rxdOwner #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 #361Definer #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$command_utils:suspend_if_needed(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$command_utils:suspend_if_needed(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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #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 rxOwner #29Definer #20

Referenced by

Source

1"name_and_number(object [,sepr] [,english_list_args]) => \"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"The third through nth arguments to nn_list corresponds to the second through nth arguments to English_list, and are passed along untouched.";
4{objs, ?sepr = " ", @eng_args} = args;
5if (typeof(objs) != LIST)
6objs = {objs};
7endif
8name_list = {};
9for what in (objs)
10name = valid(what) ? what.name | {"<invalid>", "$nothing", "$ambiguous_match", "$failed_match"}[1 + (what in {#-1, #-2, #-3})];
11name = tostr(name, sepr, "(", what, ")");
12name_list = {@name_list, name};
13endfor
14return this:english_list(name_list, @eng_args);

columnize_suspended columnise_suspended

Spec this none thisFlags rxdOwner #29Definer #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$command_utils:suspend_if_needed(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 #29Definer #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 #29Definer #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 #29Definer #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 #29Definer #20

Referenced by

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 #29Definer #20

Referenced by

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 #29Definer #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 #29Definer #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 #29Definer #20

Referenced by

none

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 #29Definer #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.";
2"args[2] is optional alphabet to use instead of $string_utils.alphabet.";
3{s, ?alphabet = this.alphabet} = args;
4index = length(s);
5if (!s)
6return alphabet[1];
7elseif (s[$] == alphabet[$])
8return this:incr_alpha(s[1..index - 1], alphabet) + alphabet[1];
9else
10t = index(alphabet, s[index]);
11return s[1..index - 1] + alphabet[t + 1];
12endif

is_float

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

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]+%) *$");

inside_quotes

Spec this none thisFlags rxOwner #29Definer #20

Referenced by

none

Source

1"Copied from Moo_tilities (#332):inside_quotes by Mooshie (#106469) Tue Dec 23 10:26:49 1997 PST";
2"Usage: inside_quotes(STR)";
3"Is the  end of the given string `inside' a doublequote?";
4"Called from $code_utils:substitute.";
5{string} = args;
6quoted = 0;
7while (i = index(string, "\""))
8if ((!quoted) || (string[i - 1] != "\\"))
9quoted = !quoted;
10endif
11string = string[i + 1..$];
12endwhile
13return quoted;

strip_all_but_seq

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

Source

1":strip_all_but_seq(string, keep) => chars in string not in exact sequence of keep removed.";
2":strip_all_but() works similarly, only it does not concern itself with the sequence, just the specified chars.";
3string = args[1];
4wanted = args[2];
5output = "";
6while (m = match(string, wanted))
7output = output + string[m[1]..m[2]];
8string = string[m[2] + 1..length(string)];
9endwhile
10return output;

ps_backup

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

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

mel_match

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

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
11exact_match = #-1;
12partial_match = #-1;
13pairs = args[2..$];
14while (pairs)
15objs = pairs[1];
16if (typeof(objs) != LIST)
17objs = {pairs[1]};
18endif
19prop = pairs[2];
20for object in (objs)
21str_list = `object.(prop) ! E_PERM, E_PROPNF => {}';
22if (typeof(str_list) == STR)
23str_list = {str_list};
24endif
25if (subject in str_list)
26if (valid(exact_match) && (exact_match != object))
27return $ambiguous_match;
28else
29exact_match = object;
30endif
31else
32for string in (str_list)
33if (index(string, subject) == 1)
34if (valid(partial_match) && (partial_match != object))
35partial_match = $ambiguous_match;
36break;
37else
38partial_match = object;
39endif
40endif
41endfor
42endif
43endfor
44pairs = listdelete(pairs, 1);
45pairs = listdelete(pairs, 1);
46endwhile
47if (valid(exact_match))
48return exact_match;
49elseif (valid(partial_match))
50return partial_match;
51elseif (partial_match == $ambiguous_match)
52return $ambiguous_match;
53else
54return $failed_match;
55endif

match_backup_spunky

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

Source

1"Copied from string utilities (#20):match by Hacker (#36) Mon Feb 23 20:07:24 2004 PST";
2"$string_utils:match(string [, obj-list, prop-name]*)";
3"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.";
4"The argument string is matched against all of the strings in the property values.";
5"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.";
6"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.";
7"Finally, if there are no exact or partial matches, then $failed_match is returned.";
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
37endfor
38endfor
39#97:tell("[su] default case");
40return no_exact_match && (no_partial_match && $failed_match);

match_aliases

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1"$string_utils:match_aliases(string, objlist [, who])";
2"The argument string is matched against all of the strings in the :name() and :aliases() of the objects in objlist. If 'who' is provided and is a player with .private_aliases defined, it will be used as well.";
3"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.";
4"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.";
5"Finally, if there are no exact or partial matches, then $failed_match is returned.";
6{subj, ?olist = {}, ?who = #-1} = args;
7if (subj == "")
8return $nothing;
9endif
10if (typeof(olist) != LIST)
11olist = {olist};
12endif
13if ((gamevalid(who) && is_a(who, $player)) && has_property(who, "private_aliases"))
14matchlist = (subj in who.private_aliases) ? who.private_aliases[subj] | {};
15matching_objs = {};
16for m in (matchlist)
17for o in (olist)
18if (((o == m) || is_a(o, m)) && (o != who))
19matching_objs = {@matching_objs, o};
20endif
21yield 0;
22endfor
23yield 0;
24endfor
25if (matching_objs)
26if (length(matching_objs) > 1)
27return $ambiguous_match;
28else
29return matching_objs[1];
30endif
31endif
32endif
33for o in (olist)
34if (gamevalid(o) && ((subj == o.name) || (subj == o:name())))
35return o;
36endif
37yield 0;
38endfor
39for o in (olist)
40if (gamevalid(o) && (subj in o.aliases))
41return o;
42endif
43yield 0;
44endfor
45for o in (olist)
46if (gamevalid(o))
47for name in ({o:name(), @o:aliases()})
48if (index(name, subj) == 1)
49return o;
50endif
51yield 0;
52endfor
53endif
54yield 0;
55endfor
56return $failed_match;

escape

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1text = args[1];
2if (typeof(text) != STR)
3return "";
4endif
5"WARNING: If you're editing this verb, chances are you're only seeing one tilde as the third argument to strsub in the folling line.  One of the tildes gets eaten on output, so you need to add it back in before you save, such that the third argument has two tildes.";
6text = strsub(text, "~", "~~");
7return text;

match_aliases_ambiguous

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1"Copied from string utilities (#20):match_aliases by Hacker (#36) Fri Mar  5 20:34:58 2004 PST";
2"$string_utils:match_aliases(string, objlist)";
3"The argument string is matched against all of the strings in the :name() and :aliases() of the objects in objlist.";
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 object in ((typeof(olist = args[2]) == LIST) ? olist | {olist})
13if (valid(object))
14str_list = {object:name(), @object:aliases()};
15if (subject in str_list)
16if (no_exact_match)
17no_exact_match = object;
18elseif (no_exact_match != object)
19return $ambiguous_match;
20endif
21else
22for string in (str_list)
23if (index(string, subject) != 1)
24elseif (no_partial_match)
25no_partial_match = object;
26elseif (no_partial_match != object)
27no_partial_match = $ambiguous_match;
28endif
29endfor
30endif
31endif
32endfor
33return no_exact_match && (no_partial_match && $failed_match);

plural

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1":plural(STR item [, count[, mode]]) => pluralization";
2"";
3"Mode can be 0 (default) -- english number, 1 -- literal number, or 2 -- no number.";
4"";
5"Examples:";
6"  :plural(\"dog\") => \"dogs\"";
7"  :plural(\"a dog\") => \"some dogs\"";
8"  :plural(\"fart\", 3) => \"three farts\"";
9{instring, ?count = "N", ?mode = 0} = args;
10article = "";
11if (count == 1)
12if (mode != 1)
13return instring;
14else
15return tostr(count, " ", instring);
16endif
17endif
18if (matchspec = match(instring, " of "))
19index = matchspec[1] - 1;
20return this:plural(instring[1..index], count) + instring[index + 1..$];
21elseif (length(instring) > 2)
22if (instring[1..2] == "a ")
23instring = instring[3..$];
24article = "some ";
25endif
26elseif (length(instring) > 3)
27if (instring[1..3] == "an ")
28instring = instring[4..$];
29article = "some ";
30endif
31elseif (length(instring) > 4)
32if (instring[1..4] == "one ")
33instring = instring[5..$];
34article = "some ";
35endif
36endif
37if (length(instring) > 2)
38if ((instring[$ - 1..$] == "ex") || (instring[$ - 1..$] == "ix"))
39nounval = instring[1..$ - 2] + "ices";
40elseif (instring[$ - 1..$] == "um")
41nounval = instring[1..$ - 2] + "a";
42elseif (instring[$ - 1..$] == "us")
43nounval = instring[1..$ - 2] + "i";
44elseif (instring[$ - 1..$] == "os")
45nounval = instring[1..$ - 2] + "oi";
46elseif (instring[$ - 1..$] == "oy")
47nounval = instring[1..$ - 2] + "oys";
48elseif (instring[$ - 1..$] == "ey")
49nounval = instring[1..$ - 2] + "eys";
50elseif (instring[$ - 1..$] == "ay")
51nounval = instring[1..$ - 2] + "ays";
52elseif (instring[$] == "y")
53nounval = instring[1..$ - 1] + "ies";
54elseif (((instring[$ - 1..$] == "ch") && (instring[$ - 2] != "o")) || (instring[$..1] == "sh"))
55nounval = instring + "es";
56elseif ((instring[$] == "x") || (instring[$] == "s"))
57nounval = instring + "es";
58else
59nounval = instring + "s";
60endif
61elseif (length(instring) > 1)
62nounval = instring + "s";
63else
64nounval = "nothings";
65endif
66if (count == "N")
67return article + nounval;
68elseif (mode == 1)
69return tostr(count, " ", nounval);
70elseif (mode == 2)
71return nounval;
72else
73count = $su:english_number(count);
74return (count + " ") + nounval;
75endif

aggregate_number

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1number = args[1];
2if (number < 11)
3return this:english_number(number);
4elseif (number < 20)
5return "lots of";
6elseif (number == 20)
7return "a score of";
8elseif (number < 51)
9return "scores of";
10else
11return "massive numbers of";
12endif

msg

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1if (args[1] == {})
2return "";
3endif
4return (typeof(args[1]) == LIST) ? args[1][random($)] | args[1];

nn_c

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

Source

1"Copied from string utilities (#20):nn by Hacker (#36) Sat Apr 10 03:54:39 2004 PDT";
2"name_and_number(object [,sepr] [,english_list_args]) => \"ObjectName (#object)\"";
3"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.";
4"The third through nth arguments to nn_list corresponds to the second through nth arguments to English_list, and are passed along untouched.";
5{objs, ?sepr = " ", @eng_args} = args;
6if (typeof(objs) != LIST)
7objs = {objs};
8endif
9name_list = {};
10for what in (objs)
11name = valid(what) ? what.name | {"<invalid>", "$nothing", "$ambiguous_match", "$failed_match"}[1 + (what in {#-1, #-2, #-3})];
12name = tostr(name, sepr, (("(" + $ansi.bg_blue) + $ansi.bold_on) + $ansi.white, what, $ansi.reset + ")");
13name_list = {@name_list, name};
14endfor
15return this:english_list(name_list, @eng_args);

message_db

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":message_db(LIST objs, STR prop) => Returns a pruned message list of the format {{objects_with_message}, message}";
2msg_db = {};
3names = {};
4things = args[1];
5prop = args[2];
6for x in (things)
7added = 0;
8msg = `x:(prop)() ! ANY => ""';
9if (!msg)
10msg = `x.(prop) ! ANY => ""';
11endif
12if (msg_db)
13for y in [1..length(msg_db)]
14$cu:sin(0);
15if (msg_db[y][2] == msg)
16msg_db[y][1] = listappend(msg_db[y][1], x);
17added = 1;
18endif
19endfor
20endif
21if (!added)
22msg_db = setadd(msg_db, {{x}, msg});
23endif
24endfor
25return msg_db;

english_weight

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1weight = args[1];
2if (weight < 1000)
3return tostr(weight) + " grams";
4else
5return (tostr(weight = weight / 1000) + " kilogram") + ((weight > 1) ? "s" | "");
6endif

english_weight_short

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1weight = toint(args[1]);
2if (weight < 1000)
3return tostr(weight) + "g";
4else
5return floatstr(tofloat(weight) / 1000.0, 1) + "kg";
6endif

plural_deprecated

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1"Copied from string utilities (#20):plural by Spunky (#97) Wed May  5 13:15:49 2004 PDT";
2string = args[1];
3if (idx = index(string, " of "))
4what = string[1..idx - 1];
5else
6what = string;
7endif
8if ((what[$] == "s") || (what[$] == "x"))
9what = what + "es";
10else
11what = what + "s";
12endif
13if (idx)
14return what + string[idx..$];
15else
16return what;
17endif

strip_article

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1text = args[1];
2text = strsub(text, "the ", "");
3text = strsub(text, "a ", "");
4text = strsub(text, "an ", "");
5return text;

random_word

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1objnums = tonum(max_object());
2while (1)
3what = #-1;
4while ((!is_a(what, #1)) || (!what.description))
5wn = random(objnums);
6what = toobj(wn);
7endwhile
8desc = what.description;
9if (typeof(desc) == LIST)
10desc = desc[random(length(desc))];
11endif
12dl = $su:explode(desc, " ");
13w = "";
14nwords = length(dl);
15tries = 0;
16while ((length(w) < 3) && (tries < nwords))
17w = dl[random(nwords)];
18tries = tries + 1;
19endwhile
20if (length(w) >= 3)
21w = $su:strip_chars(w, ".?!,");
22w = $su:lowercase(w);
23return w;
24endif
25$cu:sin();
26endwhile

nn_tb

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1what = args[1];
2if (valid(what))
3return (what.name + " ") + tostr(what);
4endif

strip_binary

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1if (length(args) != 1)
2raise(E_ARGS);
3endif
4s = args[1];
5bin = decode_binary(s);
6safe_s = "";
7for b in (bin)
8if (typeof(b) == STR)
9safe_s = safe_s + b;
10endif
11endfor
12return safe_s;

last_word_start

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

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];
3threshold = (length(args) > 1) ? args[2] | 0;
4"... find first nonspace...";
5wend = rmatch(rest, "[^ ]%|^")[1];
6rest = rest[1..wend];
7if (!rest)
8return {};
9endif
10pattern = "%(^%|[^ ]+%)%([ ]+%)";
11while (rest)
12m = rmatch(rest, pattern);
13if (!m)
14return {};
15endif
16if ((!threshold) || (wend <= threshold))
17return {m[3][2][2] + 1, wend};
18endif
19rest = rest[1..m[1]];
20endwhile
21return {};

gibberish

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1msg = args[1];
2if (typeof(msg) == INT)
3wordcount = msg;
4else
5wordcount = min(max(3, length(msg) / 5), 16);
6endif
7words = {};
8for i in [1..wordcount]
9words = setadd(words, $su:random_word());
10endfor
11return $su:from_list(words, " ");

merge

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1"Merge two paragraphs with 'join' between them.";
2"i.e., $su:merge({\"Bob is cool.\"}, {\"This sucks.\",\"The end.\"}, \"and\")";
3" => {\"Bob is cool, and this sucks.\", \"The end.\"}";
4{first, second, join} = args;
5first_endline = first[$];
6second_firstline = second[1];
7merged = "";
8if (first_endline[$] == ".")
9first_endline[$] = ",";
10endif
11`second_firstline[1] = $su:lowercase(second_firstline[1]) ! E_RANGE';
12merged = tostr(first_endline, join ? tostr(" ", join, " ") | " ", second_firstline);
13return {@first[1..$ - 1], merged, @second[2..$]};

make_table

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":make_table(LIST|STR header_colors, LIST headers, LIST|STR row_colors, LIST rows, LIST row_widths)";
2"  => a very nice table, as a list of strings to be fed to e.g. :tell_lines.";
3"  look #469417 for documentation.";
4{header_colors, headers, row_colors, rows, row_widths} = args;
5n_cols = length(row_widths);
6table = {};
7"First, the header";
8multirow_header = typeof(headers[1]) == LIST;
9if (!multirow_header)
10header_colors = {header_colors};
11headers = {headers};
12endif
13for line_idx in [1..length(headers)]
14colors = header_colors[line_idx];
15color = "";
16if (typeof(colors) != LIST)
17color = colors;
18endif
19line = headers[line_idx];
20string = "";
21for i in [1..n_cols]
22string = ((string + (color ? color | colors[i])) + $su:left(line[i], -row_widths[i])) + ((i != n_cols) ? " " | $ansi.reset);
23endfor
24table = {@table, string};
25endfor
26color = "";
27if (typeof(row_colors) != LIST)
28color = row_colors;
29endif
30for data_idx in [1..length(rows)]
31row = rows[data_idx];
32string = "";
33for i in [1..n_cols]
34string = ((string + (color ? color | row_colors[i])) + $su:left(row[i], -row_widths[i])) + ((i != n_cols) ? " " | $ansi.reset);
35endfor
36table = {@table, string};
37$cu:sin();
38endfor
39table[$] = table[$] + $ansi.reset;
40return table;

word_wrap

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1"$su:word_wrap(LIST lines, INT linelength [, STR color [, STR suspend_text]])";
2" => LIST of lines wrapped at linelength.";
3{in_lines, linelen, ?color = "", ?suspend_text = ""} = args;
4broken_lines = {};
5idx = 0;
6currlen = 0;
7indent = 2;
8indspace = "  ";
9for line in (in_lines)
10broken_lines = {@broken_lines, ""};
11idx = idx + 1;
12currlen = 0;
13for word in ($su:_splitwords(line))
14wordlen = length($ansi:strip(word));
15realwordlen = (rwl = index($ansi:strip(word), " ")) ? rwl - 1 | length($ansi:strip(word));
16while (realwordlen > linelen)
17subword = word[1..linelen];
18word = word[linelen + 1..$];
19broken_lines[idx] = subword;
20idx = idx + 1;
21broken_lines = {@broken_lines, indspace};
22currlen = indent;
23realwordlen = (rwl = index($ansi:strip(word), " ")) ? rwl - 1 | length($ansi:strip(word));
24endwhile
25if (!currlen)
26broken_lines[idx] = word;
27currlen = wordlen;
28elseif ((currlen + wordlen) < linelen)
29broken_lines[idx] = broken_lines[idx] + word;
30currlen = currlen + wordlen;
31elseif ((currlen + realwordlen) < linelen)
32broken_lines[idx] = broken_lines[idx] + word[1..realwordlen];
33idx = idx + 1;
34broken_lines = {@broken_lines, indspace};
35currlen = indent;
36else
37idx = idx + 1;
38broken_lines = {@broken_lines, indspace + word};
39currlen = wordlen + indent;
40endif
41$cu:sin(1, suspend_text);
42endfor
43endfor
44if (!color)
45return broken_lines;
46endif
47for i in [1..length(broken_lines)]
48broken_lines[i] = (color + broken_lines[i]) + $ansi.reset;
49endfor
50return broken_lines;

_splitwords

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":_splitwords(STR s) => LIST words -- split and include trailing space.";
2{s} = args;
3if (!s)
4return {};
5endif
6s = " " + s;
7words = {};
8lasti = length(s);
9while (s)
10i = rindex(s[1..lasti - 1], " ");
11if ((i == 1) || ((lasti - i) > 1))
12words = {s[i + 1..$], @words};
13s = s[1..i];
14endif
15if (i == 1)
16break;
17endif
18lasti = i;
19yield 0;
20endwhile
21return words;

colorize colourize c

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1":colorize(STR text, [LIST colors]) => colored text";
2(((" example: $su:colorize(\"/rhello\") => \"" + $ansi.red) + "hello") + $ansi.reset) + "\"";
3" available colors: /R, /G, /B, /C, /M, /Y, /K";
4"                   /r, /g, /b, /c, /m, /y, /w";
5" also callable as 'colourize'.";
6" restrict it to certain colors by passing them as a list (of strings) as the second argument, e.g. {\"red\", \"green\"}. E_INVARG is raised if a color is used which doesn't appear in the list.";
7{intext, ?ok_cols = {}} = args;
8color_subs = {};
9if (ok_cols)
10ok_letters = {};
11for col in (ok_cols)
12sub = $lu:assoc(col, this.color_subs);
13ok_letters = {@ok_letters, sub[2][2]};
14color_subs = {@color_subs, sub};
15endfor
16split = $su:explode(intext, "/");
17for word in (split)
18if (length(word))
19letter = word[1];
20if (!(letter in ok_letters))
21raise(E_INVARG, tostr("/", letter));
22return E_INVARG;
23endif
24endif
25endfor
26else
27color_subs = this.color_subs;
28endif
29color_subs = $lu:slice(color_subs, {2, 3});
30colorized = $su:subst(intext, color_subs, 1) + $ansi.reset;
31return colorized;

highlight_words

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1"(STR text, LIST words) => highlight all words in text";
2text = args[1];
3words = args[2];
4lines = (typeof(text) == LIST) ? text | {text};
5newlines = {};
6for text in (lines)
7newtext = "";
8for w in ($su:explode(text))
9ws = $su:strip_chars(w, "?!.,");
10if (ws in words)
11newtext = (newtext + ((" " + $ansi.bold_on) + w)) + $ansi.reset;
12else
13newtext = (newtext + " ") + w;
14endif
15endfor
16newtext = newtext[2..$];
17newlines = {@newlines, newtext};
18endfor
19return (typeof(args[1]) == LIST) ? newlines | newlines[1];

fast_words

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1text = args[1];
2sep = (length(args) > 1) ? args[2] | " ";
3sepl = length(sep);
4w = {};
5while (text)
6space = index(text, sep);
7if (!space)
8w = listappend(w, text);
9text = "";
10else
11w = listappend(w, word = text[1..space - 1]);
12if (length(text) >= (next = (length(word) + sepl) + 1))
13text = text[next..$];
14else
15text = "";
16endif
17endif
18endwhile
19return w;

re_sub*stitute

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1":re_sub(STR target, { {regex1, repl1}, ... }, [INT case_sensitive]) => STR result";
2{s, tuples, ?case_sensitive = 0} = args;
3for tuple in (tuples)
4{regex, repl} = tuple;
5start_s = s;
6while (matches = match(s, regex, case_sensitive))
7result = substitute(repl, matches);
8matchtext = s[matches[1]..matches[2]];
9if ((length(matchtext) > 1) && (strcmp(matchtext, $su:uppercase(matchtext)) == 0))
10s[matches[1]..matches[2]] = $su:uppercase(result);
11else
12s[matches[1]..matches[2]] = result;
13endif
14if (s == start_s)
15break;
16endif
17start_s = s;
18endwhile
19endfor
20return s;

smart_abbrev

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":smart_abbrev(STR/LIST string(s), [INT eachbelow, INT totalbelow]) => STR/LIST abbreviated.";
2"   Eliminates articles like 'the', 'an', 'pair of', then shortens non-final words, then, as a last resort, turns strings into initials. Will try to get each string in the list below 'eachbelow', and the total length of all strings below 'totalbelow'.";
3{given, ?eachbelow = 0, ?totalbelow = 0} = args;
4givenlist = typeof(given) == LIST;
5l = givenlist ? given | {given};
6orig = l;
7len = length(l);
8for phase in [1..4]
9phaseverb = tostr("_", verb, "_", phase);
10each_ok = 1;
11total_ok = (phase != 1) && (strslen < totalbelow);
12strslen = 0;
13for i in [1..len]
14if (total_ok && (length(l[i]) < eachbelow))
15"total is ok, and this one is fine, so skip it";
16else
17l[i] = this:(phaseverb)(l[i]);
18if (!l[i])
19#7195:tell("smart_abbrev] :", phaseverb, " returned 0 length string for '", orig[i], "'");
20endif
21endif
22strslen = strslen + length(l[i]);
23if (eachbelow && (length(l[i]) >= eachbelow))
24each_ok = 0;
25endif
26endfor
27if (((phase == 2) && (!totalbelow)) && each_ok)
28"return here if we didn't get totalbelow";
29return givenlist ? l | l[1];
30endif
31if (each_ok && (strslen < totalbelow))
32return givenlist ? l | l[1];
33endif
34endfor
35return givenlist ? l | l[1];

metaphone

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":metaphone(word) => special awesome code";
2{name} = args;
3metaph = "";
4ename = "";
5wname = "";
6VOWELS = "AEIOU";
7FRONTV = "EIY";
8VARSON = "CSPTG";
9excpPAIR = "AGKPW";
10nextLTR = "ENNNR";
11for i in [1..length(name)]
12if ((idx = index("abcdefghijklmnopqrstuvwxyz", name[i])) || (idx = index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", name[i])))
13ename = ename + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[idx];
14endif
15endfor
16if (!ename)
17return "";
18endif
19"ae,gn,kn,pn,wr -> drop first letter";
20if (idx = index(excpPAIR, ename[1]))
21if (ename[2] == nextLTR[idx])
22ename = ename[2..$];
23endif
24endif
25if (ename[1] == "X")
26ename[1] = "S";
27endif
28if ((length(ename) > 1) && (ename[1..2] == "WH"))
29ename[2..$] = ename[3..$];
30endif
31len = length(ename);
32for i in [1..len]
33curLtr = ename[i];
34vowelBefore = 0;
35prevLtr = " ";
36if (i > 1)
37prevLtr = ename[i - 1];
38vowelBefore = index(VOWELS, prevLtr);
39endif
40"keep initial vowel";
41if ((i == 1) && index(VOWELS, curLtr))
42metaph = metaph + curLtr;
43continue;
44endif
45vowelAfter = 0;
46frontvAfter = 0;
47nextLTR = "";
48if (i < len)
49nextLTR = ename[i + 1];
50vowelAfter = index(VOWELS, nextLTR);
51frontvAfter = index(FRONTV, nextLTR);
52endif
53"skip doubles";
54if (curLtr == nextLTR)
55continue;
56endif
57nextLtr2 = "";
58nextLtr3 = "";
59if (i < (len - 1))
60nextLtr2 = ename[i + 2];
61if (i < (len - 2))
62nextLtr3 = ename[i + 3];
63endif
64endif
65if (curLtr == "B")
66if (!((i == len) && (prevLtr == "M")))
67metaph = metaph + curLtr;
68endif
69elseif (curLtr == "C")
70if (!(((i > 1) && (prevLtr == "S")) && frontvAfter))
71if (((i > 1) && (nextLTR == "I")) && (nextLtr2 == "A"))
72metaph = metaph + "X";
73elseif (frontvAfter)
74metaph = metaph + "S";
75elseif (((i > 1) && (prevLtr == "S")) && (nextLTR == "H"))
76metaph = metaph + "K";
77elseif (nextLTR == "H")
78if ((i == 1) && (!index(VOWELS, nextLtr2)))
79metaph = metaph + "K";
80else
81metaph = metaph + "X";
82endif
83elseif (prevLtr == "C")
84metaph = metaph + "S";
85else
86metaph = metaph + "K";
87endif
88endif
89elseif (curLtr == "D")
90if (((prevLtr == "N") && (nextLTR == "S")) && (i == (len - 1)))
910;
92elseif ((nextLTR == "G") && index(FRONTV, nextLtr2))
93metaph = metaph + "J";
94else
95metaph = metaph + "T";
96endif
97elseif (curLtr == "G")
98if (((i < (len - 1)) && (nextLTR == "H")) && index(VOWELS, nextLtr2))
990;
100elseif ((((i == (len - 3)) && (nextLTR == "N")) && (nextLtr2 == "E")) && (nextLtr3 == "D"))
1010;
102elseif ((i == (len - 1)) && (nextLTR == "N"))
1030;
104elseif ((prevLtr == "D") && frontvAfter)
1050;
106elseif ((prevLtr != "G") && frontvAfter)
107metaph = metaph + "J";
108else
109metaph = metaph + "K";
110endif
111elseif (curLtr == "H")
112if (index(VARSON, prevLtr) || (vowelBefore && (!vowelAfter)))
1130;
114else
115metaph = metaph + "H";
116endif
117elseif (curLtr in {"F", "J", "L", "M", "N", "R"})
118metaph = metaph + curLtr;
119elseif (curLtr == "K")
120if (prevLtr != "C")
121metaph = metaph + "K";
122endif
123elseif (curLtr == "P")
124metaph = metaph + ((nextLTR == "H") ? "F" | "P");
125elseif (curLtr == "Q")
126metaph = metaph + "K";
127elseif (curLtr == "S")
128if (((i > 1) && (nextLTR == "I")) && (nextLtr2 in {"O", "A"}))
129metaph = metaph + "X";
130else
131metaph = metaph + ((nextLTR == "H") ? "X" | "S");
132endif
133elseif (curLtr == "T")
134if (((i > 1) && (nextLTR == "I")) && (nextLtr2 in {"O", "A"}))
135metaph = metaph + "X";
136elseif (nextLTR == "H")
137metaph = metaph + "0";
138elseif (!(((i < (len - 2)) && (nextLTR == "C")) && (nextLtr2 == "H")))
139metaph = metaph + "T";
140endif
141elseif (curLtr == "V")
142metaph = metaph + "F";
143elseif (curLtr in {"W", "Y"})
144if ((i < len) && vowelAfter)
145metaph = metaph + curLtr;
146endif
147elseif (curLtr == "X")
148metaph = metaph + "KS";
149elseif (curLtr == "Z")
150metaph = metaph + "S";
151endif
152endfor
153return metaph;

properties_like

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":properties_like(OBJ on what, STR like what) => LIST props";
2{what, match} = args;
3metamatch = this:metaphone(match);
4l = {};
5cache = this.proplikecache;
6props = properties(what);
7metamap = {};
8if (cache && (cache[1..2] == {what, length(props)}))
9metamap = cache[3..$];
10else
11for p in (props)
12if (p[1] == "_")
13continue;
14endif
15meta = this:metaphone(p);
16metamap = {@metamap, {meta, p}};
17$cu:sin();
18endfor
19this.proplikecache = {what, length(props), @metamap};
20endif
21for m in (metamap)
22if (metamatch == m[1])
23l = {@l, m[2]};
24endif
25endfor
26return l;

index_any

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":index_any(STR check, STR targets) => INT first index";
2"finds the index of the first occurence of any character in 'targets'.";
3" e.g. $su:index_any(\"hamburger\", \"aeiou\") => 2";
4{check, targets} = args;
5for i in [1..length(check)]
6if (index(targets, check[i]))
7return i;
8endif
9endfor
10return 0;

_smart_abbrev_1

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1return $su:re_sub(args[1], {{"%bpair of +", ""}, {"%bthe +", ""}, {"%ban? +", ""}, {" +and +", "&"}});

_smart_abbrev_2

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{l} = args;
2rem = l;
3did_one = 0;
4txns = {};
5while ((brk = $su:index_any(rem, " -&'")) || (!did_one))
6if (!brk)
7"first word == last word";
8spc = "";
9word = rem;
10rem = "";
11else
12spc = rem[brk];
13word = rem[1..brk - 1];
14rem = rem[brk + 1..$];
15endif
16orig_word = word;
17"e.g. alcohol => alc, creature => cr, soda => soda";
18if (tostr(tonum(word)) == word)
19"don't do anything, it's a number";
20elseif (vowel = $su:index_any(word[2..$], "aeiou"))
21if (vowel == 1)
22vowel = $su:index_any(word[3..$], "aeiou");
23vowel = vowel ? vowel + 2 | 2;
24else
25vowel = vowel + 1;
26endif
27if (vowel && (vowel != length(word)))
28word = word[1..vowel - 1];
29endif
30endif
31did_one = 1;
32txns = {@txns, {orig_word != word, length(word), word, spc}};
33endwhile
34if (rem)
35txns = {@txns, {0, length(rem), rem, ""}};
36endif
37gather = "";
38gspc = "";
39result = "";
40for txn in (txns)
41if (txn[1..2] == {1, 1})
42"length 1, changed";
43gather = gather + txn[3];
44gspc = txn[4];
45else
46"not";
47if (gather)
48result = (result + gather) + gspc;
49gather = gspc = "";
50endif
51result = (result + txn[3]) + txn[4];
52endif
53endfor
54if (!result)
55result = gather;
56endif
57return result;

_smart_abbrev_3

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1return $su:re_sub(args[1], {{"%b%([a-zA-Z]%)[a-zA-Z]+[ -]", "%1 "}});

_smart_abbrev_4

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1return $su:re_sub(args[1], {{"%b%([a-zA-Z]%)[a-zA-Z]+%b", "%1"}, {" +", ""}});

english_list_bold

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1"Copied from string utilities (#20):english_list by Hacker (#36) Fri Mar 27 03:39:15 2009 CDT";
2"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\".";
3"Optional arguments are treated as follows:";
4"  Second argument is the string to use when the empty list is given.  The default is \"nothing\".";
5"  Third argument is the string to use in place of \" and \".  A typical application might be to use \" or \" instead.";
6"  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.";
7"  Fifth argument is a string to use after the penultimate element before the \" and \".  The default is to have a comma without a space.";
8{things, ?nothingstr = "nothing", ?andstr = " and ", ?commastr = ", ", ?finalcommastr = ","} = args;
9nothingstr = "nothing";
10"This is a horrible shitty hack and I apologize to whoever is reading this.  I've wronged us both.";
11nthings = length(things);
12bold = {};
13for x in (things)
14bold = {@bold, ($ansi.bold_on + tostr(x)) + $ansi.bold_off};
15endfor
16things = bold;
17if (nthings == 0)
18r = nothingstr;
19elseif (nthings == 1)
20r = tostr(things[1]);
21elseif (nthings == 2)
22r = tostr(things[1], andstr, things[2]);
23else
24ret = "";
25for k in [1..nthings - 1]
26if (k == (nthings - 1))
27commastr = finalcommastr;
28endif
29ret = tostr(ret, things[k], commastr);
30endfor
31r = tostr(ret, andstr, things[nthings]);
32endif
33return r;

repeat

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{n, what} = args;
2if (n > 250)
3raise(E_INVARG, "n too large in $su:repeat");
4endif
5s = "";
6for i in [1..n]
7s = s + what;
8endfor
9return s;

uncapitalize

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

Source

1"Copied from string utilities (#20):capitalize by Hacker (#36) Sun Jun 28 02:45:29 2009 CDT";
2"capitalizes its argument.";
3if (string = args[1])
4ansi = 0;
5for i in [1..length(string)]
6if (string[i] == "~")
7ansi = 1;
8elseif (ansi && (string[i] == "m"))
9ansi = 0;
10elseif (!ansi)
11if (testi = index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", string[i], 0))
12string[i] = "abcdefghijklmnopqrstuvwxyz"[testi];
13return string;
14endif
15endif
16endfor
17endif
18return string;

encrypt decrypt

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":encrypt/:decrypt(STR, KEY) => Encrypt or decrypt 'STR' with KEY.  In both cases, the process is reversible.  A zero-length means that STR will be returned verbatim.";
2if (verb == "decrypt")
3args = {@args, 1};
4return this:crypto(@args);
5else
6return this:crypto(@args);
7endif

_tohash

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1"_tohash(string) -- auxiliary for :to_value()";
2rest = this:triml(args[1]);
3vhash = [];
4if (!rest)
5return {0, []};
6elseif (rest[1] == "]")
7return {rest[2..$], []};
8endif
9while (1)
10rlen = length(rest);
11key = 0;
12if (rest[1] == "\"")
13result = this:_unquote(rest[2..rlen]);
14if (typeof(result[1] == INT))
15return result;
16endif
17key = result[2];
18rest = result[1];
19if (!rest)
20return {0, ""};
21endif
22key_end = index(rest, "->");
23if (!key_end)
24return {rlen, "missing arrow '->' in hash entry definition"};
25endif
26rest = rest[key_end + 2..$];
27elseif (w = index("{[", rest[1]))
28return {rlen, "hash key cannot be list or hash"};
29else
30key_end = index(rest, "->");
31if (!key_end)
32return {rlen, "missing arrow '->' in hash entry definition"};
33endif
34thing = rest[1..key_end - 1];
35if (typeof(s = this:_toscalar(thing)) == STR)
36return {rlen, s};
37endif
38key = s;
39rest = rest[key_end + 2..rlen];
40endif
41val = 0;
42rest = this:triml(rest);
43rlen = length(rest);
44if (w = index("{[\"", rest[1]))
45result = this:({"_tolist", "_tohash", "_unquote"}[w])(rest[2..rlen]);
46if (typeof(result[1] == INT))
47return result;
48endif
49val = result[2];
50rest = result[1];
51else
52val = rest[1..vlen = min(index(rest + ",", ","), index(rest + "]", "]")) - 1];
53if (typeof(s = this:_toscalar(val)) == STR)
54return {rlen, s};
55endif
56val = s;
57rest = rest[vlen + 1..rlen];
58endif
59vhash[key] = val;
60rest = this:triml(rest);
61if (!rest)
62return {0, vhash};
63elseif (rest[1] == "]")
64return {rest[2..$], vhash};
65elseif (rest[1] == ",")
66rest = this:triml(rest[2..$]);
67else
68return {length(rest), ", or ] expected"};
69endif
70endwhile

crapsum

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{text, key, ?limit = 999} = args;
2if (!key)
3raise(E_INVARG, "key is required");
4else
5sum = length(text);
6for i in [1..length(key)]
7sum = sum + $su:to_ascii(key[i]);
8$cu:sin();
9endfor
10state = $rng:make_state(sum);
11result = limit;
12for i in [1..length(text)]
13{v, state} = $rng:random(limit, state);
14result = (result + v) - $su:to_ascii(text[i]);
15endfor
16return mod(abs(result), limit);
17endif

new_encrypt new_decrypt

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1":encrypt/:decrypt(STR, KEY) => Encrypt or decrypt 'STR' with KEY.  In both cases, the process is reversible.  A zero-length means that STR will be returned verbatim.";
2{s, key} = args;
3if (!key)
4return s;
5elseif (length(s) > 3000)
6raise(E_INVARG, "string too long");
7else
8rnd_a = 16807;
9rnd_m = $maxint;
10rnd_state = 1;
11ascii = $su.ascii;
12keysum = length(s);
13k = length(ascii);
14for i in [1..length(key)]
15keysum = keysum + index(ascii, key[i], 1);
16endfor
17result = "";
18for i in [1..length(s)]
19rnd_state = mod(rnd_a * rnd_state, rnd_m);
20v = mod(rnd_state, 64) + 1;
21if (verb == "new_decrypt")
22c = (index(ascii, s[i], 1) - v) - 2;
23else
24c = index(ascii, s[i], 1) + v;
25endif
26result = result + ascii[mod(c, k) + 1];
27endfor
28return result;
29endif

format_bytesize

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":format_bytesize(INT bytes) => STR formatted nicely. e.g., 49394 => 48k.";
2{b} = args;
3if (!b)
4return "0b";
5endif
6minus = b < 0;
7b = abs(b);
8if (b > 943718400)
9"over 900mb";
10gb = tofloat(b) / 1073741824.0;
11s = floatstr(gb, 1) + "g";
12elseif (b >= 1048576)
13"1mb+";
14mb = tofloat(b) / 1048576.0;
15s = floatstr(mb, 0) + "m";
16elseif (b >= 1024)
17"1kb+";
18kb = tofloat(b) / 1024.0;
19s = floatstr(kb, 0) + "k";
20else
21s = tostr(b, "b");
22endif
23return tostr(minus ? "-" | "", s);

crypto

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":crypto(STR s, STR key [, INT decrypt]) => STR encrypted/decrypted.";
2ascii = this.ascii;
3{s, key, ?decrypt = 0} = args;
4if (!key)
5return s;
6endif
7strlen = length(s);
8keysum = strlen;
9for i in [1..length(key)]
10keysum = (keysum + index(ascii, key[i], 1)) + 31;
11endfor
12state = keysum;
13result = "";
14for i in [1..strlen]
15state = mod(16807 * state, 2147483647);
16val = mod(state, 64) + 1;
17if (decrypt)
18c = (index(ascii, s[i], 1) - val) - 2;
19else
20c = index(ascii, s[i], 1) + val;
21endif
22result = result + ascii[mod(c, 95) + 1];
23endfor
24return result;

columnize_horiz*ontal

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

Source

1"columnize_horiz*ontal (items, n [, width[, hard]]) - Just like $su:columnize, but values go left-to-right first.";
2{items, n, ?width = 79, ?hard = 0, ?highlight = 0} = args;
3height = ((length(items) + n) - 1) / n;
4colwidths = {};
5for col in [1..n]
6colwidths = {@colwidths, 1 - (((width + 1) * col) / n)};
7endfor
8result = {};
9bright = 1;
10for row in [1..height]
11row_items = items[1 + ((row - 1) * n)..min($, row * n)];
12n_for_row = min(length(row_items), n);
13if (highlight)
14bright = !bright;
15line = bright ? $ansi.bold_on | $ansi.reset;
16else
17line = "";
18endif
19for col in [1..n_for_row]
20col_item = tostr(row_items[col]);
21line = this:left((line + " ") + col_item, colwidths[col]);
22endfor
23diff = length(line) - length($ansi:strip(line));
24line = line[1..min($, width + diff)] + $ansi.reset;
25result = {@result, line};
26yield;
27endfor
28return result;

reverse_nn rev_nn

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1o = args[1];
2return tostr(o, " (", `o.name ! E_INVIND => "<invalid>"', ")");

spr*intf pr*intf

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

none

Source

1" :spr*intf	(STR before, value1, value2, ...)	=> 'before' formatted";
2" :pr*intf	(OBJ who, STR, value1, value2, ...)	=> Same as sprintf, but :tell()s 'who' the result";
3"";
4"This verb is a 'copy' of C's sprintf() function. There is documentation on sprintf";
5" in numerous places, such as here:";
6"";
7"http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/";
8"";
9"Note that this is unfinished, and shouldn't be used for output players will see (yet).";
10"Also, a number of functions of the original sprintf wouldn't make any sense here - e.g.,";
11" MOO is not made to deal with memory addresses, so the %p specifier (for fetching the";
12" value that a pointer 'points' to) would be entirely useless, as well as (to my knowledge)";
13" impossible to implement via MOO's programming language alone.";
14"";
15"The %s, %d, %i, %f, %c, and %% specifiers are supported, of course, but there are also";
16" some changes:";
17"	%s	Normal if given a string; provided with a list, picks one element at random. Ex:";
18"			sprintf(\"%s\", {\"True\", \"False\"}) => \"True\" OR \"False\"";
19"	%o	Takes an object and returns the effect of tostr(object). The '#' option";
20"		makes this display *without* the usual '#' seen in front (e.g. #1 => 1).";
21"";
22" ~ Irony";
23if (verb[1..2] == "pr")
24{who, string, @repl} = args;
25(typeof(who) == OBJ) || raise(E_INVARG);
26offset = 2;
27else
28{string, @repl} = args;
29who = 1;
30offset = 1;
31endif
32SPECIFIERS = ["s" -> {STR, LIST}, "d" -> {INT}, "i" -> {INT}, "f" -> {FLOAT}, "o" -> {OBJ}, "c" -> {INT}];
33SPECIFIER_KEYS = "sdifoc";
34OPTIONS = "-+ #0";
35CAN_OPTIONS = "-+ #0123456789.";
36FLOATLEN = 19;
37"opt: 1: -, 2: +, 3: (space), 4: #, 5: 0";
38dopt = opt = {0, 0, 0, 0, 0};
39types = E_NONE;
40newstring = text = "";
41on = pos = prec = len = 0;
42strlen = length(string);
43while ((pos = pos + 1) <= strlen)
44if (string[pos] != "%")
45newstring = newstring + string[pos];
46continue;
47elseif (string[pos..min(pos + 1, $)] == "%%")
48newstring = newstring + "%";
49pos = pos + 1;
50continue;
51endif
52char = string[pos = pos + 1];
53while (index(CAN_OPTIONS, char))
54if ((!(len || prec)) && (o = index(OPTIONS, char)))
55opt[o] = 1;
56elseif (((val = decode_binary(char, 1)[1] - 48) > -1) && (val < 10))
57if ((prec > 0) || (string[pos - 1] == "."))
58prec = (prec * 10) + val;
59else
60len = (len * 10) + val;
61endif
62endif
63char = string[pos = pos + 1];
64endwhile
65if (index(SPECIFIER_KEYS, char, 1))
66types = SPECIFIERS[char];
67`sub = repl[on = on + 1] ! E_RANGE => raise(E_ARGS)';
68if (!(typeof(sub) in types))
69errmsg = tostr("args[", on + offset, "] is invalid: %", char, " does not accept an argument of type ", $code_utils:type_str(sub));
70raise(E_TYPE, errmsg);
71elseif (equal("s", char))
72if (typeof(sub) == LIST)
73text = sub[random($)];
74else
75text = sub;
76endif
77(prec > 0) && (text = text[1..min(prec, $)]);
78elseif (equal("f", char))
79text = floatstr(sub, (sub % 1.0) ? FLOATLEN | (opt[4] ? prec || length(tostr(sub)) | 0));
80elseif (index("di", char, 1) && (prec > length(tostr(sub))))
81text = $su:right(sub, prec, "0");
82elseif (equal("o", char))
83text = tostr(sub)[1 + opt[4]..$];
84elseif (equal("c", char))
85text = encode_binary(sub);
86prec = len = 0;
87else
88text = tostr(sub);
89endif
90else
91errmsg = tostr("Invalid specifier '%", char, "'");
92raise(E_INVARG, errmsg);
93endif
94if (index("dif", char, 1))
95if (opt[2] && (sub > ((typeof(sub) == INT) ? 0 | 0.0)))
96text = "+" + text;
97elseif (opt[3] && (!sub))
98text = " " + text;
99endif
100endif
101if (len)
102text = $su:(opt[1] ? "left" | "right")(text, len, opt[5] ? "0" | " ");
103endif
104opt = dopt;
105prec = len = 0;
106newstring = newstring + text;
107endwhile
108(typeof(who) == OBJ) && who:tell(newstring);
109return newstring;

capitalize_words

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1s = args[1];
2ns = "";
3space = 1;
4for i in [1..length(s)]
5ch = s[i];
6if ((ch == " ") || (ch == "-"))
7space = 1;
8ns = ns + ch;
9elseif (!space)
10ns = ns + ch;
11elseif (charnum = index("abcdefghijklmnopqrstuvwxyz", ch))
12ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[charnum];
13ns = ns + ch;
14space = 0;
15else
16ns = ns + ch;
17space = 0;
18endif
19endfor
20return ns;

superview sv

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1v = args[1];
2m = "";
3reset = $ansi.reset;
4if (typeof(v) == LIST)
5m = ($ansi.yellow + "{") + $ansi.white;
6first = 1;
7for x in (v)
8m = m + (first ? "" | (($ansi.yellow + ", ") + $ansi.white));
9first = 0;
10m = m + this:superview(x);
11endfor
12m = m + ($ansi.yellow + "}");
13elseif (typeof(v) == HASH)
14m = ((col = $ansi.bold_on + $ansi.yellow) + "[") + reset;
15first = 1;
16for kvp in (v)
17{k, v} = kvp;
18m = (((((m + (first ? "" | ((col + ", ") + $ansi.reset))) + $su:superview(k)) + col) + " -> ") + reset) + this:superview(v);
19first = 0;
20endfor
21m = ((m + col) + "]") + reset;
22elseif ((typeof(v) == OBJ) && valid(v))
23m = ((((($ansi.cyan + v.name) + " (") + $ansi.bold_on) + tostr(v)) + $ansi.bold_off) + ")";
24elseif (typeof(v) == OBJ)
25m = $ansi.red + tostr(v);
26elseif (typeof(v) == STR)
27m = ("\"" + v) + "\"";
28else
29m = tostr(v);
30endif
31return m + reset;

widen

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{old_s, ?n_spaces = 1} = args;
2s = "";
3old_chars = this:char_list(old_s);
4spaces = $su:space(n_spaces);
5for c in (old_chars)
6s = (s + c) + spaces;
7endfor
8return s[1..$ - n_spaces];

bonus_num

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1n = args[1];
2s = "";
3if (((typeof(n) == FLOAT) && (n >= 0.0)) || ((typeof(n) == INT) && (n >= 0)))
4if (tofloat(n) == 0.0)
5s = "+";
6else
7s = $ansi.green + "+";
8endif
9else
10s = $ansi.red;
11endif
12return (s + tostr(n)) + $ansi.reset;

trim_binary

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{text} = args;
2if (!text)
3return text;
4elseif (text && (text[$] != $ansi.binary_tag))
5return text;
6endif
7total = 0;
8length = length(text);
9for i in [0..length - 1]
10if (text[$ - i] != $ansi.binary_tag)
11break;
12endif
13total = total + 1;
14yield;
15endfor
16if ((total % 2) == 1)
17return text[1..$ - 1] + " ";
18endif
19return text;

short_num

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1n = args[1];
2if (n < 1000)
3return tostr(n);
4elseif (n < 10000)
5n = tofloat(n) / 1000.0;
6n = tofloat(toint(n * 10.0)) / 10.0;
7return tostr(n) + "k";
8else
9n = n / 1000;
10return tostr(n) + "k";
11endif

random_string

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{?len = 20} = args;
2s = this:space(len);
3for i in [1..len]
4s[i] = this.lettersnumbers[random($)];
5endfor
6return s;

silence

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1":silence(STR s, FLOAT pct) => randomly replace characters in s until pct of it is periods.";
2{s, pct} = args;
3len = length(s);
4to_silence = toint(ceil(tofloat(len) * pct));
5positions = $lu:range(1, len);
6weights = {};
7for p in (positions)
8weight = random();
9weights = {@weights, {p, weight}};
10endfor
11weights = $lu:sort_alist(weights, 2);
12delete = weights[1..to_silence];
13for pw in (delete)
14s[pw[1]] = ".";
15endfor
16return s;

scramble

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1":scramble(STR s, FLOAT pct) => randomly replace characters in s until pct of it is line noise.";
2{s, pct} = args;
3len = length(s);
4to_silence = toint(ceil(tofloat(len) * pct));
5positions = $lu:range(1, len);
6weights = {};
7for p in (positions)
8weight = random();
9weights = {@weights, {p, weight}};
10endfor
11weights = $lu:sort_alist(weights, 2);
12delete = weights[1..to_silence];
13for pw in (delete)
14s[pw[1]] = this.line_noise[random($)];
15endfor
16return s;

silence_words

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

Source

1{s, pct} = args;
2wordlens = {};
3words = this:explode(s);
4full_len = length(s);
5for w in (words)
6wordlens = {@wordlens, tofloat(length(w)) / tofloat(full_len)};
7endfor
8real_words = words;
9words = $lu:make_alist({words, $lu:range(1, length(words)), wordlens});
10words = $lu:sort_alist(words, 3);
11silenced = 0.0;
12while loop (silenced < pct)
13for word_index in [1..length(words)]
14{word, real_index, pct_for_word} = words[word_index];
15if ((silenced + pct_for_word) < pct)
16real_words[real_index] = "...";
17words = listdelete(words, word_index);
18silenced = silenced + pct_for_word;
19continue loop;
20endif
21endfor
22"if we get here, we need to do characters";
23{word, real_index, pct} = words[random($)];
24word_pct = ((pct - silenced) / (1.0 / tofloat(full_len))) / tofloat(length(word));
25real_words[real_index] = this:silence(word, word_pct);
26endwhile
27final = {};
28last_w = "";
29for w in (real_words)
30if (last_w != "...")
31final = {@final, w};
32elseif (w != "...")
33final = {@final, w};
34endif
35last_w = w;
36endfor
37return $su:from_list(final, " ");

to_hex

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1{value} = args;
2digits = "0123456789ABCDEF";
3bits = $math_utils:BLFromInt(value);
4r = "";
5for i in [0..3]
6o = i * 8;
7r = r + digits[1 + $math_utils:IntFromBL(bits[o + 1..o + 4])];
8r = r + digits[1 + $math_utils:IntFromBL(bits[o + 5..o + 8])];
9endfor
10return r;

to_hex2

Spec this none thisFlags rxdOwner #361Definer #20

Referenced by

none

Source

1inthash = string_hash(args[1]);
2if (inthash < 0)
3hex = $math_utils:base_conversion($minint + inthash, 10, 16);
4first = toint($math_utils:base_conversion(hex[1], 16, 10));
5hex = $math_utils:base_conversion(first + 8, 10, 16) + hex[2..$];
6else
7hex = $math_utils:base_conversion(inthash, 10, 16);
8endif
9return hex;

match_aliases_generics

Spec this none thisFlags rxdOwner #29Definer #20

Referenced by

Source

1"Copied from string utilities (#20):match_aliases_ambiguous by Hacker (#36) Sun Nov 21 05:30:18 2010 CST";
2"Copied from string utilities (#20):match_aliases by Hacker (#36) Fri Mar  5 20:34:58 2004 PST";
3"$string_utils:match_aliases(string, objlist)";
4"The argument string is matched against all of the strings in the :name() and :aliases() of the objects in objlist.";
5"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.";
6"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.";
7"Finally, if there are no exact or partial matches, then $failed_match is returned.";
8subject = args[1];
9if (subject == "")
10return $nothing;
11endif
12no_exact_match = no_partial_match = 1;
13for object in ((typeof(olist = args[2]) == LIST) ? olist | {olist})
14if (valid(object))
15str_list = {object:name(), @object:aliases()};
16if (subject in str_list)
17if (no_exact_match)
18no_exact_match = object;
19elseif (parent(no_exact_match) != parent(object))
20return $ambiguous_match;
21endif
22else
23for string in (str_list)
24if (index(string, subject) != 1)
25elseif (no_partial_match)
26no_partial_match = object;
27elseif (parent(no_partial_match) != parent(object))
28return $ambiguous_match;
29endif
30endfor
31endif
32endif
33endfor
34return no_exact_match && (no_partial_match && $failed_match);