String Primitives

Summary
String Primitives
Macros
atoiConvert string to a decimal number.
cftimeFormat time and date.
characteratRetrieve the character value within a string.
compressCompress repeated instances of white-space characters.
diff_stringsCompare to strings.
firstofLeftmost character search.
formatFormatted printing.
indexSearch string for a leftmost sub-string or character.
isalnumAlphanumeric character predicate.
isalphaAlpha character predicate.
isasciiASCII character predicate.
isblankBlank character predicate.
iscntrlControl character predicate.
iscsymA symbol character predicate.
isdigitNumeric character predicate.
isgoldAlphanumeric character predicate.
isgraphGraphic character predicate.
islowerLowercase character predicate.
isprintA printable character predicate.
ispunctPunctuation character predicate.
isspaceSpace character predicate.
isupperUppercase character predicate.
iswordWord character predicate.
isxdigitHexadecimal character predicate.
itoaConvert an integer into a string.
lastofRightmost character search.
lowerConvert string or character to lowercase.
ltrimChomp characters from the front of a string.
macro_listRetrieve list of current macros.
readRead characters from the buffer.
rindexSearch string for a rightmost sub-string or character.
rtrimChomp characters from the end of a string.
search_stringSearches for a pattern in a string.
splitSplit a string into tokens.
split_argumentsArgument split.
sprintfFormatted printing to a string.
sscanfRead formatted data from string.
strcasecmpString case insensitive compare.
strcasestrLocate first occurrence of a case insensitive.
strcmpString compare.
strfilecmpFilename comparison.
strftimeFormat time and date.
string_countCount occurrences of characters in a string.
strpbrkSearch a string for any of a set of characters.
strpopPop the leading character(s).
strrstrLocate last occurrence of a sub-string.
strstrLocate first occurrence of a sub-string.
strtodString to double.
strtofString to float.
strtolConvert a string into its numeric value.
strverscmpVersion string compare.
substrExtract a sub-string.
tokenizeTokenize a string into token elements.
trimChomp characters from a string.
upperConvert string or character to uppercase.
ctypeCharacter classes

Macros

atoi

int atoi(string str,
 [int svalue = TRUE])

Convert string to a decimal number.

Description

The atoi() primitive converts the initial portion of the string str into its numeric value.  This behaviour is equivalent to using strtol as follows.

val = strtol(str, NULL, 10);

Optionally atoi if svalue is specified and zero then the ascii value of the first character in string is returned.  This behaviour is equivalent to using characterat as follows.

val = characterat(str, 1);

Parameters

strString object.
svalueOptional flag, when stated as FALSE only the value of the leading character is returned.

Returns

The atoi function returns integer value of argument string treated as an ascii number or the ascii value of the first character in string if svalue is zero.

Portability

A GriefEdit extension.

See Also

strtol

cftime

string cftime(string format,
int time)

Format time and date.

Description

The cftime() primitive is an alternative interface to strftime.

Returns

The cftime function returns a string containing the formatted time and date.

Portability

Provided for CRiSP ™ compatility, see strftime.

See Also

strftime

characterat

int characterat(string str,
int index)

Retrieve the character value within a string.

Description

The characterat function returns the character value within the string str located at the specified position index starting at offset one.

Parameters

strString object to be searched.
indexCharacter index, starting from on offset of 1 being the first character.

Return

Character value as an integer, otherwise -1.

Portability

A GriefEdit extension.

compress

string compress(
   string str,
    [int trim = FALSE],
      [string chars = " \\t\\r\\n"],
    [int replacement = ' ']
)

Compress repeated instances of white-space characters.

Description

The compress() primitive takes a string and removes all multiple white space characters, by converting consecutive white-space characters into a single white-space character.

The default is to compress all tabs, spaces and newline characters.  If trimchars is specified, then all characters within the trimchar string are compressed.

If trim is specified then compress() acts the same as

trim(compress(str,trimchars),trimchars)

Parameters

strString object to be compressed.
trimOptional flag, when TRUE invokes trim on the compressed result.
charsOptional string defining the set to characters be to compressed and optionally trimmed.
replacementOptional replacement character, if given as a non-positive (<= 0) value when the first character with the consecutive set shall be used.

Returns

Returns a copy of string with all spaces, tabs and newlines mapped to single spaces.

Portability

The chars and replacement options are a GriefEdit extensions.

By default BRIEF preserved the first character in every group of compressed characters, whereas GriefEdit replaces them with a single space; unless replacement is stated as a non-positive number (e.g.  -1).

See Also

trim, rtrim, ltrim

diff_strings

int diff_strings( [int flags],
string s1,
string s2)

Compare to strings.

Description

The diff_strings() primitive determines whether the specified strings are equivalent based on the set of formatting rules specified by the comparison flags flags.

Comparison Flags

Line comparison flags, which affects the treatment of whitespace and character case.

Constant
Description
DIFF_IGNORE_WHITESPACE
Ignore white-space differences.
DIFF_IGNORE_CASE
Ignore character case, whereby characters using different case shall be treated as equivalent.
DIFF_COMPRESS_WHITESPACE
Repeated whitespace characters are compressed into a single space and compared as such.
DIFF_SUPPRESS_LEADING
Leading whitespace is ignored.
DIFF_SUPPRESS_TRAILING
Trailing whitespace is ignored.
DIFF_SUPPRESS_LFCR
Line-feed and carriage-return characters are ignored.

Parameters

flagsOptional integer flags defining the rules to be applied during their comparison which maybe one or more of the predefined flags or’ed together.  If omitted or zero diff_strings behaves similar to strcmp.
s1First string to compare.
s2Second string against which to compare the first.

Returns

The diff_strings() primitive returns zero if the two string are equivalent otherwise non-zero.

Portability

A GriefEdit extension.

See Also

<diff_buffers>, <diff_lines>, strcmp, strcasecmp

firstof

int firstof(string str,
string chars,
 [int &result])

Leftmost character search.

Description

The firstof() primitive returns the offset to the first occurrence of any of the characters contained within chars in the string str.

If supplied, on success result shall be populated with the matching character otherwise is set if zero.

firstof() is similar to index yet allows multiple characters to be matched.

Parameters

strString object to be searched.
charsCharacter set to match against.
resultOptional result, populated with the matching character value.

Returns

The firstof() primitive returns the starting offset or 0 if non of the characters are found.

Portability

A GriefEdit extension.

See Also

lastof, index, rindex

format

string format(string format,
 ...)

Formatted printing.

Description

