General HSP Language Methods

APIs & Tools

These general methods are used for WebMail, WebMailProxy and WebAdmin.

Name

inc (Increment)

Syntax

inc(NUMBER contor [, NUMBER step])

Explanation

Increments <contor> by <step>. If <step> is missing <contor> will be incremented by 1.

Name

dec (Decrement)

Syntax

dec(NUMBER contor [, NUMBER step])

Explanation

Decrements <contor> by <step>. If <step> is missing,<contor> will be decremented by 1.

Name

mul

Syntax

NUMBER mul(NUMBER val1 , NUMBER val2)

Explanation

Returns <val1>*<val2>.

Name

mod

Syntax

NUMBER mod(NUMBER val1 , NUMBER val2)

Explanation

Returns <val1>%<val2>..

Name

div

Syntax

NUMBER div(NUMBER val1 , NUMBER val2)

Explanation

Returns <val1>%<val2>..

Name

eq

Syntax

eq(VALUE arg1, VALUE arg2[, ... VALUE arg6])

Explanation

Returns true if <arg1> is equal to one of the other arguments (case sensitive), returns false otherwise. A maximum of 6 arguments is supported.

Name

eqcase

Syntax

eqcase(STRING arg1, STRING arg2[, ... VALUE arg6])

Explanation

Returns true if <arg1> is equal to one of the other arguments (case INSENSITIVE), returns false otherwise.A maximum of 6 arguments is supported.

Name

eqmatch

Syntax

eqmatch(VALUE arg1, VALUE arg2)

Explanation

Returns true if <arg1> is matched by the regular expression arg2, returns false otherwise.

Name

eqmatchcase

Syntax

eqmatchcase(STRING arg1, STRING arg2)

Explanation

Returns true if <arg1> is matched by the regular expression arg2 (case sensitive). Returns false otherwise.

Name

gt (greater)

Syntax

gt(NUMBER arg1, NUMBER arg2)

Explanation

Returns true if <arg1> is greater than <arg2>.

Name

gte (greater than or equal to)

Syntax

gte(NUMBER arg1, NUMBER arg2)

Explanation

Returns true if <arg1> is greater than or equal to <arg2>.

Name

lt (less than)

Syntax

lt(NUMBER arg1, NUMBER arg2)

Explanation

Returns true if <arg1> is less than <arg2>.

Name

lte (less than or equal to)

Syntax

lte(NUMBER arg1, NUMBER arg2)

Explanation

Returns true if <arg1> is less than or equal to <arg2>.

Name

eval (evaluate)

Syntax

eval(STRING eval1, STRING eval2):

Explanation

Assigns the value of the variable that has the identifier <eval2> to the variable that has the identifier <eval1>

Name

exists

Syntax

exists(VAR arg)

Explanation

Returns true if <arg> exists

Name

isempty

Syntax

isempty(VAR arg)

Explanation

Returns true if value of <arg> is empty; if <arg> is an ARRAY or a MAP returns true if it has no element.

Name

pop

Syntax

OBJECT pop(ARRAY A)

Explanation

Pops an element of array A and returns it

Name

push

Syntax

push(ARRAY A, OBJECT el)

Explanation

Pushes element <el> into ARRAY <A>

Name

map_getValue

Syntax

ANY map_getValue(MAP map, STRING prop)

Explanation

It returns the value of <prop> property, contained in <map>.

Name

map_setValue

Syntax

map_setValue(MAP map, STRING prop, OBJECT data)

Explanation

Sets data to the property <prop> of <map>.

Name

type

Syntax

STRING type(VAR data)

Explanation

It returns the type of data. The type can be "value", "map", or "vector".

Name

getSize

Syntax

NUMBER getSize(VAR arg)

Explanation

Returns size of <arg> (<arg> can be an ARRAY or a MAP)

Name

str_escape

Syntax

STRING str_escape(STRING arg)

Explanation

Escapes string <arg> and returns this value.

Name

str_str

Syntax

NUMBER str_str(STRING haystack, STRING needle)

Explanation

It returns the first occurrence of the substring <needle> in the string <haystack>. -1 is returned if there is no occurrence.

Name

str_rstr

Syntax

NUMBER str_rstr(STRING haystack, STRING needle)

Explanation

It returns the last occurrence of the substring <needle> in the string <haystack>. -1 is returned if there is no occurrence.

Name

str_replace

Syntax

STRING str_replace(STRING haystack, STRING needle, STRING newsub)

