# lib_fn function library

Dependencies:

## Description

Functions here should be pure functions (no side effects, no reference to external data) and so should all be dimorphic. No specific naming convention. Be cautious putting functions in here.

Functions here should have no dependencies outside lib_fn.

## Public functions

despecialize(string:s)=(string:s) dimorphic

Take a string, and return it with any WEIDU regexp special characters escaped out.

divide_round_up(numerator:i, denominator:i)=(value:s) dimorphic

Divide two numbers, rounding up any remainder

ensure_hex(pad_length:i, in:s)=(out:s) dimorphic

Forces the string 'in' into hex form and passes it as 'out'. If pad_length is set to a non-zero value, ensure the hex is (at least) that long.

eval(var:s, arguments:s)=(var:s, value:s) dimorphic

Given a string, return its value if it's a variable, or the string itself if not. Also permits 'argument'->'value' interface.

invert_string(block_size:i, string:s)=(string:s) dimorphic

Break 'string' into 'block_size'xN substrings, and invert the order of those substrings.

point_in_bounds(x:i, xmin:i, xmax:i, y:i, ymin:i, ymax:i)=(in_bounds:s, x_in_bounds:s, y_in_bounds:s) dimorphic

Determine whether (x,y) are inside the rectangle with bottom left point (xmin,ymin) and top right point (xmax,ymax)

return_first_entry(list:s, separator:s=" ")=(entry:s, list:s) dimorphic

Given a list of strings (separated by spaces, either bare or in "" or ~~ quotes), return the first entry, and the rest of the list. If 'separator' is specified, use it instead of space to separate strings. (It should be a single character.) If you use ' ' as a separator, newlines and tabs are replaced by spaces in processing the string

return_first_pair(list:s, arrow:s=":s=>", separator:s=" ")=(list:s, key:s, value:s) dimorphic

Given a string in the form 'key=>value list', return the first key, the first value, and the rest of the string. if 'arrow' is specified, its value is used in place of '=>' to separate key-value pairs. 'key' and 'value' can be bare strings or can be wrapped in "" or ~~.

tolower(arguments:s)=(value:s) dimorphic

Given a string, return it in lower case. (This is for use in functional programming - WEIDU's TO_LOWER suffices for first-order code.)

tolower_safe(arguments:s)=(value:s) dimorphic

Convert the (assumed mixed-case) string to lowercase, skipping any accented characters

toupper(arguments:s)=(value:s) dimorphic

Given a string, return it in upper case.

trim_string(require_both:i, character:s=" ", string:s)=(string:s) dimorphic

Given a single string, and a character (space by default) remove any occurrences of the character from the beginning and end of the string. If require_both=1, only strip if the character appears at beginning and end (and only strip one).

## Internal functions

These should not be called from outside the library itself.

hex_digit(digit:i)=(out:s) patch

hexify(in:i, pad_length:i, out:s)=(out:s) patch