____ ____ ____ ____ 
||n |||i |||m |||f ||
||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|

	

the nimf guide : api : " text "

The nimf text module provides helpers for dealing with characters and strings. Character helpers begin with the prefix `ch.` and string helpers begin with `str.`. This listing does not include any private words used within the module.

Enums

Words


ch.lower?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is a lowercase character and 0 otherwise.

ch.upper?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is an uppercase character and 0 otherwise.

ch.alpha?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is an alpha character (A-Z or a-z) and 0 otherwise.

ch.digit?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is a digit character (0-9) and 0 otherwise.

ch.alphanum?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is a digit character (0-9) or an alpha character (A-Z or a-z) and 0 otherwise.

ch.ascii?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is in the range of ascii characters and 0 otherwise.

ch.printable?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is a printable character (has a visual representation) and 0 otherwise.

ch.ascii-printable?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is a printable character (has a visual representation) in the range of ascii characters and 0 otherwise.

ch.whitespace?

Signature: ( ch -- flag )

Description: Eats acharacter from TOS and leaves -1 on the stack if it is a whitespace character and 0 otherwise.

Note: This word is designed to be used to test for ascii whitespace and cannot be used to determine non-ascii range utf-8 whitespace.

ch.punctuation?

Signature: ( ch -- flag )

Description: Eats a character from TOS and leaves -1 on the stack if it is a punctuation character and 0 otherwise.

Note: This word is designed to be used to test for ascii punctuation and cannot be used to determine full utf-8 punctuation.

ch.to-upper

Signature: ( ch -- CH )

Description: Eats a character from TOS and leaves an uppercase version of any character between a and z. Any other characters will be left unaltered.

Note: This word is designed to work with ascii range characters and will leave all other utf-8 characters unaltered.

ch.to-lower

Signature: ( CH -- ch )

Description: Eats a character from TOS and leaves a lowercase version of any character between A and Z. Any other characters will be left unaltered.

Note: This word is designed to work with ascii range characters and will leave all other utf-8 characters unaltered.

str.print

Signature: ( sptr -- _ )

Description: Eats a string pointer from TOS and prints the string stored at that address. Leaves nothing on the stack.

str.print-buf

Signature: ( _ -- _ )

Description: Prints the string currently held in the temporary string buffer. Takes nothing from, and leaves nothing on, the stack.

str.equal?

Signature: ( sptr sptr -- flag )

Description: Eats two string pointers from TOS and leaves a flag representing whether the strings are equal, as in: are the same length and contain the same characters; not as in: they are the same memory address, though the same address put in would be equal and result in -1 on the stack.

str.index-of

Signature: ( ch sptr -- offset )

Description: Eats a string pointer and a character from TOS. Searches that string for the given character and leaves the offset of the first instance of that character on the stack, or -1 if the character could not be found in the string.

str.offset-index-of

Signature: ( ch sptr offset1 -- offset2 )

Description: Eats an offset value, a string pointer, and a character from TOS. Searches that string for the given character starting at the given offset and leaves the first instance of that character on the stack, or -1 if the character could not be found in the string.

str.sub

Signature: ( start end sptr -- _ )

Description: Moves a substring to the temporary string buffer. Eats a string pointer, and ending offset, and a starting offset from TOS. start and end are both inclusive (ie. a start of 2 and end of 4 would result in a string with a length of 3, not 1 or 2). Leaves nothing on the stack. If the start and end range extends beyond the string bounds or the end offset is less than the start offset an error will be raised.

str.count-of-char

Signature: ( ch sptr -- n )

Description: Eats a string pointer and a character from TOS and leave the number of times the character is found in the given string.

str.range-count-of-char

Signature: ( ch start end sptr -- n )

Description: Eats a string pointer, an ending offset, a starting offset, and a character from TOS and leaves the number of times the character is found within the offset range of the given string. If the end offset is larger than the string bounds, it will be adjusted to the bounds of the string. If the end offset is less than the start offset 0 will be left on the stack.

str.append-char

Signature: ( ch sptr -- _ )

Descriptioin: Eats a string pointer and a character from TOS. Appends the char to the end of the string. It is the callers responsibility to make sure there is room for the char in memory. As a result, this word should be called with care so as to not overwrite areas of memory unexpectedly. Leaves nothing on the stack.

str.is-number?

Signature: ( sptr -- flag )

Description: Eats a string pointer from TOS and leaves a flag indicating whether the given string represents a number (positive or negative, not a decimal).