String Functions for Mocha
- boolean is_word (string word_list, string word);
- Returns true if every word in the string word appears
as a word in the string word_list, or false otherwise. As
an exception to this behavior, returns false if the word
is the empty string.
- boolean is_abbreviation (string word_list, string word);
- Returns true if every word in the string word is an
abbreviation of a word in the string word_list, or false
otherwise. As an exception to this behavior, returns false if the
word is the empty string. Note that the abbreviations need not
be proper. That is, the whole word may appear in word.
- integer num_words (string str);
- Returns the number of space- or '.'-separated words in a string.
- string get_word (string str, integer word_num);
- Returns the word in a string with index word_num, where the
valid indices run from 1 through the number of words in the string as
given by num_words.
- boolean is_number (string str);
- Returns true if a string is a number--an optional plus or minus
sign followed by a string of digits.
- integer get_number (string str);
- Returns the number at the start of a string, whether it be positive
or negative. If the string does not begin with a number, returns 0.
- integer numeric_prefix (string str);
- Returns the value of the numeric prefix for a string, usually a string
taken from an argument. The prefix consists of a string of digits followed
by a perio. Note that the prefix can not begin with a plus or minus sign.
Returns the default prefix, 1, if no prefix is found. As an example, the
numeric prefix of the string "2.sword" is 2, while the numeric prefix of
the string "sword" is 1, as is the numeric prefix of the string "2sword."
- string strip_prefix (string str);
- Returns a string stripped of any numeric prefix, as defined for the
previous function. If the string lacks a numeric prefix, it is returned
whole.
string args.first;
Returns the first argument from the arguments args
(e.g., "give 3 coins beggar" has first argument "coins").
string args.second;
Returns the second argument from the arguments args
(e.g., "give 3 coins beggar" has second argument "beggar").
integer args.number;
Returns the number from the arguments args (e.g., "give 3 coins
beggar" has the number 3). If no number was specified in args, returns
the value nothing.
Return to Mocha's Main Page