ejAddParam GoAhead JavaScript API GoAhead EMF

Synopsis

Add a key/value pair to a JavaScript encoded string.

Prototype

#include "ej.h"

int ejAddParam(char_t *paramList, int size, char_t *key, 
        char_t *value); 

Parameters

paramList JavaScript formatted parameter list
size Total size of paramList buffer in characters
key Name of the key to add to paramString
value Name of the key's corresponding value

Description

ejAddParam is a utility function to allow for easy creation of JavaScript formatted strings of key/value pairs. It is similar in function to strcat; it encodes the key/value pair and then appends them to paramList. An error will be returned if the key/value will not fit in the remaining space of paramList, or the key contains illegal characters. The caller is responsible for allocating and or freeing the memory associated with all input strings.

The JavaScript format is as follows:

var1="5";var2="another value";var3="yet another value"; 

Return Value

Returns length in characters of paramList, -1 if an error occured.

Example

char_t *param;

if ((param = balloc(512 * sizeof(char_t))) == NULL) {
    error(E_L, E_LOG, T("Error allocating memory\n"));
}

param[0] = '\0';
if (ejAddParam(param, 512, "month", "5") == -1) {
    error(E_L, E_LOG, T("Error adding parameter\n"));
}
if (ejAddParam(param, 512, "day", "15") == -1) {
    error(E_L, E_LOG, T("Error adding parameter\n"));
}
if (ejAddParam(param, 512, "year", "1999") == -1) {
    error(E_L, E_LOG, T("Error adding parameter\n"));
}

printf("%s\n",param);
month="5";day="15";year="1999"

bfreeSafe(B_L, param);

See Also

ejGetParam