Explanation

It replaces all <needle> occurrences, from <haystack>, with <newsub> and stores the new value into <newstr>.

Name

str_substring

Syntax

STRING str_substring(STRING str, NUMBER begin, NUMBER end)

Explanation

Returns the substring of <str>, from <begin> to <end>-1.

Name

str_len

Syntax

NUMBER str_len(STRING str)

Explanation

Returns the length of <str>.

Name

str_cmp

Syntax

NUMBER str_cmp(STRING str1, STRING str2)

Explanation

Returns strcmp(str1, str2).

Name

str_caseCmp

Syntax

NUMBER str_caseCmp(STRING str1, STRING str2)

Explanation

Returns strcasecmp(str1, str2).

Name

str_split

Syntax

ARRAY str_split(STRING str, STRING delim)

Explanation

Returns an array of tokens(strings) from <str>, delimited by <delim>.

Name

str_join

Syntax

STRING str_join(ARRAY strArray, STRING delim)

Explanation

Returns a string which contains all tokens from <strArray> delimited by <delim>.

Name

str_trim

Syntax

STRING str_trim(STRING str[, STRING type])

Explanation

Trims white spaces from the beginning and/or the end of <str>. <type> can be:

− "left": white spaces from the beginning of string are trimmed
− "right": white spaces from the end of string are trimmed
− parameter can miss: white spaces from the beginning AND the end of string are trimmed

Name

encode_url

Syntax

STRING encode_url(STRING arg):

Explanation

Encodes <arg> in URL format and returns this value; transforms non-alphanumeric characters in %{hex}{hex} and spaces in "+". (For example, "." becomes "%2E").

Name

decode_url

Syntax

STRING decode_url(STRING arg)

Explanation

Decodes <arg> from url format and returns this value.

Name

encode_html

Syntax

STRING encode_html(STRING arg):

Explanation

Encodes <arg> in html format and returns this value; '<' becomes "<", '>' becomes ">" and "&" becomes "&".

Name

url_ok

Syntax

url_ok(STRING url)

Explanation

Returns true if the servers considers <url> as a valid external url.

Name

getLastError

Syntax

STRING getLastError()

Explanation

Returns the last error, after a method call

Name

random

Syntax

NUMBER random(NUMBER n, NUMBER m)

Explanation

Returns a random value, between <n> and <m>-1

Name

getSessionId

Syntax

STRING getSessionId()

Explanation

Returns the current session key.

Name

setHeaders

Syntax

setHeaders(NUMBER httpCode, [STRING h1 [, STRING h2 [,...]]])

Explanation

It resets HTTP response headers. It is used for a personalized response to the client.

Don't write any other HTML or HSP code before this method!

Name

headers_getUserAgent

Syntax

STRING headers_getUserAgent()

Explanation

Returns User-Agent HTTP header value.

Name

json2hsp

Syntax

ANY json2hsp(STRING json)

Explanation

It returns the hsp entity with the associated json representation. If the json string is illegal the following errors can be returned:

− JSON_FLEX_ERROR - usually when an illegal character was encountered in the json string (e.g. unescaped control character U+0000:U+001F);
− JSON_SYNTAX_ERROR - when a token is encountered in an illegal context (e.g. {"abc" "xyz"} -> missing ':' between key "abc" and value "xyz");
− JSON_DATA_STACK_FULL or JSON_STATE_STACK_FULL - if the resulting object depth exceeded 128 levels (e.g. "[[[ ... ]]]" - with 129 left/right brackets);

- the full json syntax is supported by method;
- in addition(to strings) the keys in maps can be HSP identifiers, so the json '{abc: 1}' is successfully parsed like '{"abc": 1}';
- the U+0000 unicode is not encoded in string values (the json string "abc\u0000xyz" will result in the "abcxyz" hsp string);
- strings are limited to 4096 memory bytes; all json atomic values(strings, numbers, true, false, null) will be stringified by this method (eg. the hsp json strings "{abc: 123, xyz:[true, false, null]" and "{\"abc\"  : \"123\", \"xyz\": [\"true\", \"false\", \"null\"]}" will produce the same hsp entity);

Name

hsp2json

Syntax

STRING hsp2json(ANY)()

Explanation

It returns json string representaion of the hsp entity (string, array, map). If the object is too big then the method fails with error code JSON_OBJECT_TOOBIG; an object is too big if its json string is greater than one mega (1024K) or its depth greater than 128.