string

Documentation for the simul_efun-string api in /secure/simul_efun/string.c.

Functions

string add_article(string str)
Adds article to things, i.e.::

add_article(“torch”) -> “a torch” add_article(“apple”) -> “an apple”

string punctuate(string str)

Adds a period to a sentence if needed. Also not after URLs (http/https/ftp). Original by Rust in M_GRAMMAR.

varargs string wrap(string str, int width, int indent)

Takes the string to wrap, and optionally a width to wrap it to and optionally an indent for any line after the first.

string iwrap(string str)

Indented wrapping. Takes the string to wrap. This is really just a shortcut for:

wrap(str, 0, DEFAULT_INDENT);
string chr(int i)

Return a string from a character. Example:

chr(120) -> “x”

int ord(string x)

Return a char value from a single length string. Example:

ord(“x”) -> 120

string swapcase(string s)

Swaps uppercase to lowercase and lower to upper. Example:

swapcase(“jOHN”) -> “John”

varargs int count_substrings(string s, string sub, int i)

Returns a count of how many times the substring (minimum length 2) was part of the main string. Optionally, takes a position where to begin the search.

string ljust(string s, int width)

Left justify a string to a certain width.

string truncate(string s, int length)

Note that truncate adds an elipsis (”…”) to the end if it truncates. String must be longer than 1.

int is_letter(int c)

Test whether a character value is a letter (true) or something else (false).

string format_list(string *list, string separator)

Formats an array of strings into a string seperated by commas and ended by “and” as a default seperator. Example:

format_list(({“apple”,”pear”,”banana”})) -> “apple, pear, and banana”

string tidy_list(mixed items, string separator)

Formats an array of strings into a formatted list including count of items. Example:

tidy_list(({“apple”,”pear”,”banana”,”apple”})) -> “a pear, 2 apple, and a banana”

string title_capitalize(string instring)

Return the incoming string with the appropriate words capitalized for a title.

string time_to_string(int num, int short)

Return a nicely string formatted version of a number of seconds. Default is long format short=1 for shorter format. Examples:

time_to_string(500) -> “8 minutes, 20 seconds” time_to_string(500,1) -> “8m 20s”

Months, Days, hours, minutes and seconds are supported. A month is calculated as 30 days.

varargs string weight_to_string(float w, int imperial)

Converts a measure in kg to a nicely formatted string in metric or emperial measures. Default is metric. Two decimals max. The function returns grams if you give weight below a kilo.

If imperial = 1, we convert to imperial not metric.

The default behaviour of this function can be changed by modifying #METRIC in config.h.

string shorten_filename(mixed ob)

Shortens a filename by introducing ^ as /domains/ and ~ as /wiz/.

varargs string obname(mixed ob, int no_instance)

Returns the object name without the path. Example:

obname(.me) -> “coder#5453” obname(.me,1) -> “coder”

string filename_ellipsis(string fpath, int max)

Tries to shorten the filepath of a file to fit within the max length by adding .. and replacing the ends of long directory names. It never touches the filename at the end. The string is first run through shorten_filename(s).

string drunk_speak(string s, int drunk)

Turns a string into a drunken slurry string. Drunk ranges from 0-10, where 0 is comatose and 10 is sober.

File generated by Lima 1.1a4 reStructured Text daemon.