The format() primitive produces formatted output according to the format specification format.  The trailing arguments ... are the integer, string or list expressions used to satisfy the % formatting options; refer to (See: message) for details on the supported format specifications.

The format primitive is similar to the sprintf() primitive with the exception the formatted result is returned directly as a string.

This function is one of a set of formatted output primitives each supporting a common feature set, see message for a complete discussion on the supported format specification syntax.

Parameters

formatString that contains the text to be written.  It can optionally contain an embedded <Format Specification> that are replaced by the values specified in subsequent additional arguments and formatted as requested.
...Optional format specific arguments, depending on the format string, the primitive may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string.
There should be at least as many of these arguments as the number of values specified in the format specifiers.  Additional arguments are ignored by the primitive.

Returns

The format() primitive returns a string containing the formatted results, as defined by the format specification and the values contained within the associated arguments.

Portability

See message

See Also

sprintf

index

int index(string str,
int ch|string s)

Search string for a leftmost sub-string or character.

Description

The index() primitive returns the offset to the first occurrence of the character ch or the string s in the string str.

Parameters

strString object to be searched.
ch|sObject to be matched against.

Returns

The index() primitive returns the starting offsetr or 0 if the character or string was not found.

Portability

The character needle form is a GriefEdit extension.

See Also

rindex

isalnum

int isalnum(string |int object,
 [int index])

Alphanumeric character predicate.

Description

The isalnum() primitive determines whether the specified object object belongs to the alpha or numeric character-classes.

This is [0 through 9], [A through Z] and [a through z] in the program’s current locale; which is equivalent to (isalpha() || isdigit()).

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isalnum() primitive returns non-zero if object is an alphanumeric character; otherwise it returns 0.

Portability

The index option is a GriefEdit extension.

Example

if (isalnum(read(1)))
message("Next character is alnum.");

See Also

ctype

isalpha

int isalpha(string |int object,
 [int index])

Alpha character predicate.

Description

The isalph() primitive determines whether the specified object object belongs to the alpha character-class.

This is [A through Z] and [a through z] in the program’s current locale; which is equivalent to (isupper()

| islower()).

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isalpha() primitive returns non-zero if object is an alphanumeric character; otherwise it returns 0.

Example

