MongoosePeople. Places. Questionable inventions.

All help topics · Link to this topic

Showing help on '$string_utils'

string utilities ($string_utils #20)

For a complete description of a given verb, do `help $string_utils:verbname'

Conversion routines:

:from_list (list [,sep]) => "foo1foo2foo3"
:english_list (str-list[,none-str[,and-str[, sep]]]) => "foo1, foo2, and foo3"
:title_list*c (obj-list[,none-str[,and-str[, sep]]]) => "foo1, foo2, and foo3"
or => "Foo1, foo2, and foo3"
:from_value (value [,quoteflag [,maxlistdepth]]) => "{foo1, foo2, foo3}"
:print (value) => value in string
:abbreviated_value (value, options) => short value in string

:to_value (string) => {success?, value or error message}
:prefix_to_value(string) => {rest of string, value} or {0, error message}

:english_number(42) => "forty-two"
:english_ordinal(42) => "forty-second"
:ordinal(42) => "42nd"
:group_number(42135 [,sep]) => "42,135"
:from_ASCII(65) => "A"
:to_ASCII("A") => 65
:from_seconds(number) => string of rough time passed in large increments

:name_and_number(obj [,sep]) => "ObjectName (#obj)"
:name_and_number_list({obj1,obj2} [,sep])
=> "ObjectName1 (#obj1) and ObjectName2 (#obj2)"
:nn is an alias for :name_and_number.
:nn_list is an alias for :name_and_number_list.

Type checking:

:is_integer (string) => return true if string is composed entirely of digits
:is_float (string) => return true if string holds just a floating point

Parsing:

:explode (string,char) -- string => list of words delimited by char
:words (string) -- string => list of words (as with command line parser)
:word_start (string) -- string => list of start-end pairs.
:first_word (string) -- string => list {first word, rest of string} or {}
:char_list (string) -- string => list of characters in string

:parse_command (cmd_line [,player] => mimics action of builtin parser

Matching:

:find_prefix (prefix, string-list)=>list index of element starting with prefix
:index_delimited(string,target[,case]) =>index of delimited string occurrence
:index_all (string, target string) => list of all matched positions
:common (first string, second string) => length of longest common prefix
:match (string, [obj-list, prop-name]+) => matching object
:match_player (string-list[,me-object]) => list of matching players
:match_object (string, location) => default object match...
:match_player_or_object (string, location) => object then player matching
:literal_object (string) => match against #xxx, $foo
:match_stringlist (string, targets) => match against static strings
:match_string (string, wildcard target,options)=> match against a wildcard

Pretty printing:

:space (n/string[,filler]) => n spaces
:left (string,width[,filler]) => left justified string in field
:right (string,width[,filler]) => right justified string in field
:center/re (string,width[,lfiller[,rfiller]]) => centered string in field
:columnize/se (list,n[,width]) => list of strings in n columns

Substitutions

:substitute (string,subst_list [,case]) -- general substitutions.
:substitute_delimited (string,subst_list [,case])
/help/ -- like subst, but uses index_delim
:pronoun_sub (string/list[,who[,thing[,location]]])
/help/ -- pronoun substitutions.
:pronoun_sub_secure (string[,who[,thing[,location]]],default)
/help/ -- substitute and check for names.
:pronoun_quote (string/list/subst_list) -- quoting for pronoun substitutions.

Miscellaneous string munging:

:trim (string) => string with outside whitespace removed.
:triml (string) => string with leading whitespace removed.
:trimr (string) => string with trailing whitespace removed.
:strip_chars (string,chars) => string with all chars in `chars' removed.
:strip_all_but(string,chars) => string with all chars not in `chars' removed.
:capitalize/se(string) => string with first letter capitalized.
:uppercase/lowercase(string) => string with all letters upper or lowercase.
:names_of (list of OBJ) => string with names and object numbers of items.
:a_or_an (word) => "a" or "an" as appropriate for that word.
:reverse (string) => "gnirts"
:incr_alpha (string) => "increments" the string alphabetically

A useful property:

.alphabet => "abcdefghijklmnopqrstuvwxyz"

Suspended versions (with _suspended at end of name) for
:print :from_value :columnize/se :match

:space(noansi) - space(len,fill) returns a string of length abs(len) consisting of copies of fill.
:left(noansi) - $string_utils:left(string,width[,filler])
:right(noansi) - $string_utils:right(string,width[,filler])
:centre - $string_utils:center(string,width[,lfiller[,rfiller]])
:columnize(noansi) - columnize (items, n [, width]) - Turn a one-column list of items into an n-column list.
:from_list - $string_utils:from_list(l [, separator])
:english_list - Prints the argument (must be a list) as an english list, e.g.
:names_of - `names_of(list [, sort=0 [, joiner=" "]])`
: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.
:trim (string [, space]) -- remove leading and trailing spaces
:triml(string [, space]) -- remove leading spaces
:trimr(string [, space]) -- remove trailing spaces
:strip_chars(string,chars) => string with chars removed
:strip_all_but(string,keep) => string with chars not in `keep' removed.
:uppercase - lowercase(string) -- returns a lowercase version of the string.
:capitalize - capitalizes its argument.
:literal_object - Matches args[1] against literal objects: #xxxxx, $variables, *mailing-lists, and username.
:match - $string_utils:match(string [, obj-list, prop-name]*)
:match_str*ing - * wildcard matching.
:match_object(string,location[,someone])
:match_player - match_player(name,name,...) => {obj,obj,...}
:match_player_or_object - 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).
:find_prefix - find_prefix(prefix, string-list) => list index of something starting with prefix, or 0 or $ambiguous_match.
:index_d*elimited - 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)
:is_numeric(string) => 1 if string is a number: optional sign, digits, optional decimal part ("3", "-2", "0", "0.5", ".5"). is_integer(string) => 1 only for whole numbers. Surrounding spaces are allowed; anything else is not a number.
:short_ordinal(1) => "1st",:short_ordinal(2) => "2nd",etc...
:group_number - $string_utils:group_number(INT n [, sep_char])
:english_number - $string_utils:english_number(n) -- convert the integer N into English
:english_ordinal - $string_utils:english_ordinal(n) -- convert the integer N into an english ordinal (1 => "first", etc...)
:subst*itute - subst(string,{{redex1,repl1},{redex2,repl2},{redex3,repl3}...}[,case])
:_cap_property - cap_property(what,prop[,ucase]) returns what.(prop) but capitalized if either ucase is true or the prop name specified is capitalized.
:pronoun_sub_backup - Pronoun (and other things) substitution.
:pronoun_sub_secure - $string_utils:pronoun_sub_secure(string[,who[,thing[,location]]], default)
:pronoun_quote - pronoun_quote(string) => quoted_string
:explode - $string_utils:explode(subject [, break[, blanks]])
:words - This breaks up the argument string into words, the resulting list being obtained exactly the way the command line parser obtains `args' from `argstr'.
:word_start - 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.
:to_value(string) tries to parse string as a value (i.e., object, number, string, error, or list thereof).
:prefix_to_value - Last modified 06/16/19 6:34 a.m.
:_tolist - _tolist(string) --- auxiliary for :to_value()
:_unquote - _unquote(string) (auxiliary for :to_value())
:_toscalar - Last modified 11/02/22 2:45 p.m.
:parse_command(cmd_line[,player])
:from_value - $string_utils:from_value(value [, quote_strings = 0 [, list_depth = 1]])
:print - $string_utils:print(value)
:reverse(string) => "gnirts"
:char_list(string) => string as a list of characters.
:regexp_quote(string)
:connection_hostname_bsd - Takes the output from connection_name() and returns just the host string portion of it.
:connection_hostname - This is the function that should actually be called to get the host name from a connection name.
:from_value_suspended - $string_utils:from_value(value [, quote_strings = 0 [, list_depth = 1]])
:end_expression(string[,stop_at])
:first_word(string) => {first word, rest of string} or {}
:common(first,second) => length of longest common prefix
:title_list*c - $string_utils:title_list/title_listc(<obj-list>[, @<args>)
:name_and_number - name_and_number(object [,sepr] [,english_list_args]) => "ObjectName (#object)"
:columnize_suspended - columnize_suspended (interval, items, n [, width]) - Turn a one-column list of items into an n-column list, suspending for `interval' seconds as necessary.
:a_or_an(<noun>) => "a" or "an"
:index_all - index_all(string,target) -- returns list of positions of target in string.
:match_stringlist - $string_utils:match_stringlist(string, {list of strings})
:from_ASCII - This converts a ASCII character code in the range [32..126] into the ASCII character with that code, represented as a one-character string.
:to_ASCII - Convert a one-character string into the ASCII character code for that character.
:abbreviated_value(value,max_reslen,max_lstlev,max_lstlen,max_strlen,max_toklen)
:_abbreviated_value - Internal to :abbreviated_value.
:match_suspended - $string_utils:match_suspended(string [, obj-list, prop-name]*)
:incr_alpha - args[1] is a string.
:is_float - Usage: is_float(string)
:inside_quotes - Usage: inside_quotes(STR)
:strip_all_but_seq(string, keep) => chars in string not in exact sequence of keep removed.
:rot13 - Sean's rot13 encryptor.
:matchable_string - $string_utils:matchable_string(OBJ) => STR
:rnn - reverses the effects of name_and_number.
:redirect_ansi - ...redirects verbs to $ansi_utils...
:pronoun_sub - Pronoun (and other things) substitution.
:to_list - Usage: $string_utils:to_list(str <subject>[, str <separator>])
:name_list - name_list/namec_list/etc(<obj-list>[, @<args>)
:match_all - $string_utils:match_all(string [, obj-list, prop-name]*)
:title_and_number - title_and_number(object [,sepr] [,english_list_args]) => "Objecttitle (#object)"
:csv_to_list - csv_to_list(csv_string) => parse one CSV record into a list of fields.
:table_left/table_center/table_centre/table_right(headers, data[, sep-char[, linelen]]): Return a list of strings representing the provided headers and table data.
:url_encode - url_encode(string) => URL-encode special characters (wrapper for builtin)
:_tomap - Last modified 11/29/18 4:48 a.m.
:starts_with - starts_with(string, prefix) => 1 if string starts with prefix, 0 otherwise
:template - Given a template, a string or list of strings,
:ends_with - ends_with(string, suffix) => 1 if string ends with suffix (or any in list), 0 otherwise
:size_string - $string_utils:size_string(bytes[, precision=2[, longform=0]])
:fit_to_screen({elements}, ?padding = 2, ?underline = 0, ?separator = " ") => Returns a columnized display that is adapted to the linelength of the viewers screen.
:adjust_column_lengths({lengths}) => Takes a list of numbers that are assumed to be column lengths. Then, if the sum
:neat - {string, length, [seperator]}
:fit_to_screen({elements}, ?padding = 2, ?underline = 0, ?separator = " ") => Returns a columnized display that is adapted to the linelength of the viewers screen.
:is_uppercase - Returns 1 if args[1][1] is an uppercase letter.
:spintax - Resolve spintax in a string.
:head - first(string, ?n) => return first n characters of string (default 1)

Also from $generic_utils: 1 documented verb. help $generic_utils