ejGetParam GoAhead JavaScript API GoAhead EMF

Synopsis

Retrieve a value from a JavaScript encoded string.

Prototype

#include "ej.h"

char_t *ejGetParam(char_t *paramList, char_t *key); 

Parameters

paramList JavaScript formatted parameter list
key Name of the key to look up within paramString

Description

ejGetParam is a utility function to allow for easy extraction of values from a string of key/value pairs in JavaScript format. The caller is responsible for freeing memory allocated by this function for the return value.

The JavaScript format is as follows:

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

Return Value

Returns the value associated with the given key within the parameter list. If the key is not found or paramList cannot be successfully parsed, NULL is returned.

Note: This function allocates memory for the return value. This memory must be explicitly freed using bfree or bfreeSafe.

Example

char_t *day, *month, *year;
char_t param = "month=\"5\";day=\"15\";year=\"1999\";";

day = ejGetParam(param, "day");
month = ejGetParam(param, "month");
year = ejGetParam(param, "year");

if (day && month && year) {
    printf("%s/%s/%s\n", month, day, year);
	5/15/1999
}
bfreeSafe(B_L, day);
bfreeSafe(B_L, month);
bfreeSafe(B_L, year);

See Also

ejAddParam