if (isalpha(read(1)))
message("Next character is a alpha character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isascii

int isascii(string |int object,
 [int index])

ASCII character predicate.

Description

The isascii() primitive determines whether the specified object object belongs to the ascii character-class.

This is any character value in the range 0 through 0177 (0 through 0x7F), inclusive.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isascii() primitive returns non-zero if object is an alphanumeric character; otherwise it returns 0.

Example

if (isascii(read(1)))
message("Next character is an ascii character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isblank

int isblank(string |int object,
 [int index])

Blank character predicate.

Description

The isblank() primitive determines whether the specified object object belongs to the blank character-class.

This is a space ( ) or tab (\t) character.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isblank() primitive returns non-zero if object is an alphanumeric character; otherwise it returns 0.

Example

if (isblank(read(1)))
message("Next character is blank.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

iscntrl

int iscntrl(string |int object,
 [int index])

Control character predicate.

Description

The iscntrl() primitive determines whether the specified object object belongs to the control character-class.

The control-class is any character for which the isprint() subroutine returns a value of False (0) and any character that is designated a control character in the current locale.  For the C locale, control characters are the ASCII delete character (0177 or 0x7F), or an ordinary control character

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The iscntrl() primitive returns non-zero if object is an control character; otherwise it returns 0.

Example

if (iscntrl(read(1)))
message("Next character is a control character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

iscsym

int iscsym(string |int object,
 [int index])

A symbol character predicate.

Description

The iscsym() primitive determines whether the specified object object belongs to the c-symbol classes, which represent a symbol in the C/C++, GriefEdit macro and similar languages.

This is [0 through 9], [A through Z], [a through z] and underscore (_) in the program’s current locale. which is equivalent to (isalpha() || isdigit() || _).

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The iscsym() primitive returns non-zero if object is a symbol character; otherwise it returns 0.

Example

if (iscsym(read(1)))
message("Next character is symbol character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isdigit

int isdigit(string |int object,
 [int index])

Numeric character predicate.

Description

The isdigit() primitive determines whether the specified object object belongs to the numeric character-class.

This is [0 through 9] in the program’s current locale.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isdigit() primitive returns non-zero if object is an numeric character; otherwise it returns 0.

Example

if (isdigit(read(1)))
message("Next character is a numeric character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isgold

int isgold(string |int object,
 [int index])

Alphanumeric character predicate.

Description

The isgold() primitive determines whether the specified object object belongs to either the function, keypad or special character-classes.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.   The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isgold() primitive returns non-zero if object is a meta/gold key character; otherwise it returns 0.

Portability

A GriefEdit extension.

Example

if (isgold(read(1)))
message("Next character is gold.");

See Also

ctype

isgraph

int isgraph(string |int object,
 [int index])

Graphic character predicate.

Description

The isgraph() primitive determines whether the specified object object belongs to the graphic character-classes.

The a graphic character is equivalent to

(isprint() && not-space)

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isgraph() primitive returns non-zero if object is an graphic character; otherwise it returns 0.

Example

if (isgraph(read(1)))
message("Next character is a graphic character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

islower

int islower(string |int object,
 [int index])

Lowercase character predicate.

Description

The islower() primitive determines whether the specified object object belongs to the lower-case character-classes.

This is [a through z] in the program’s current locale.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The islower() primitive returns non-zero if object is an lower-case character; otherwise it returns 0.

Example

if (islower(read(1)))
message("Next character is a lower-case character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isprint

int isprint(string |int object,
 [int index])

A printable character predicate.

Description

The isprint() primitive determines whether the specified object object belongs to the printable character-class.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isprint() primitive returns non-zero if object is an printable character; otherwise it returns 0.

Example

if (isprint(read(1)))
message("Next character is printable.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

ispunct

int ispunct(string |int object,
 [int index])

Punctuation character predicate.

Description

The ispunct() primitive determines whether the specified object object belongs to the punctuation character-class.

Punctuation characters are ones that are printable ((see isprint )) character but neither alphanumeric (See: isalnum) nor a space (See: isspace).

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The ispunct() primitive returns non-zero if object is an alphanumeric character; otherwise it returns 0.

Example

if (ispunct(read(1)))
message("Next character is alnum.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isspace

int isspace(string |int object,
 [int index])

Space character predicate.

Description

The isspace() primitive determines whether the specified object object belongs to the space character-class.

White-space characters are (space, form feed (\f), new-line (\n), carriage-return (\r), horizontal tab (\t) or vertical tab (\v).

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The issspace() primitive returns non-zero if object is an whitespacec character; otherwise it returns 0.

Example

if (isspace(read(1)))
message("Next character is a space character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isupper

int isupper(string |int object,
 [int index])

Uppercase character predicate.

Description

The isupper() primitive determines whether the specified object object belongs to the uppercase character-class.

This is [A through Z] in the program’s current locale.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isupper() primitive returns non-zero if object is an uppercase character; otherwise it returns 0.

Example

if (isupper(read(1)))
message("Next character is an uppercase character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isword

int isword(string |int object,
 [int index])

Word character predicate.

Description

The isword() primitive determines whether the specified object object belongs to the word character-class.

This is [A through Z], [a through z], [o through 9] and underscore (_) or dash (-) in the program’s current locale; which is equivalent to (isalpha() || isdigit() || _ || ‘-’).

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isword() primitive returns non-zero if object is an word character; otherwise it returns 0.

Example

if (isword(read(1)))
message("Next character is a word character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

isxdigit

int isxdigit(string |int object,
 [int index])

Hexadecimal character predicate.

Description

The isxdigit() primitive determines whether the specified object object belongs to the hexadecimal character-class.

This is [0 through 9], [A through f] and [a through f] in the program’s current locale.

The specified object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.

The optional index allows an alternative character within the string to be tested, with the first character represented by offset one.

Parameters

objectCharacter or string object.
[index]If a string, an optional character index within the string, starting at offset one being the first character. if the index denotes a character out-of-bounds, the function returns 0.

Returns

The isxdigit() primitive returns non-zero if object is a hexadecimal character; otherwise it returns 0.

Example

if (isxdigit(read(1)))
message("Next character is a hexadecimal character.");

Portability

The index option is a GriefEdit extension.

See Also

ctype

itoa

string itoa(int value,
 [int base = 10])

Convert an integer into a string.

Description

The itoa() primitive converts an integer value to a string using the specified base and returns the result.

If base is 10 and value is negative, the resulting string is preceded with a minus sign (-).  With any other base, value is always considered unsigned.

Returns

Upon successful completion, itoa() returns the converted value.  If no conversion could be performed, itoa() returns an empty string.

Portability

A GriefEdit extension.

See Also

atoi, strtod, strtof, sscanf

lastof

int lastof(string str,
string chars,
 [int &result])

Rightmost character search.

Description

The lastof() primitive returns the offset to the last occurrence of any of the characters contained within chars in the string str.

If supplied, on success result shall be populated with the matching character otherwise is set if zero.

lastof() is similar to rindex yet allows multiple characters to be matched.

Parameters

strString object to be searched.
charsCharacter set to match against.
resultOptional result, populated with the matching character value.

Returns

The lastof() primitive returns the starting offset or 0 if non of the characters are found.

Portability

A GriefEdit extension.

See Also

index, rindex

lower

string|int lower(string str|int character)

Convert string or character to lowercase.

Description

The lower() primitive converts all alphabetic characters within the string object str or just the specified character ch to lowercase.

Returns

Returns the specified object with all alphabetic characters converted to lowercase.

If the argument is a string then a copy of the string is returned, otherwise the integer value of the converted character.

Portability

Character support is a GriefEdit extension.

See Also

ltrim

string ltrim(string str,
 [string chars = " \\t\\r\\n"])

Chomp characters from the front of a string.

Description

The ltrim() primitive removes leading (or left) characters from the specified string.

The default is to remove all tabs, spaces and newline characters.  If chars is specified, then all characters within the trimchar string are removed from the beginning of the string.

Returns

Returns a copy of string with all leading white space characters removed.  (spaces, tabs and newlines by default).

Portability

n/a

See Also

compress, trim, rtrim

macro_list

list macro_list([string pattern = NULL])

Retrieve list of current macros.

Description

The macro_list() primitive retrieves a sorted list of all defined macros.

The optional pattern is a regular expression similar to that accepted by the command line shells (See: file_match), providing an inclusion filter.

Parameters

patternOptional string value containing the macro-name pattern to be applied against each name, only returning the matching.  A macro-name expression is a shell style regular expression (See: file_match) (e.g.  * for wildcard, ? for wild-character, and [..] to select a range of characters).

Returns

The macro_list() primitive returns a list of strings each containing the name of a macro.

Portability

n/a

See Also

command_list, file_match

read

string read([int number],
[int &status])

Read characters from the buffer.

Description

The read() primitive reads characters up to the specified number of characters length, if omitted characters are read up to the end of the current buffer including the new-line terminator.

The current buffer position remains unchanged.

Parameters

  • 0 - Partial, within a line.
  • 1 - End of line.
  • -1 - End of file.
numberAn optional number of characters to be read.
statusOptional integer variable reference to be populated with the read completion status, representing the position of the cursor at the end of the read operation;

Returns

The read() primitive returns the string read.

Portability

n/a

See Also

insert, insertf

rindex

int rindex(string str,
int ch|string s)

Search string for a rightmost sub-string or character.

Description

The rindex() primitive returns the offset to the last (in otherwords the right) occurrence of the character ch or the string s in the string str.

Parameters

strString object to be searched.
ch|sObject to be matched against.

Returns

The rindex() primitives returns the starting offset or 0 if the character or string was not found.

Portability

The character needle form is a GriefEdit extension.

See Also

index

rtrim

string rtrim(string str,  
string chars =  \\t \\r \\n)

Chomp characters from the end of a string.

Description

The rtrim() primitive removes trailing (or right) characters from the specified string.

The default is to remove all tabs, spaces and newline characters.  If chars is specified, then all characters within the trimchar string are removed from the end of the string.

Returns

Returns a copy of string with all trailing white space characters removed.  (spaces, tabs and newlines by default).

Portability

A GriefEdit extension; this is a replacement of the original trim() function.

See Also

compress, trim, ltrim

search_string

int search_string(string pattern,
string text,
  [int &length],
 [int re],
 [int case])

Searches for a pattern in a string.

Description

The search_string() primitive searches the string text against the expression pattern.  The treatment of the matched pattern may either be a regular-expression or constant string dependent on re and with case folding based on case.

Note:

The search_string primitive is provided primary for BRIEF compatibility.  Since re and case can reference the current global search states, inconsistent and/or unexpected results may result between usage; as such it is advised that the state-less re_search primitive is used by new macros.

Parameters

patternA string containing the pattern to be matched.
textA string containing the text to be search for the specified pattern.
lengthOptional integer variable reference.  If ths search is successful and specified is populated with the length of the matched text.
reOptional integer value.  If re is specified and is zero, then pattern is treated as a literal string not as a regular expression; behaviour being the same as index.  Otherwise the string shall be treated as a regular expression using the current global syntax, see re_syntax and search_back for additional information.
caseOptional integer value specifying whether case folding should occur.  If case is specified and is zero, then the search is done with case insensitive.  If omitted the current global setting is referenced.

Returns

The search_string() primitive returns the starting character in string where the match was found, or zero if the match failed.

Alternatively, if a \\c anchor was encountered within the pattern, it returns the length of the text from the position of the marker to the end of the matched text plus one.

Portability

n/a

See Also

re_search

split

list split(string expr,
string|integer delims,
  [int numeric = FALSE],
 [int noquoting = FALSE],
  [int empties = FALSE],
 [int limit = 0])

Split a string into tokens.

Description

The split() primitive splits the string expr into a list of strings and returns the resulting list.

split provides simple field processing, compared to the tokenize primitive which offers greater functionality.

Parameters

exprString to be parsed.
delimsSpecifies either a string containing the characters used to split the token, alternative an integer character value of a single character.
numericIf specified and is true(1), then all tokens which start with a digit are converted to a number, rather than a string.  Alternative when given as two (2) then values are converted using strtol(), allowing support leading base specifications hexidecimal (0x), octal (0) and binary (0b).
nonquotingUpon the delim parameter containing a double quote character then it is assumed that any entries inside double quotes should have any embedded characters preserved.  When specified the noquote optional allows explicit control enabling and disabling of this feature.
emptiesUpon the delim character being given as a integer value empty split column are not returned witnin the list.  When specified the empties optional allows explicit control enabling (non-zero) and disabling (zero) to whether empties are returned.
limitLimit the split to limit elements, returning the trailing content in the last element; note any special processing including quotes and numeric wont apply on the trailing.

Results

List of strings where each string is a token from the string parameter.

Portability

The options empties and limit are GriefEdit extensions.

See Also

tokenize, sscanf, index, substr

Examples

Using | was a delimiter and empties being returned.

''         ==> ''
'a' ==> 'a'
'|b' ==> '', 'b'
'|' ==> '', ''
'a|b' ==> 'a', 'b'
'a|b|' ==> 'a', 'b', ''
'a|b|c' ==> 'a', 'b', 'c'
'a||b' ==> 'a', '', 'b'

the same without empties

''          ==>
'a' ==> 'a'
'|b' ==> 'b'
'|' ==>
'a|b' ==> 'a', 'b'
'a|b|' ==> 'a', 'b'
'a||b' ==> 'a', 'b'

split_arguments

list split_arguments(string arguments)

Argument split.

Description

The split_arguments() primitive splits argument into list of words.  As it parses the command line, split_arguments looks for command separators, white space (spaces and tabs).  Normally, these special characters cannot be passed to a command as part of an argument.  However, special characters in an argument by enclosing the entire argument in double quotes [“].  The [“] themselves will not be passed to the command as part of the argument.  Within a double quoted string the [“] character and [\] character can be represented as [\”] and [\\].

Parameters

argumentString containing the argument buffer.

Return

The split_argument returns a list of words encountered within the argument buffer.

Portability

A GriefEdit extension.

See Also

getsubopt

sprintf

int sprintf(string &buffer,
string format,
 ...)

Formatted printing to a string.

Description

The sprintf() primitive produces formatted output according to the format specification format into the given string buffer.  The trailing arguments ... are the integer, string or list expressions used to satisfy the % formatting options; refer to (See: message) for details on the supported format specifications.

The format primitive is similar to the C sprintf() primitive, exporting the formatted result into the destination buffer.

This function is one of a set of formatted output primitives each supporting a common feature set, see message for a complete discussion on the supported format specification syntax.

Parameters

bufferString which shall be populated with the result.
formatString that contains the text to be written.  It can optionally contain an embedded <Format Specification> that are replaced by the values specified in subsequent additional arguments and formatted as requested.
...Optional format specific arguments, depending on the format string, the primitive may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string.
There should be at least as many of these arguments as the number of values specified in the format specifiers.  Additional arguments are ignored by the primitive.

Returns

The sprintf() primitive returns the number of charaters stored within the result string buffer.

Portability

See message

See Also

format, error, message

sscanf

int sscanf(string str,
string format,
 ...)

Read formatted data from string.

Description

The sscanf() primitive reads data from the string buffer str.  Data input are stored in the locations specified by argument according to the format string format.

The additional arguments should be objects of the type specified by their corresponding format specifier within the format string.

Parameters

strSource buffer.
formatString that contains a format string, see below.
...Additional arguments; depending on the format string, the function may expect a sequence of additional arguments, each containing a reference to a variable where the interpretation of the extracted characters is stored with the appropriate type.  There should be at least as many of these arguments as the number of values stored by the format specifiers.  Additional arguments are ignored by the function.

Return Value

The sscanf() primitive returns the number of input fields that were successfully converted.  An EOF (-1) is returned if an error is encountered.

Portability

A GriefEdit extension.

Format Specification

The format may be composed of one or more whitespace characters, non whitespace characters, and format specifications.

The format string is read from left to right.  Characters that are not part of the format specifications must match characters in the input stream.  These characters are read from the input stream but are discarded and not stored.  If a character in the input stream conflicts with the format string, scanf terminates.  Any conflicting characters remain in the input stream.

  • whitespace characters - blank (‘ ‘), tab (\t), or newline (\n), cause scanf to skip whitespace characters in the input stream.  A single whitespace character in the format string matches 0 or more whitespace characters in the input stream.
  • non whitespace characters - with the exception of the percent sign (%), cause scanf to read but not store a matching character from the input stream.  The scanf function terminates if the next character in the input stream does not match the specified non-whitespace character.
  • format specifications - begin with a percent sign (%) and cause scanf to read and convert characters from the input stream to the specified type values.  The converted value is stored to an argument from the parameter list.  Characters following a percent sign that are not recognized as a format specification are treated as ordinary characters.  For example, %% matches a single percent sign in the input stream.

Format Specification

The first format specification encountered in the format string references the first argument after format.  The scanf function converts input characters and stores the value using the format specification.  The second format specification accesses the second argument after format, and so on.  If there are more arguments than format specifications, the extra arguments are ignored.  Results are unpredictable if there are not enough arguments for the format specifications.

Values in the input stream are called input fields and are delimited by whitespace characters.  When converting input fields, scanf ends a conversion for an argument when a whitespace character or another unrecognized character is encountered.

Format specifications have the following format

% [*] [width] type

Each field in the format specification can be a single character or a number which specifies a particular format option.

The type field is where a single character specifies whether input characters are interpreted as a character, string, or number.  This field can be any one of the characters in the following table.

scanf types
Character
Argument Type
Input Format
d
int &
Signed decimal number.
i
int &
Signed decimal, hexadecimal, or octal integer.
u
int &
Unsigned decimal number.
o
int &
Unsigned octal number.
x
int &
Unsigned hexadecimal number.
e
float &
Floating-point number.
f
float &
Floating-point number.
g
float &
Floating-point number.
c
int &
A single character.
s
string &
A string of characters terminated by whitespace.
\[
string &
A string not to be delimited by space characters.
Type Specifiers

An asterisk (*) as the first character of a format specification causes the input field to be scanned but not stored.  The asterisk suppresses assignment of the format specification.

The width field is a non-negative number that specifies the maximum number of characters read from the input stream.  No more than width characters are read and converted for the corresponding argument.  However, fewer than width characters may be read if a whitespace or other unrecognized character is encountered first.

Character Set

[ indicates a string not to be delimited by space characters.

The conversion specification includes all subsequent characters in the format string up to and including the matching right square bracket (]).

The characters between the square brackets comprise the scanset, unless the character after the left square bracket is a circumflex (^), in which case the scanset contains all characters that do not appear in the scanlist between the circumflex and the right square bracket.

If the conversion specification begins with “[]” or “[^]”, the right square bracket is included in the scanlist and the next right square bracket is the matching right square bracket that ends the conversion specification; otherwise the first right square bracket is the one that ends the conversion specification.

If a hyphen character (-) is in the scanlist and is not the first character, nor the second where the first character is a circumflex (^), nor the last character, it indicates a range of characters to be matched.  To include a hyphen, make it the last character before the final close bracket.  For instance, `[^]0-9-]’ means the set `everything except close bracket, zero through nine, and hyphen’.

Character classes

Within a bracket expression, the name of a character class enclosed in [: and :] stands for the list of all characters (not all collating elements!) belonging to that class.

Types
Identifier
Description
alpha
A letter.
upper
An upper-case letter.
lower
A lower-case letter.
blank
A space or tab character.
digit
A decimal digit.
xdigit
A hexadecimal digit.
alnum
An alphanumeric (letter or digit).
print
An alphanumeric (same as alnum).
blank
A space or tab character.
space
A character producing white space in displayed text.
punct
A punctuation character.
graph
A character with a visible representation.
cntrl
A control character.
word
A “word” character (alphanumeric plus “_”).
Type Specifiers

strcasecmp

int strcasecmp(string s1,
string s2,
 [int length])

String case insensitive compare.

Description

The strcmp() primitive shall compare the string s1 to the string s2, ignoring case.

Parameters

s1First string.
s2Second string to compare against.
lengthOptional, when specified only the first length characters of both string shall be compared.

Return

strcasecmp() shall return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2, respectively; when ignoring case.

Portability

A GriefEdit extension.

See Also

strcmp, ==, <=>

strcasestr

sub-string. int strcasestr(
   string haystack,
   string needle
)

Locate first occurrence of a case insensitive.

Description

The strcasestr() primitive finds the first occurrence of the case insensitive sub-string needle in the string haystack.

Parameters

haystackString object to be searched.
needleString to be matched.

Return

Index of first matching character starting at the index one, otherwise zero if no match.

Portability

A GriefEdit extension.

See Also

strstr, strrstr, index, rindex

strcmp

int strcmp(string s1,
string s2,
 [ int length])

String compare.

Description

The strcmp() primitive shall compare the string s1 to the string s2 not ignoring case.

Parameters

s1First string.
s2Second string to compare against.
lengthOptional, when specified only the first length characters of both string shall be compared.

Return

strcmp() shall return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2, respectively.

Portability

A GriefEdit extension.

See Also

strcasecmp, <=>

strfilecmp

int strfilecmp(string file1,
string file2,
 [int length])

Filename comparison.

Description

The strfilecmp() primitive lexicographically compares the filenames name1 and name2 and returns a value indicating their relationship, taking into account any filesystem implementation specifics.

If specified length defines the number of significant characters of each path which shall be compared, ignoring any characters after the length characters of each.

Notes

Under DOS, Windows and OS/2 this primitive is case insensitive and permits the intermixing of both back(\) and forward(/) slashes as directory delimiters.

Under Unix™ this primitive is the same as an equality (==) operation between two strings.

Returns

The return indicates the lexicographic relation of name1 and name2.

<0 - name1 less than name2.
0 - name1 identical to name2.
>0 - name1 greater than name2.

Portability

A GriefEdit extenions.

See Also

strcmp

strftime

string strftime([string format = NULL],
[int time = NULL])

Format time and date.

Description

The strftime() primitive is an interface to the system library function strftime.  Unless time is specified, the current time shall be formatted otherwise the stated time shall be formatted.

The format specification is a string and may contain special character sequences called conversion specifications, each of which is introduced by a % character and terminated by some other character known as a conversion specifier character.  All other character sequences are ordinary character sequences.

Conversion specifications

Most implementations support the following conversion specifications.

%ais replaced by the locale’s abbreviated weekday name.
%Ais replaced by the locale’s full weekday name.
%bis replaced by the locale’s abbreviated month name.
%Bis replaced by the locale’s full month name.
%cis replaced by the locale’s appropriate date and time representation.
%Cis replaced by the century number (the year divided by 100 and truncated to an integer) as a decimal number [00-99].
%dis replaced by the day of the month as a decimal number [01,31].
%Dsame as %m/%d/%y.
%eis replaced by the day of the month as a decimal number [1,31]; a single digit is preceded by a space.
%hsame as %b.
%His replaced by the hour (24-hour clock) as a decimal number [00,23].
%Iis replaced by the hour (12-hour clock) as a decimal number [01,12].
%jis replaced by the day of the year as a decimal number [001,366].
%mis replaced by the month as a decimal number [01,12].
%Mis replaced by the minute as a decimal number [00,59].
%nis replaced by a newline character.
%pis replaced by the locale’s equivalent of either a.m. or p.m.
%ris replaced by the time in a.m. and p.m. notation; in the POSIX locale this is equivalent to %I:%M:%S %p.
%Ris replaced by the time in 24 hour notation (%H:%M).
%Sis replaced by the second as a decimal number [00,61].
%tis replaced by a tab character.
%Tis replaced by the time (%H:%M:%S).
%uis replaced by the weekday as a decimal number [1, 7], with 1 representing Monday.
%Uis replaced by the week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
%Vis replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01, 53].  If the week containing 1 January has four or more days in the new year, then it is considered week 1.  Otherwise, it is the last week of the previous year, and the next week is week 1.
%wis replaced by the weekday as a decimal number [0, 6], with 0 representing Sunday.
%Wis replaced by the week number of the year (Monday as the first day of the week) as a decimal number [00, 53].  All days in a new year preceding the first Monday are considered to be in week 0.
%xis replaced by the locale’s appropriate date representation.
%Xis replaced by the locale’s appropriate time representation.
%yis replaced by the year without century as a decimal number [00,99].
%Yis replaced by the year with century as a decimal number.
%Zis replaced by the timezone name or abbreviation, or by no bytes if no timezone information exists.
%%is replaced by %.

Returns

The strftime function returns a string containing the formatted time and date.

Portability

A GriefEdit extension.

See Also

time, cftime, date, stat, localtime, gmtime

string_count

int string_count(string haystack,
int needle|string needles)

Count occurrences of characters in a string.

Description

The string_count() primitive computes the number of occurrences of the character(s) within needles in the string haystack.

Parameters

haystackString to be searched.
needleElements to the counted, each character shall be accumulated.

Returns

Returns the number of times the characters in needle occur in the string parameter.

Portability

The integer needle form is a GriefEdit extension.

See Also

substr, rindex, index

strpbrk

int strpbrk(string str,
string characters)

Search a string for any of a set of characters.

Description

The strpbrk() primitive returns the index of the first character in str which matches any character from the string characters.

This function is like index() and rindex() yet these only matches a single character string rather than a complete sub-string.

Return

Index of first matching character starting at the index one, otherwise zero if no match.

Portability

A GriefEdit extension.

See Also

firstof, lastof

strpop

string strpop(string str,
 [int length = 1])

Pop the leading character(s).

Description

The strpop() primitive is equivalent to substr(sym, 1, length) with the additional functionality that the returned character is removed from the specified string str.

Portability

length is a GriefEdit extension.

Return

String value containing the first character(s) of the original value of sym.

See Also

substr, characterat

strrstr

int strrstr(string haystack,
string needle)

Locate last occurrence of a sub-string.

Description

The strrstr() primitive finds the last occurrence of the sub-string needle in the string haystack.

Parameters

haystackString object to be searched.
needleString to be matched.

Return

Index of last matching character starting at the index one, otherwise zero if no match.

Portability

A GriefEdit extension.

See Also

strstr, index, rindex

strstr

int strstr(string haystack,
string needle)

Locate first occurrence of a sub-string.

Description

The strstr() primitive finds the first occurrence of the sub-string needle in the string haystack.

Parameters

haystackString object to be searched.
needleString to be matched.

Return

Index of first matching character starting at the index one, otherwise zero if no match.

Portability

A GriefEdit extension.

See Also

strcasestr, strrstr, index, rindex

strtod

int strtod(string str,
 [int &endofoffset])

String to double.

Description

The strtod() primitive converts the initial portion of the string str to a floating point double representation; it is an interface to the standard library function of the same name.

Returns

Upon successful completion, strtod() returns the converted value, if any, and (if supplied) an index (base of 1) to the first unprocessed character within the string is stored in the integer object endoffset.

If no conversion could be performed, strtod() returns 0 and errno may be set to EINVAL.  The subject sequence contains no characters and index of 0 is stored in endoffset.

If the correct value is outside the range of representable values, strtod() returns HUGE_MAX or HUGE_MIN and errno is set to ERANGE.

Portability

A GriefEdit extension.

See Also

atoi, strtof, sscanf

strtof

int strtof(string str,
 [int &endofoffset])

String to float.

Description

The strtof() primitive converts the initial portion of the string str to a floating point representation; it is an interface to the standard library function of the same name.

Returns

Upon successful completion, strtof() returns the converted value, if any, and (if supplied) an index (base of 1) to the first unprocessed character within the string is stored in the integer object endoffset.

If no conversion could be performed, strtof() returns 0 and errno may be set to EINVAL.  The subject sequence contains no characters and index of 0 is stored in endoffset.

If the correct value is outside the range of representable values, strtod() returns FLT_MAX or FLT_MIN and errno is set to ERANGE.

Portability

A GriefEdit extension

See Also

atoi, strtod, sscanf

strtol

int strtol(string str,
 [int &endoffset],
 [int base])

Convert a string into its numeric value.

Description

The strtol() primitive converts the initial portion of the string str to a type integer representation; it is an interface to the standard library function of the same name.

If the value of base is 0 (or if not supplied), the expected form of the subject sequence is that of a decimal constant, octal constant or hexadecimal constant, any of which may be preceded by a ‘+ ‘or ‘- ‘sign.  A decimal constant begins with a non-zero digit, and consists of a sequence of decimal digits.  An octal constant consists of the prefix 0 optionally followed by a sequence of the digits ‘0 ‘to ‘7 ‘only.  A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal digits and letters a (or A) to f (or F) with values 10 to 15 respectively.

If the value of base is between 2 and 36, the expected form of the subject sequence is a sequence of letters and digits representing an integer with the radix specified by base, optionally preceded by a + or - sign.  The letters from a (or A) to z (or Z) inclusive are ascribed the values 10 to 35; only letters whose ascribed values are less than that of base are permitted.  If the value of base is 16, the characters 0x or 0X may optionally precede the sequence of letters and digits, following the sign if present.

The subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-white-space character, that is of the expected form.  The subject sequence contains no characters if the input string is empty or consists entirely of white-space characters, or if the first non-white-space character is other than a sign or a permissible letter or digit.

If the subject sequence has the expected form and the value of base is 0, the sequence of characters starting with the first digit is interpreted as an integer constant.  If the subject sequence has the expected form and the value of base is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value as given above.  If the subject sequence begins with a minus sign, the value resulting from the conversion is negated.

Returns

Upon successful completion, strtol() returns the converted value, if any, and (if supplied) an index (base of 1) to the first unprocessed character within the string is stored in the integer object endoffset.

If no conversion could be performed, strtol() returns 0 and errno may be set to EINVAL.  The subject sequence contains no characters and index of 0 is stored in endoffset.

If the correct value is outside the range of representable values, strtol() returns LONG_MAX or LONG_MIN and errno is set to ERANGE.

Portability

A GriefEdit extension.

See Also

atoi, itoa, strtod, strtof, sscanf

strverscmp

int strverscmp(string s1,
string s2)

Version string compare.

Description

strverscmp(3)/versionsort(3) style version comparison function.

Often one has files jan1, jan2, ..., jan9, jan10, ... and it feels wrong when ls orders them jan1, jan10, ..., jan2, ..., jan9.  In order to rectify this, GNU introduced the -v option to ls(1), which is implemented using versionsort(3), which again uses strverscmp.

Thus, the task of strverscmp is to compare two strings and find the “right” order, while strcmp only finds the lexicographic order.

Return

The strverscmp() primitive returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be earlier than, equal to, or later than s2.

Portability

A GriefEdit extension.

See Also

strcmp, strcasecmp, ==

substr

string substr(string str,
 [int offset],
 [int length])

Extract a sub-string.

Description

The substr() primitive extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.

The substr() primitive does not change the original string.

Parameters

offsetThe position where to start the extraction.  First character is at index 1.
lengthOptional, the number of characters to extract.

Returns

Returns the sub-string of string which starts at start, and goes on for length characters, or the end of the string if length is omitted.

See Also

index, rindex

tokenize

list tokenize(string expr,
string delims,
int flags,
 [string whitespace = "\t\n\r"])

Tokenize a string into token elements.

Description

The tokenize() primitive tokenizes the string expr into a list of strings and returns the list in list context.

tokenize() provides greater field processing then the simpler split primitive and should be used by new macros.

Parameters

exprString to be tokenize.
delimsis a string consisting of one or more characters which indicate the delimiter characters.
flagsis an integer containing a set of flags which indicate how the input string is to be tokenized.  Flags consist of one or more the tokenize flags detailed below OR’ed together.
whitespaceOptional set of characters to be treated as whitespace.

Tokenize flags

General
  • TOK_COLLAPSE_MULTIPLE - Splits the string expr into a list of strings and returns the list in list context.  Collapses occurrences of the repeated delimiter characters treating them as single delimiter, in other words empty elements with the delimited text shall not be returned.
Numeric field conversion
  • TOK_NUMERIC - Fields which begin with a digit are converted into their decimal numeric value and returned as integer element rather than a string.
  • TOK_NUMERIC_STRTOL - Numeric fields are converted using strtol allowing support leading base specifications hexadecimal (0x), octal (0) and binary (0b).
  • TOK_NUMERIC_STRICT - Strict conversion of numeric fields where by any invalid values, for example trailing non-numeric characters, result in the the field being returned as a string element and not a integer element.
Parsing options
  • TOK_WHITESPACE - Allow leading and trailing whitespace around quoted and numeric element.
  • TOK_BACKSLASHES - Allow backslahes to escape the meaning of any delimiter characters and both single and double.
  • TOK_ESCAPE - Enable backslash escape sequence processing.
  • TOK_ESCAPEALL - Control the behaviour of TOK_ESCAPE to escape all characters preceded with a backslashes, otherwise by default unknown escape sequences are ignored.
Quote options
  • TOK_DOUBLE_QUOTES - Enables double quote support where all characters enclosed within a pair of matching quotes are treated as a single element including any embedded delimiters.
  • TOK_DOUBLE_QUOTES - Same as TOK_DOUBLE_QUOTES but enables single quote support.
  • TOK_QUOTE_STRINGS - When single or double quoted support is enabled allow the element is be enclosed within a extra pair of quotes, for example
""hello world""
  • TOK_PRESERVE_QUOTES - When an element is enclosed in quotes and the quote character is specified in delims then the returned element shall also be enclosed within the encountered quotes.
Field Processing Options
  • TOK_TRIM_LEADING - Remove any leading whitespace from non-quoted string elements.  Whitespace is defined as any space, tab or newline character unless they exist within the set of specified delimiters.
  • TOK_TRIM_TRAILING - Remove any trailing whitespace from string elements.
  • TOK_TRIM - Remove any leading and trailing whitespace characters.
  • TOK_TRIM_QUOTED - Apply trim logic to quoted strings.

Return

The tokensize() primitive returns a list of the words and/or numeric values as encountered within the string str.

Portability

Many of the features are GriefEdit specific; CRiSP ™ has a similar primitive yet as the two were developed independently features differ.

See Also

split, sscanf, index, substr

trim

string trim(string str,
 [string chars = " \\t\\r\\n"])

Chomp characters from a string.

Description

The trim() primitive removes leading and trailing characters from the specified string.

The default is to remove all tabs, spaces and newline characters.  If chars is specified, then all characters within the trimchar string are removed from the beginning and end of the string.

Parameters

strString object to be trimmed.
charsOptional string defining the set to characters to be removed.

Returns

Returns a copy of string with all leading and trailing white space characters removed.  (spaces, tabs and newlines by default).

Portability

The chars and removal of trailing characters in addition to leading is a GriefEdit extension (See: rtrim).

See Also

compress, ltrim, rtrim

upper

string|int upper(string str|int character)

Convert string or character to uppercase.

Description

The upper() primitive converts all alphabetic characters within the string object str or just the specified character ch to uppercase.

Returns

Returns the specified object with all alphabetic characters converted to uppercase.

If the argument is a string then a copy of the string is returned, otherwise the integer value of the converted character.

Portability

Character support is a GriefEdit extension.

See Also

lower

ctype

Character classes

Description

The GriefEdit ctype (character class) functionality is used to designated character-coded integer values into one or more character types.

Standard character classes are;

  • alnum - An alphanumeric (letter or digit).
  • alpha - A letter.
  • ascii - An ASCII character (ie 0 > x < 127).
  • blank - A space or tab character.
  • cntrl - A control character.
  • csym - A symbol.
  • digit - A decimal digit.
  • graph - A character with a visible representation.
  • lower - A lower-case letter.
  • print - An alphanumeric (same as alnum).
  • punct - A punctuation character.
  • space - A character producing white space in displayed text.
  • upper - An uppercase letter.
  • xdigit - A hexadecimal digit.

Support

The following GriefEdit interfaces have direct support for character-classes:

Bracket expressions

Within sscanf and search <regexp> expressions, the name of a character class enclosed in [: and :] stands for the list of all characters (not all collating elements!) belonging to that class.

Macros

The set of the isaxxxx(object, [index]) primitive exist allowing tests within macros.  Each of these subroutines returns a nonzero value is the specified value is contained within the given class, otherwise zero.

The specified argument object can be an integer (whose ASCII code represents a single character), or a string, in which case the first character of the string is tested.  The optional index allows an alternative character within the string to be tested, starting at offset one being the first character.

Note:

The isaxxx() primitives should only be used on character data that can be represented by a single byte value (0 through 255).  Attempting to use the ctype subroutines on multi-byte locale data may give inconsistent results.

See Also

sscanf, <regexp>, isalnum, isalpha, isascii, iscntrl, iscsym, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit

$Id: $

To send feedback on this topic email: grie.nosp@m.fedit@gmai.nosp@m.l.com

Copyright © Adam Young All Rights Reserved.

int atoi(string str,
 [int svalue = TRUE])
Convert string to a decimal number.
string cftime(string format,
int time)
Format time and date.
int characterat(string str,
int index)
Retrieve the character value within a string.
string compress(
   string str,
    [int trim = FALSE],
      [string chars = " \\t\\r\\n"],
    [int replacement = ' ']
)
Compress repeated instances of white-space characters.
int diff_strings( [int flags],
string s1,
string s2)
Compare to strings.
int firstof(string str,
string chars,
 [int &result])
Leftmost character search.
string format(string format,
 ...)
Formatted printing.
int index(string str,
int ch|string s)
Search string for a leftmost sub-string or character.
int isalnum(string |int object,
 [int index])
Alphanumeric character predicate.
int isalpha(string |int object,
 [int index])
Alpha character predicate.
int isascii(string |int object,
 [int index])
ASCII character predicate.
int isblank(string |int object,
 [int index])
Blank character predicate.
int iscntrl(string |int object,
 [int index])
Control character predicate.
int iscsym(string |int object,
 [int index])
A symbol character predicate.
int isdigit(string |int object,
 [int index])
Numeric character predicate.
int isgold(string |int object,
 [int index])
Alphanumeric character predicate.
int isgraph(string |int object,
 [int index])
Graphic character predicate.
int islower(string |int object,
 [int index])
Lowercase character predicate.
int isprint(string |int object,
 [int index])
A printable character predicate.
int ispunct(string |int object,
 [int index])
Punctuation character predicate.
int isspace(string |int object,
 [int index])
Space character predicate.
int isupper(string |int object,
 [int index])
Uppercase character predicate.
int isword(string |int object,
 [int index])
Word character predicate.
int isxdigit(string |int object,
 [int index])
Hexadecimal character predicate.
string itoa(int value,
 [int base = 10])
Convert an integer into a string.
int lastof(string str,
string chars,
 [int &result])
Rightmost character search.
string|int lower(string str|int character)
Convert string or character to lowercase.
string ltrim(string str,
 [string chars = " \\t\\r\\n"])
Chomp characters from the front of a string.
list macro_list([string pattern = NULL])
Retrieve list of current macros.
string read([int number],
[int &status])
Read characters from the buffer.
int rindex(string str,
int ch|string s)
Search string for a rightmost sub-string or character.
string rtrim(string str,  
string chars =  \\t \\r \\n)
Chomp characters from the end of a string.
int search_string(string pattern,
string text,
  [int &length],
 [int re],
 [int case])
Searches for a pattern in a string.
list split(string expr,
string|integer delims,
  [int numeric = FALSE],
 [int noquoting = FALSE],
  [int empties = FALSE],
 [int limit = 0])
Split a string into tokens.
list split_arguments(string arguments)
Argument split.
int sprintf(string &buffer,
string format,
 ...)
Formatted printing to a string.
int sscanf(string str,
string format,
 ...)
Read formatted data from string.
int strcasecmp(string s1,
string s2,
 [int length])
String case insensitive compare.
sub-string. int strcasestr(
   string haystack,
   string needle
)
Locate first occurrence of a case insensitive.
int strcmp(string s1,
string s2,
 [ int length])
String compare.
int strfilecmp(string file1,
string file2,
 [int length])
Filename comparison.
string strftime([string format = NULL],
[int time = NULL])
Format time and date.
int string_count(string haystack,
int needle|string needles)
Count occurrences of characters in a string.
int strpbrk(string str,
string characters)
Search a string for any of a set of characters.
string strpop(string str,
 [int length = 1])
Pop the leading character(s).
int strrstr(string haystack,
string needle)
Locate last occurrence of a sub-string.
int strstr(string haystack,
string needle)
Locate first occurrence of a sub-string.
int strtod(string str,
 [int &endofoffset])
String to double.
int strtof(string str,
 [int &endofoffset])
String to float.
int strtol(string str,
 [int &endoffset],
 [int base])
Convert a string into its numeric value.
int strverscmp(string s1,
string s2)
Version string compare.
string substr(string str,
 [int offset],
 [int length])
Extract a sub-string.
list tokenize(string expr,
string delims,
int flags,
 [string whitespace = "\t\n\r"])
Tokenize a string into token elements.
string trim(string str,
 [string chars = " \\t\\r\\n"])
Chomp characters from a string.
string|int upper(string str|int character)
Convert string or character to uppercase.
int message(string format,
 ...)
Display a message on the command line.
Character classes
int file_match(pattern,
file,
[flags])
File match utility.
list command_list(  [int nomacros = FALSE],
[string pattern])
Retrieve list of built-in and active macros.
int insert(string|int val,
 [int num = 1])
Insert string into current buffer.
int insertf(string format,
 ...)
Insert a formatted string.
int re_search([int flags],
[string pattern],
 [declare object],
[int start],
[int lensym])
Search for a string.
int re_syntax([int re],
[int case],
[int capture])
Set the regular expression mode.
int search_back(string pattern,
 [int re],
 [int case],
  [int block],
 [int length])
Backwards buffer search.
int getsubopt(string value,
 [list options],
  [string|list args],
 [string delim],
 [string quotes])
Parse suboption arguments from a string.
int error(string format,
 ...)
Issue an error message on the command line.
expr1 == expr2
Equality operator.
expr1 <=> expr2
Comparison operator.
int time([int &hour],
[int &min],
[int &sec],
[int &msec])
Get the current system time.
int date([int &year],
[int &month],
[int &day],
 [string &monname],
[string &dayname])
Get current system date.
int stat([string path],
[int size],
 [int mtime],
[int ctime],
 [int atime],
[int mode],
[int uid],
[string uid2name],
 [int gid],
[string gid2name],
 [int nlink],
[int inode])
Obtain file information.
int localtime([int time = NULL],
[int &year],
[int &mon],
[int &mday],
 [string &monname],
[string &dayname],
[int &hour],
 [int &min],
[int &sec])
Convert a time value to local time components.
int gmtime([int time = NULL],
[int &year],
[int &mon],
[int &mday],
 [string &monname],
[string &dayname],
[int &hour],
 [int &min],
[int &sec])
Convert a time value to UTC time components.
extern int errno;
Last system errno number.